Show Navigation | Hide Navigation
You are here:
Geoprocessing tool reference > Data Management toolbox > Features toolset > Tools

Repair Geometry (Data Management)

Release 9.3
Last modified March 8, 2012
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Tools"


Related Topics

NOTE: This topic was updated for 9.3.1.


Inspects each feature's geometry for problems and fixes the problems that are found. Valid input formats are shapefile and feature classes stored in a personal geodatabase or file geodatabase. For more information, see Checking and repairing geometries.

ArcSDE geodatabases automatically check each geometry's validity when it is uploaded; therefore, the Check and Repair Geometry tools are not for use with ArcSDE geodatabases.


Usage tips

Command line syntax
An overview of the Command Line window
RepairGeometry_management <in_features> {DELETE_NULL | KEEP_NULL}

Parameter Explanation Data Type
<in_features>

The feature class or layer that will have feature geometry problems repaired. If a layer is specified and that layer has a selection, only the selected features will be repaired. Valid input formats are shapefile and feature classes stored in a personal geodatabase or file geodatabase.

Feature Layer
{DELETE_NULL | KEEP_NULL}

Specifies if action should be taken when features with NULL geometry are encountered.

  • DELETE_NULL (This is the default) — Features that have NULL geometry will be deleted from the input.
  • KEEP_NULL — Features that have NULL geometry will not be deleted from the input.

Boolean
Data types for geoprocessing tool parameters


Command line example

RepairGeometry c:\myNewShapefiles\sketchy.shp"

Scripting syntax
About getting started with writing geoprocessing scripts
RepairGeometry_management (in_features, delete_null)

Parameter Explanation Data Type
in_features (Required)

The feature class or layer that will have feature geometry problems repaired. If a layer is specified and that layer has a selection, only the selected features will be repaired. Valid input formats are shapefile and feature classes stored in a personal geodatabase or file geodatabase.

Feature Layer
delete_null (Optional)

Specifies if action should be taken when features with NULL geometry are encountered.

  • DELETE_NULL (This is the default) — Features that have NULL geometry will be deleted from the input.
  • KEEP_NULL — Features that have NULL geometry will not be deleted from the input.

Boolean

Data types for geoprocessing tool parameters


Script example

# RepairGeometryProblemList.py
# Description: 
#   Goes through the table generated by the Check Geometry tool.  Runs the
#   Repair Geometry tool on the features which were identified as having 
#   some geometry problem.
# Requirements: Python and the Python win32all extension
# Author: ESRI
# Date 1/1/2004

# Create the Geoprocessor
import arcgisscripting, os
gp = arcgisscripting.create()

# Table that was produced by Check Geometry tool
table = "c:/data/badg.mdb/fc"

# Create some variables
dict = {}
query = ""
fieldName = ""

# Loop through the table using a cursor
rows = gp.searchCursor(table)
row = rows.next()

while row:
    # Get the class (feature class) for that row, as well as the Feature ID
    fc = row.GetValue("CLASS")
    fid = row.GetValue("FEATURE_ID")

    if not fieldName:
        # Determine which type feature class this is (Geodatabase or other) since how the field name
        # in the query is different for each
        fcType= gp.Describe(fc).DataType
        fieldName = gp.ListFields(fc, "*","FID").Next().Name
        if  fcType == "FeatureClass":
            fieldName = "[" + fieldName + "]"       # For Geodatabase, wrap the field name in [ ]
        elif fcType == "ShapeFile":
            fieldName = '"' + fieldName + '"'       # For ShapeFiles, wrap the field name in " "
        else:
            raise Exception, "Repair Geometry does not support this format " + fcType

    # Create the query
    if query:
        query = query + " OR " + fieldName + " = " + str(fid)
    else:
        query = fieldName + " = " + str(fid)
    prevFc = fc
    row = rows.next()

    # Since there could be more than 1 CLASS in the table, separate each CLASS and its
    # associated query into entries in a Python dictionary
    if row:
        if fc <> row.GetValue("CLASS"):
            dict[prevFc] = query
            query = ""
            fieldName = ""
    else:
        dict[prevFc] = query
        query = ""
        fieldName = ""

# Destroy the cursor object now that we're done with it
del rows

# Now loop through the dictionary and Make a layer with a definition query (so the Repair
#  Geometry is run only on those features with some problem) and run Repair Geometry on each.  
for fc in dict:
    try:
        gp.MakeFeatureLayer(fc, os.path.basename(fc),dict[fc])
        gp.RepairGeometry(fc, r"c:\junk\outy.shp")

    except:
        print "Problem encountered attempting to repair " + fc

print "FINISHED"

Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.