
正文
ArcGis Python脚本——将细碎小面合并到相邻的面积最大的面
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
参数:
polygon_fc 面要素类
area_limit 给定面积值,小于它的面会被合并
给定两个参数即可,这回没有注释。
#polygon_fc 面要素类
#area_limit 给定面积值,小于它的面会被合并
polygon_fc="C:\Users\Administrator\Desktop\yang\New Folder\Export_Output_4.shp"
area_limit=4000
fieldList=arcpy.ListFields(polygon_fc)
field_name_List=[]
for field in fieldList:
field_name_List.append(field.name)
if 'Shape_Area' not in field_name_List :
arcpy.AddField_management(polygon_fc,'Shape_Area','DOUBLE',field_precision=18,field_scale=6)
arcpy.CalculateField_management(polygon_fc,'Shape_Area','!shape.area!','PYTHON_9.3')
updateCursor=arcpy.UpdateCursor(polygon_fc,'Shape_Area<='+str(area_limit))
for small_row in updateCursor:
small_geometry=small_row.shape
searchcursor = arcpy.SearchCursor(polygon_fc, 'Shape_Area>' + str(area_limit))
areas=[]
for row in searchcursor:
geometry = row.shape
if (small_geometry.touches(geometry)):
areas.append(row.getValue('Shape_Area'))
updateCursor1 = arcpy.UpdateCursor(polygon_fc, 'Shape_Area>' + str(area_limit))
if len(areas)>0:
area_max = max(areas)
for row1 in updateCursor1:
if (row1.getValue('Shape_Area') == area_max):
row1.shape = row1.shape.union(small_geometry)
updateCursor1.updateRow(row1)
updateCursor.deleteRow(small_row)
del updateCursor1
del updateCursor
del searchcursor
# code source: https://www.cnblogs.com/yzhyingcool/# QQ:975601416
print '合并完成!'







