使用ArcPy拓撲檢查的基本步驟

拓撲檢查是GIS的特性,在ArcGIS可以使用多種方法進行檢查,包括:python

一、在數據集上右鍵按嚮導創建;工具

二、使用拓撲工具箱的一系列工具分步創建;spa

三、建立模型工具,製做專門的拓撲工具;code

四、利用ArcPy靈活定製拓撲檢查腳本;blog

五、使用ITopologyContainer等接口二次開發。接口

基本步驟

不管使用哪一種方式,拓撲檢查都離不開如下的步驟:ip

建立拓撲:在數據集上新建一個用於拓撲的容器;utf-8

添加要素類:必須將須要參與拓撲檢查的要素類添加到同一數據集的拓撲容器中;開發

設置容差:通常能夠不設置,默認地理座標是0.000000008983153度,投影座標是0.0002米;it

添加規則:根據檢查要素添加點、線、面的拓撲規則;

驗證拓撲:若是前面步驟沒有報錯,表示建立拓撲完成,能夠開始驗證了;

查看結果:可能經過拓撲工具條查看拓撲結果,也能夠導出爲錯誤要素記錄;

修改錯誤:拓撲檢查的目的是修改拓撲錯誤,不一樣的錯誤有相應的修改方式。

使用示例

下面是一個拓撲檢查的示例,先由模型工具製做後,直接導出ArcPy腳本稍做修改(ESRI是否是很強大)。

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Fun   : NcTopology
# Author: gisweis
# Date  : 2019.10.8
# Email : 
# Notes : 
# ---------------------------------------------------------------------------


# Set the necessary product code
import arceditor
import arcpy
import os

# Script arguments
db = arcpy.GetParameterAsText(0)

arcpy.env.workspace = db
arcpy.env.overwriteOutput = True

# Local variables:
StrDataset = "StrDataset"
TraDataset = "TraDataset"
GQ_HOUA="GQ_HOUA"
GQ_BUIA="GQ_BUIA"
GQ_LRDA="GQ_LRDA"
GQ_LRRA="GQ_LRRA"

StrDataset_TP1 = "StrDataset_TP1"
StrDataset_TP1_PATH = StrDataset + os.sep + StrDataset_TP1

Not_Overlap = "Must Not Overlap (Area)"
Not_Gaps="Must Not Have Gaps (Area)"
BeCovered="Must Be Covered By Feature Class Of (Area-Area)"
Not_OverlapWith="Must Not Overlap With (Area-Area)"

# Process1: Create Topology
arcpy.CreateTopology_management(StrDataset, StrDataset_TP1, "")

# Process2: Add FeatureClass
arcpy.AddFeatureClassToTopology_management(StrDataset_TP1_PATH, GQ_HOUA, "1", "1")
arcpy.AddFeatureClassToTopology_management(StrDataset_TP1_PATH, GQ_BUIA, "1", "1")

arcpy.Copy_management(TraDataset + os.sep +GQ_LRDA, StrDataset + os.sep + GQ_LRDA+"_1", "")
arcpy.AddFeatureClassToTopology_management(StrDataset_TP1_PATH, GQ_LRDA+"_1", "1", "1")

arcpy.Copy_management(TraDataset + os.sep +GQ_LRRA, StrDataset + os.sep + GQ_LRRA+"_1", "")
arcpy.AddFeatureClassToTopology_management(StrDataset_TP1_PATH, GQ_LRRA+"_1", "1", "1")

# Process3: Set Tolerance
arcpy.SetClusterTolerance_management(StrDataset_TP1_PATH, "8.98315284119521E-09")

# Process4: Add Rule
arcpy.AddRuleToTopology_management(StrDataset_TP1_PATH, Not_Overlap, GQ_HOUA, "", "", "")
arcpy.AddRuleToTopology_management(StrDataset_TP1_PATH, Not_Overlap, GQ_BUIA, "", "", "")
arcpy.AddRuleToTopology_management(StrDataset_TP1_PATH, BeCovered, GQ_BUIA, "", GQ_HOUA, "")
arcpy.AddRuleToTopology_management(StrDataset_TP1_PATH, Not_OverlapWith, GQ_HOUA, "", GQ_LRDA+"_1", "")
arcpy.AddRuleToTopology_management(StrDataset_TP1_PATH, Not_OverlapWith, GQ_HOUA, "", GQ_LRRA+"_1", "")
# arcpy.AddRuleToTopology_management(StrDataset_TP1_PATH, Not_Gaps, GQ_HOUA, "", "", "")
# arcpy.AddRuleToTopology_management(StrDataset_TP1_PATH, Not_Gaps, GQ_BUIA, "", "", "")

# Process5: Validate Topology
arcpy.ValidateTopology_management(StrDataset_TP1_PATH)

# Process6: Delete
# 
# arcpy.Delete_management( StrDataset + os.sep +GQ_LRDA+"_1")
# arcpy.Delete_management( StrDataset + os.sep +GQ_LRRA+"_1")
相關文章
相關標籤/搜索