参数:
polygon_fc 面要素类
area_limit 给定面积值,小于它的面会被合并
给定两个参数即可,这回没有注释。
1 #polygon_fc 面要素类 2 #area_limit 给定面积值,小于它的面会被合并 3 polygon_fc="C:\Users\Administrator\Desktop\yang\New Folder\Export_Output_4.shp" 4 area_limit=4000 5 fieldList=arcpy.ListFields(polygon_fc) 6 field_name_List=[] 7 for field in fieldList: 8 field_name_List.append(field.name) 9 if ‘Shape_Area‘ not in field_name_List : 10 arcpy.AddField_management(polygon_fc,‘Shape_Area‘,‘DOUBLE‘,field_precision=18,field_scale=6) 11 arcpy.CalculateField_management(polygon_fc,‘Shape_Area‘,‘!shape.area!‘,‘PYTHON_9.3‘) 12 updateCursor=arcpy.UpdateCursor(polygon_fc,‘Shape_Area<=‘+str(area_limit)) 13 for small_row in updateCursor: 14 small_geometry=small_row.shape 15 searchcursor = arcpy.SearchCursor(polygon_fc, ‘Shape_Area>‘ + str(area_limit)) 16 areas=[] 17 for row in searchcursor: 18 geometry = row.shape 19 if (small_geometry.touches(geometry)): 20 areas.append(row.getValue(‘Shape_Area‘)) 21 updateCursor1 = arcpy.UpdateCursor(polygon_fc, ‘Shape_Area>‘ + str(area_limit)) 22 if len(areas)>0: 23 area_max = max(areas) 24 for row1 in updateCursor1: 25 if (row1.getValue(‘Shape_Area‘) == area_max): 26 row1.shape = row1.shape.union(small_geometry) 27 updateCursor1.updateRow(row1) 28 updateCursor.deleteRow(small_row) 29 del updateCursor1 30 del updateCursor 31 del searchcursor 32 print ‘合并完成!‘
原文地址:https://www.cnblogs.com/yzhyingcool/p/10561332.html
时间: 2024-10-22 17:33:25