Repair Geometry (Data Management)

License Level:BasicStandardAdvanced

Summary

Inspects each feature in a feature class for geometry problems. Upon discovery of a geometry problem, a relevant fix will be applied, and a one line description will be printed identifying the feature as well as the problem encountered.

Valid inputs are shapefiles, personal and file geodatabase feature classes.

Learn more about checking and repairing geometries

Usage

Syntax

RepairGeometry_management (in_features, {delete_null})
ParameterExplanationData Type
in_features

The feature class or layer that will be repaired. Valid input features are shapefiles and personal and file geodatabase feature classes.

Feature Layer
delete_null
(Optional)

Specifies what action to take on null geometries.

  • DELETE_NULL Features which have NULL geometry will be deleted from the input. This is the default.
  • KEEP_NULL Features which have NULL geometry will NOT be deleted from the input.
Boolean

Code Sample

Repair Geometry example (Python window)

The following Python Window script demonstrates how to use the RepairGeometry function in immediate mode.

import arcpy
arcpy.RepairGeometry_management ("c:/data/sketchy.shp")
Repair Geometry example 2 (stand-alone script)

The following stand-alone script is an example of how to apply the RepairGeometry function in scripting.

# 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)

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015