利用Python制作Arcgis脚本工具
#coding=utf-8
import arcpy
import os
import os.path
inWorkspace = arcpy.GetParameterAsText(0) #输入英文城市名文件所在路径,下含已转好的DAE_SHP文件夹
#inWorkspace = "D:/PythonCode_inWork/09DAE_SHP_Check/PROCESS/DATA/YANGZHOU"
#城市名自动提取
#【方法1,在python脚本中提取正常,但在Arcgis脚本工具中错误,需要修改】
##city_reverse= ""
##for i in range(1,len(inWorkspace)):
## if inWorkspace[-i] == "/":
## break
## else:
## city_reverse += inWorkspace[-i]
##city = (city_reverse[::-1])
##arcpy.AddMessage(city)
#【方法2】
#city = inworkspace.split('\\')[-1] if '\\' in inworkspqce else inworkspqce.split('/')[-1]
#【方法3】
#city = inworkspace.split(os.path.sep)[-1]
#【方法4】
city = os.path.split(inWorkspace)[-1]
#_H合并Tile
shps_dir = inWorkspace + "/DAE_SHP"
shps = os.listdir(shps_dir)
shps_H = []
for i in shps:
if '_H_poly.shp' in i:
shps_H.append(shps_dir+"/"+i)
arcpy.AddMessage('Start merging...')
#merge_name = city + "_MERGE.shp"
#merge_result = os.path.join(inWorkspace,merge_name)
merge_result = inWorkspace + "/"+ city + "_MERGE.shp"
#print merge_result
arcpy.Merge_management(shps_H,merge_result)
arcpy.AddMessage('Merging succeed!')
#按PID融合
arcpy.AddMessage('Start dissolving...')
dissolve_result = inWorkspace + "/"+ city + "_DISSOLVE.shp"
arcpy.Dissolve_management(merge_result, dissolve_result,["PID","FTYPE"])
arcpy.AddMessage('Dissolving succeed!' )
#与Tile面交集取反
Outline = ""
arcpy.AddMessage('Start symdiffing...')
for j in os.listdir(inWorkspace):
if "Submit_Outline_M.shp" in j:
Outline = j
inFeatures = inWorkspace + "/"+ Outline
updateFeatures = dissolve_result
outFeatureClass = inWorkspace + "/"+ city + "_SymDiff.shp"
arcpy.SymDiff_analysis(inFeatures, updateFeatures, outFeatureClass, "ALL",0.05)
arcpy.AddMessage('Symdiffing succeed!' )
#漏蓝结果排除边界外
blue_union = inWorkspace + "/"+ city + "_BLUE_UNION.shp"
arcpy.Clip_analysis(outFeatureClass, inFeatures, blue_union)
#拆分多部件要素
blue = inWorkspace + "/"+ city + "_BLUE.shp"
arcpy.MultipartToSinglepart_management(blue_union,blue)
#漏蓝检查提示消息
feature_count = int(arcpy.GetCount_management(blue).getOutput(0))
if feature_count == 0:
arcpy.AddMessage("No blue!Congratulations!".format(feature_count))
elif feature_count == 1:
arcpy.AddMessage("There is {0} blue gap to confirm!".format(feature_count))
else:
arcpy.AddMessage("There are {0} blue gaps to confirm!".format(feature_count))
转载自:https://blog.csdn.net/lzqg1990/article/details/89397691