码迷,mamicode.com
首页 > 编程语言 > 详细

ArcGis Python脚本——将细碎小面合并到相邻的面积最大的面

时间:2019-03-19 21:32:03      阅读:1072      评论:0      收藏:0      [点我收藏+]

标签:class   div   output   合并   tput   python   int   end   double   

参数:

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 合并完成!    

 

ArcGis Python脚本——将细碎小面合并到相邻的面积最大的面

标签:class   div   output   合并   tput   python   int   end   double   

原文地址:https://www.cnblogs.com/yzhyingcool/p/10561332.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!