在ArcGIS 10和Python中,我想获取shapefile中每个多边形的范围(xmax,ymax,xmin,ymin)信息。
我可以使用获取整个shapefile的范围
file=r"D:\SCRATCH\ARCGIS\100k_trc_tiles_TVM.shp"
desc=arcpy.Describe(file)
print desc.extent.Xmax
394551.52085039532
但是我似乎无法弄清楚如何为数据集中的每一行获取相同的信息。
rows = arcpy.SearchCursor("100k_trc_tiles_TVM")
for row in rows:
print row
打印数据集中的31行,但是
for row in rows:
desc=arcpy.Describe(row)
print desc.extent.Xmax
给出一个错误。
运行时错误:对象:描述输入值无效的类型
我当时正在考虑使用“计算几何”将范围值添加到表中,但这仅给出了质心。然后,我猜我们可以使用诸如row.GetValue(“ xmax”)之类的东西。
话虽这么说,我知道我们可以使用http://www.ian-ko.com/free/free_arcgis.htm中的函数创建X / Y,max / min,但是最好避免添加字段,尤其是在ArcPy可以获取这些值的情况下。
基本上,我需要获取范围以输入到裁剪工具中,以裁剪出30个数据区域(根据1:100,000地图图)进行地理处理,因为拆分工具由于数据集的大尺寸而失败(请参见为什么相交会给错误999999:错误执行功能无效拓扑[太多lineseg端点])。我要自动执行此操作,因为它在许多数据集上重复出现。
===工作脚本===
# Emulates Arc Info SPLIT tool by using Clip but
# Requires a FC from which each row is used as the input clip feature.
# Each row must be rectangular.
# Used on 12GB FGDB with 100 million records.
#Licence: Creative Commons
#Created by: George Corea; georgec@atgis.com.au, coreagc@gmail.com
import arcpy, string
#inFrame=arcpy.GetParameterAsText(0) # Input dataframe FC
#inFile=arcpy.GetParameterAsText(1) # Input FC for splitting
#outDir=arcpy.GetParameterAsText(2) # Output FGDB
inFrame=r"D:\SCRATCH\ARCGIS\100k_trc_tiles_TVM.shp"
inFile=r"c:\junk\106\data\7_Merge.gdb\FullRez_m2b"
outDir=r"D:\SCRATCH\Projects\206\datasplit\test_slaasp.gdb"
#NameField="Name_1"
#arcpy.env.workspace = r"C:/Workspace"
arcpy.env.overwriteOutput = True
rows = arcpy.SearchCursor(inFrame)
shapeName = arcpy.Describe(inFrame).shapeFieldName
for row in rows:
feat = row.getValue(shapeName)
Name = row.Name_1
print "Executing clip on: "+str(Name)
extent = feat.extent
#print extent.XMin,extent.YMin,extent.XMax,extent.YMax
# Create an in_memory polygon
XMAX = extent.XMax
XMIN = extent.XMin
YMAX = extent.YMax
YMIN = extent.YMin
pnt1 = arcpy.Point(XMIN, YMIN)
pnt2 = arcpy.Point(XMIN, YMAX)
pnt3 = arcpy.Point(XMAX, YMAX)
pnt4 = arcpy.Point(XMAX, YMIN)
array = arcpy.Array()
array.add(pnt1)
array.add(pnt2)
array.add(pnt3)
array.add(pnt4)
array.add(pnt1)
polygon = arcpy.Polygon(array)
ShapeFile = outDir+"\\temp_poly"
arcpy.CopyFeatures_management(polygon, ShapeFile)
#print Name
### Set local variables
in_features = inFile
clip_features = ShapeFile
out_feature_class = outDir+"\\"+Name
xy_tolerance = "0.22"
# Execute Clip
try:
arcpy.Clip_analysis(in_features, clip_features, out_feature_class, xy_tolerance)
print "Completed: "+str(Name)
except:
error = arcpy.GetMessages()
print "Failed on: "+str(Name)+" due to "+str(error)