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; }