以下示例使用一个 x,y 坐标列表创建了一个多边形几何对象。然后使用裁剪工具来裁剪具有多边形几何对象的要素类。

时间:2023-03-09 19:32:19
以下示例使用一个 x,y 坐标列表创建了一个多边形几何对象。然后使用裁剪工具来裁剪具有多边形几何对象的要素类。
import arcpy

# Create an Array object.
#
array = arcpy.Array() # List of coordinates.
#
coordList = ['1.0;1.0','1.0;10.0','10.0;10.0','10.0;1.0'] # For each coordinate set, create a point object and add the x- and
# y-coordinates to the point object, then add the point object
# to the array object.
#
for coordPair in coordList:
x, y = coordPair.split(";")
pnt = arcpy.Point(x,y)
array.add(pnt) # Add in the first point of the array again to close the polygon boundary
#
array.add(array.getObject(0)) # Create a polygon geometry object using the array object
#
boundaryPolygon = arcpy.Polygon(array) # Use the geometry to clip an input feature class
#
arcpy.Clip_analysis("c:/data/rivers.shp", boundaryPolygon, "c:/data/rivers_clipped.shp")