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

Repair Geometry (Data Management)

Release 9.2
Last modified November 29, 2010
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Tools"


Related Topics

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. SDE Geodatabases automatically check each geometry's validity when it is uploaded, therefore the Check and Repair Geometry tools are not for use with SDE.


Usage tips

Command line syntax
An overview of the Command Line window
RepairGeometry_management <in_features>

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

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

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
# Data 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 it's
    # 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.