[GIS] Improving performance when merging features using ArcObjects

arcgis-enginearcobjectsfeaturesperformanceshapefile

I am writing an ArcGIS Engine application that can take a shapefile, and merge a set of polygons together.

Here is the code that I am using to merge the polygons:

private static void mergeFeatures(IFeature merger, IFeature mergee)
{
    ITopologicalOperator union = (ITopologicalOperator)mergee.Shape;
    mergee.Shape = union.Union(merger.Shape);
    merger.Delete();
    mergee.Store();            
}

Is this the best solution to merge polygons?

In my application this part of my code takes 60% of the execution time.

Is it slower to use a shapefile than a file geodatabase help to do this?

Just to clarify, I am taking a large set of polygons and am trying to merge ones under a certain number of acreage. From these polygons that are small, I need to merge polygons with similar attributes (for example on a vegetation layer, ones that are similar vegetation.) So this can incur a large number of small polygons getting merged together, and eliminating some of the merges can be difficult. If there is an easier way to bulk merge, then that would be best, but thus far, I have not found one.

Best Answer

Try using a profiler.

You are making multiple delete and store calls. These are expensive:

Try:

  • Reducing the number of times you call each function (store and delete);
  • Merge all polygons, store only once (or a few times, after 'n' iterations);
  • Delete only once (check ITable.DeleteSearchedRows(IFilter));

To delete only once, you can store a list of integers, those being the objectid of the features you are merging into the main feature. After that, make a single IN filter and delete them all with ITable interface (you can cast it from IFeatureClass).

Related Question