Python Esri Arcpy 比较多边形和折线的几何图形
Posted
技术标签:
【中文标题】Python Esri Arcpy 比较多边形和折线的几何图形【英文标题】:Python Esri Arcpy Compare geometry from Polygon and Polyline 【发布时间】:2021-09-07 20:28:11 【问题描述】:我在 ArcMap 上有两层:
A 层几何多边形 B 层几何折线(关闭) 我想将 A 层的每条记录与 B 层的轮廓进行比较。B 层(折线)具有围绕多边形(配菜)的线。 因此,我必须比较线 B 是多边形 A 与 python 2.7 和 arcpy 的边界如果我在折线中转换第一个多边形
#arcpy.PolygonToLine_management("inLayerPolygon", "outFeaturePolyline", "IGNORE_NEIGHBORS")
所以你有两条折线
那么 我可以比较 Shape 字段吗?
''''
#LIST LAYERS ON THE MAP
for lyr in arcpy.mapping.ListLayers(self.mxd, '*'):
self.listLayer[lyr.name] = lyr.dataSource
LayerP = 'LayerA'
LayerB = 'LayerB'
dsLayer = self.listLayer.get(layer, 0)
arr = arcpy.da.FeatureClassToNumPyArray(in_table= ds, field_names= ["ID", "SHAPE"])
for row in arr:
cursor = arcpy.da.SearchCursor("LayerB", field_names= ["ID", "SHAPE"], where_clause = "ID = " + str(row[0]))
for r in cursor:
if row["SHAPE"] == r["SHAPE"]:
arcpy.AddMessage('YES')
else:
arcpy.AddMessage('NO')
''''
谢谢
【问题讨论】:
【参考方案1】:我找到了这个解决方案:
#LIST LAYERS
for lyr in arcpy.mapping.ListLayers(self.mxd, '*'):
self.listLayer[lyr.name] = lyr.dataSource
desc = arcpy.Describe(lyr.dataSource)
arcpy.AddMessage("Feature Type: " + desc.featureType)
arcpy.AddMessage("Shape Type : " + desc.shapeType)
arcpy.AddMessage("Spatial Index: " + str(desc.hasSpatialIndex))
layer1 = 'LayerA' (Polyline)
layer2 = 'LayerB' (Polygon)
newLayer = 'newLayer'
ds1 = self.listLayer.get(layer1, 0)
ds2 = self.listLayer.get(layer2, 0)
geodb = 'C:/GEODB/chk.gdb'
arcpy.MakeFeatureLayer_management(ds1,newLayer)
# Select all cities that overlap the chihuahua polygon
arcpy.SelectLayerByLocation_management(newLayer, "BOUNDARY_TOUCHES", ds2, "", "NEW_SELECTION")
num = arcpy.GetCount_management(newLayer)
arcpy.AddMessage("num = " + str(num))
# Write the selected features to a new featureclass
arcpy.CopyFeatures_management(newLayer, geodb + "/newfc")
我想获得未选择的功能
【讨论】:
【参考方案2】:这是一个更好的解决方案
arr = arcpy.da.FeatureClassToNumPyArray(in_table= ds, field_names= '*', where_clause= sWhere)
for row in arr:
if arcpy.Exists(fcLayerPolyline):
arcpy.Delete_management(fcLayerPolyline)
if arcpy.Exists(fcLayerPolygon):
arcpy.Delete_management(fcLayerPolygon)
arcpy.MakeFeatureLayer_management(dsPolyline, fcLayerPolyline, "ID_GMO = " + str(row["ID"]))
arcpy.MakeFeatureLayer_management(dsPolygon, fcLayerPolygon)
#Seleziono Poligono ST011PAT
arcpy.SelectLayerByLocation_management(fcLayerPolygon, "SHARE_A_LINE_SEGMENT_WITH", fcLayerPolyline, "", "NEW_SELECTION")
num = arcpy.GetCount_management(fcLayerPolygon)
with arcpy.da.SearchCursor(fcLayerPolygon, ['TIPO']) as cursor:
for r in cursor:
if r[0] == row["TIPO"]
....
【讨论】:
以上是关于Python Esri Arcpy 比较多边形和折线的几何图形的主要内容,如果未能解决你的问题,请参考以下文章
arcpy地理处理工具案例教程-生成范围-自动画框-深度学习样本提取-人工智能-AI
esri.config.defaults.io.proxyUrl设置