修复几何 (数据管理)

许可等级:BasicStandardAdvanced

摘要

检查要素类中每个要素的几何问题。发现几何问题后,将应用相关修复,并打印一行描述,以便识别要素并确定遇到的问题。

有效的输入为 shapefile、个人地理数据库要素类和文件地理数据库要素类。

了解有关检查和修复几何的详细信息

用法

语法

RepairGeometry_management (in_features, {delete_null})
参数说明数据类型
in_features

将修复的要素类或图层。有效的输入要素为 shapefile、个人地理数据库要素类和文件地理数据库要素类。

Feature Layer
delete_null
(可选)

指定要在空几何上执行的操作。

  • DELETE_NULL 从输入中删除具有“空”几何的要素。这是默认设置。
  • KEEP_NULL “不”从输入中删除具有“空”几何的要素。
Boolean

代码实例

修复几何示例(Python 窗口)

以下 Python 窗口脚本演示了如何在立即模式下使用 RepairGeometry 函数。

import arcpy arcpy.RepairGeometry_management ("c:/data/sketchy.shp")
修复几何示例 2(独立脚本)

以下独立脚本是如何在脚本中应用 RepairGeometry 函数的示例。

# Description: 
#   Goes through the table generated by the Check Geometry tool and does 
#   the following
#   1) backs-up all features which will be 'fixed' to a "_bad_geom" feature class
#   2) runs repairGeometry on all feature classes listed in the table 
# Author: ESRI

import arcpy
import os
 
# Table that was produced by Check Geometry tool
table = r"c:\temp\data.gdb\cg_sample1"
 
# Create local variables
fcs = []
 
# Loop through the table and get the list of fcs
for row in arcpy.da.SearchCursor(table, ("CLASS")):
    # Get the class (feature class) from the cursor
    if not row[0] in fcs:
        fcs.append(row[0])
 
# Now loop through the fcs list, backup the bad geometries into fc + "_bad_geom"
# then repair the fc
print "> Processing {0} feature classes".format(len(fcs))
for fc in fcs:
    print "Processing " + fc
    lyr = 'temporary_layer'
    if arcpy.Exists(lyr):
        arcpy.Delete_management(lyr)
    
    tv = "cg_table_view"
    if arcpy.Exists(tv):
        arcpy.Delete_management(tv)

    arcpy.MakeTableView_management(table, tv, ("\"CLASS\" = '%s'" % fc))
    arcpy.MakeFeatureLayer_management(fc, lyr)
    arcpy.AddJoin_management(lyr, arcpy.Describe(lyr).OIDFieldName, tv, "FEATURE_ID")
    arcpy.CopyFeatures_management(lyr, fc + "_bad_geom")
    arcpy.RemoveJoin_management(lyr, os.path.basename(table))
    arcpy.RepairGeometry_management(lyr)

环境

相关主题

许可信息

ArcGIS for Desktop Basic:是
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013