zoukankan      html  css  js  c++  java
  • 1章代码

    arcpy面积计算

    #coding=utf8
    # -*- coding: UTF-8 -*-
    import arcpy
    from arcpy import env
    import os
    
    import sys
    ###############
    ##################################
    
    fc= arcpy.GetParameterAsText(0)
    fieldname= arcpy.GetParameterAsText(1)
    
    
    rows = arcpy.da.UpdateCursor(fc,["shape@",fieldname])
    
    i=1
    try:
        for row in rows:
    
            feat = row[0]
            row[1]=feat.area
            arcpy.AddMessage("No:"+str(i)+":"+str(feat.area))
            rows.updateRow(row)
    
            i=i+1
    
        del rows
    except Exception as e:
        arcpy.AddError(e.message)

    Arcengine C#调用arcpy的工具方法

    private static bool CalArea(IFeatureClass pFeatureClass, string FieldName)
            {
    
                string tbxFileName = @"F:2020book原始资料data1Python基础工具箱.tbx";
                if (!File.Exists(tbxFileName))
                {
                    MessageBox.Show("文件" + tbxFileName + "不存在");
                    return false;
                }
                IGeoProcessor gp = new GeoProcessor();
                gp.OverwriteOutput = true;
                gp.AddOutputsToMap = false;
              
    
                gp.AddToolbox(tbxFileName);
    
    
    
                // Create a variant - data are in the workspace
                IVariantArray parameters = new VarArray();
    
                parameters.Add(pFeatureClass);//参数
                parameters.Add(FieldName);//参数
             
                string toolname="计算面积";//工具名称,建议工具名称为英文,标签为中文,
    
    
                //object sev = null;
    
                try
                {
                    gp.Execute(toolname, parameters, null);              
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误:" + ex.Message + ",
    请自己允许" + tbxFileName + "/" + toolname);
                    //string errorMsgs = gp.GetMessages(ref sev);
                    //MessageBox.Show(errorMsgs);
                    return false;
                }
                finally
                {
                    gp = null;
                    //MessageBox.Show("ok");
                }
                return true;
    
            }
  • 相关阅读:
    hive函数总结
    python判断文件和目录是否存在
    python中的参数
    写hive db的两种方法
    python中argparse模块的使用
    python数据持久存储:pickle模块的使用
    python读文件
    mysql 将时间戳直接转换成日期时间
    shell日期的应用
    [转]SQL UNION 和 UNION ALL 操作符
  • 原文地址:https://www.cnblogs.com/gisoracle/p/13533167.html
Copyright © 2011-2022 走看看