使用ArcPy拓扑检查的基本步骤

拓扑检查是GIS的特性,在ArcGIS可使用多种方法进行检查,包括:

1、在数据集上右键按向导建立;

2、使用拓扑工具箱的一系列工具分步建立;

3、创建模型工具,制作专门的拓扑工具;

4、利用ArcPy灵活定制拓扑检查脚本;

5、使用ITopologyContainer等接口二次开发。

基本步骤

无论使用哪种方式,拓扑检查都离不开以下的步骤:

创建拓扑:在数据集上新建一个用于拓扑的容器;

添加要素类:必须将需要参与拓扑检查的要素类添加到同一数据集的拓扑容器中;

设置容差:一般可以不设置,默认地理坐标是0.000000008983153度,投影坐标是0.0002米;

添加规则:根据检查要素添加点、线、面的拓扑规则;

验证拓扑:如果前面步骤没有报错,表示创建拓扑完成,可以开始验证了;

查看结果:可能通过拓扑工具条查看拓扑结果,也可以导出为错误要素记录;

修改错误:拓扑检查的目的是修改拓扑错误,不同的错误有相应的修改方式。

使用示例

下面是一个拓扑检查的示例,先由模型工具制作后,直接导出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")

  

posted @ 2019-10-09 09:15  我也是个傻瓜  阅读(2812)  评论(0编辑  收藏  举报