在生產中,經常會遇見有圖斑重疊這種拓撲錯誤的矢量,大部分情況下,需要人工比對影像處理。但是如果只需要用到這些矢量的形狀、面積,可以在ArcMap中用以下方法,快速消除圖斑重疊錯誤,不必手工處理。
如下圖所示,兩個圖斑存在重疊部分。
首先,使用 Intersect 工具,得到矢量所有相交部分,這時,相交結果矢量里,每一個圖斑都有一個或以上形狀完全相同的圖斑存在。然后,使用 Delete Identical 工具,刪除形狀相同的其他圖斑,刪除結果就是矢量里所有相交的部分。
最后,使用 Update 工具,將刪除結果更新到源矢量里,這樣就將所有重疊部分獨立出來,成為單獨的圖斑。
把這些步驟,寫入腳本保存。
# coding:utf-8
import os
import arcpy
def GetNewFileName(dir, baseName):
for i in range(1, 100):
if not os.path.exists(os.path.join(dir, baseName + str(i))):
return os.path.join(dir, baseName + str(i))
return os.path.join(dir, baseName)
overlapedShp = arcpy.GetParameterAsText(0)
resultShp = arcpy.GetParameterAsText(1)
resultDir = os.path.split(resultShp)[0]
intersectedShp = GetNewFileName(resultDir, 'temp') + '.shp'
arcpy.Intersect_analysis([overlapedShp], intersectedShp)
arcpy.DeleteIdentical_management(intersectedShp, ['shape'])
arcpy.Update_analysis(overlapedShp, intersectedShp, resultShp)
arcpy.Delete_management(intersectedShp)