在ArcGIS中叠加操作会带来碎图斑或狭长面,而这些碎图斑或狭长面又会影响后续的判断。所以就需要消除。
例如:
具体操作有以下方式:
1、最简单的的方法就是使用ArcGIS提供的“消除工具”。在"数据管理工具"——“制图综合”——“消除”。
2、使用Python脚本
# -*-coding:gbk-*-
import arcpy
from arcpy import env
import time
# 融合指定条件的图斑
try:
source_gdb_path = "F:/gisData/" # 原始图层工作空间
in_features = "subbasin.shp" # 输入图层
expression = "SHAPE_AREA <50 or SHAPE_Area/ SHAPE_Length<0.2" # 融合限制条件
env.workspace = source_gdb_path
time_begin = time.time()
print "消除指定条件下的要素{0}".format(expression)
tempLayer = "block_layer"
# SearchCursor
fcount = len([feature[0] for feature in arcpy.da.SearchCursor(in_features, "SHAPE_AREA", expression)])
while (fcount > 0):
print('fcount:{0} Time : {1} s'.format(fcount, time.time() - time_begin))
tempLayer = "{0}_b".format(tempLayer)
# MakeFeatureLayer
arcpy.MakeFeatureLayer_management(in_features, tempLayer)
in_features = "{0}_E".format(in_features)
if arcpy.Exists(in_features):
arcpy.Delete_management(in_features)
# SelectLayerByAttribute to define feature to be eliminated
arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION", expression)
# Eliminate
arcpy.Eliminate_management(tempLayer, in_features, "AREA")
fcount2 = len([feature[0] for feature in arcpy.da.SearchCursor(in_features, "SHAPE_AREA", expression)])
if fcount2 == fcount:
break
else:
fcount = fcount2
print "Total Time {0}".format(time.time() - time_begin)
except Exception, e:
print e.message.decode("utf_8")