Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to write some c# code to delete duplicate rows from a shapefile stored in a folder.

Can anyone provide me with an example or pointers on the best way to attempt this, please?

share|improve this question
how do you define duplicate? – iant Dec 7 '12 at 8:24
duplicate geometry or duplicate attribute? – vinayan Dec 7 '12 at 8:35
Actually i used clip method from IBasiGeoProcessor interface to clip a shapefile with a given boundary. The output shapefile shows some duplicate rows(i.e., two fid denoting same feature). – Navish Dec 7 '12 at 8:47
Perhaps you can provide some screenshots of the geometry being affected. Most likely they are legitimate features that were split during the clip operation. – blah238 Dec 7 '12 at 10:54
@Navish, a simple google search (e.g. arcobjects find dupoicate featuers) should give you a number of code snippets of how to do this. – artwork21 Dec 7 '12 at 12:21

To remove duplicate geometry with different fid you may use an algorithm like:

List<IFeature> features = GetAllFeatures(featureClass)
foreach(var feature in features)
    string query = "OIDFieldName = feature.OID";
    List<IFeature> queryFeatures = GetFeaturesBasedOnQuery(featureClass, query);
    foreach(var queryFeature in queryFeatures)
         List<IFeature> sameLocationFeatures = GetFeaturesBySameLocation(featureClass, queryFeature.Shape);
         for (int i = 1; i < sameLocationFeatures.Count; i++)

To get features based on location you may use following code snippent:

    public IFeatureCursor GetFeaturesBySameLocation(IFeatureClass featureClass, IGeometry queryGeometry)
        string shapeFieldName = featureClass.ShapeFieldName;
        ISpatialFilter spatialFilter = new SpatialFilter();
        spatialFilter.Geometry = queryGeometry;
        spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
        spatialFilter.set_OutputSpatialReference(shapeFieldName, spatialReferance);

        IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
        return featureCursor ;

Code snippet for getting all features of a layer:

    public IFeatureCursor GetAllFeatureOfLayer(IFeatureClass featureClass)
        IFeatureCursor featureCursor = featureClass.Search(null, false);
        return featureCursor;

Code snippet for getting features based on query from a layer:

    public IFeatureCursor GetFeaturesBasedOnQuery(IFeatureClass featureClass, string query)
        IQueryFilter queryFilter = new QueryFilterClass();        
        queryFilter.WhereClause = query;
        IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);

        return featureCursor;
share|improve this answer
This algorithm will delete (all-1) features in a same location. – Emi Jan 7 '13 at 4:49
@Navish: Doesn't this what you are looking for? – Emi Jan 8 '13 at 7:12

I have a python code to delete duplicate geometry..

code snippet:

gp.SelectLayerByAttribute_management(featureverticeshp_Layer, "NEW_SELECTION", gbgquery)    
gp.SelectLayerByLocation_management(featureverticeshp_Layer, "ARE_IDENTICAL_TO", featureverticeshp_Layer, "", "NEW_SELECTION")    
gp.SelectLayerByAttribute_management(featureverticeshp_Layer, "REMOVE_FROM_SELECTION", gbgquery)    

If you want I can provide the entire code (author name: Gerry Gabrisch). (I forgot from where I download it, but works fine with shape file).

share|improve this answer

Now just convert this shape file tp featureclass and open this using Access and find out those duplicate records and delete those..

share|improve this answer
It sounds like a programmatic solution is being asked for. Besides, messing with a personal geodatabase feature class's attribute table in Access is likely to corrupt it. – blah238 Dec 7 '12 at 10:51
Actually same feature is being denoted by two or in some cases more than two fid. – Navish Dec 7 '12 at 11:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.