I have a large number of polygon features in a personal geodatabase featureclass. I would like to find the nearest polygon for several points inside an area of interest(the red area in figure). enter image description here

I found IIndexQuery2.NearestFeature is a good option since it 'Finds the nearest feature in index to the input shape' as per the documentation.

At present, I do not see any way of utilizing the existing spatial index in the geodatabase through arcobjects. The only option i found is to create a temporary index using IFeatureIndex2.Index method.

My problems are with the IFeatureIndex2.Index method. I only need to index a particular group of features. There is a IFeatureIndex2.FeatureCursor option which supposedly reduces the number of features indexed. So i passed a featureCursor of the specified area to IFeatureIndex2.But mysteriously, this option only increases the time taken for index creation.

Also the Envelope parameter in the Index method (shown below) does not seem to have an effect on the performance.

public void Index (ITrackCancel pTrackCancel, IEnvelope pQueryingGeometryFullExtent));

It does not matter if null is passed or a valid envelope of Area is passed to this method as parameter. It takes same time to complete.

I tested it on a polygon featureclass with around 100000 features. The Index Method took 4 seconds Index Method with FeatureCursor took 12 seconds.

Can anyone suggest whether I am using the methods in the proper way? I might have to run this on an SDE with millions of features. So I am looking forward to indexing only the particular area so that the nearest feature queries would execute faster.

2 Answers 2


Do you have a cut-off distance for the how far you wish to search for the closest feature? If so, you might consider using ISpatialCacheManager3 instead. I've heard people have had problems with IFeatureIndex2. Once you've called FillCache, you should be able to quickly return features with IFeatureClass.Search using a small search envelope whose width and height is the size of your cut-off distance and then loop through each feature to find which is the closest.


I've read somewhere that if you set the subfields on the Queryfilter for the feature cursor, to only contain OID field and shapefield should improve the index generation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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