以下代码将获取输入栅格,获取其范围,然后将该范围插入到面要素类中:
import arcpy
r = arcpy.Raster(in_raster)
point = arcpy.Point()
array = arcpy.Array()
corners = ["lowerLeft", "lowerRight", "upperRight", "upperLeft"]
cursor = arcpy.InsertCursor(fc)
feat = cursor.newRow()
for corner in corners:
point.X = getattr(r.extent, "%s" % corner).X
point.Y = getattr(r.extent, "%s" % corner).Y
array.add(point)
array.add(array.getObject(0))
print len(array)
polygon = arcpy.Polygon(array)
feat.shape = polygon
cursor.insertRow(feat)
array.removeAll()
del feat
del cursor
您可以在ArcMap的Python窗口通过设置运行它in_raster
,并fc
像这样:
>>> fc = 'r_extent'
>>> in_raster = 'CaliCoast10mNED_HavCurvedPCS'
这里r_extent
是一个已有的多边形要素类。然后只需复制代码并运行即可。我得到这个: