[GIS] Near analysis with mixed feature types in ArcObjects

arcobjectsc

I am trying to emulate the Near (analysis) ArcGIS tool in ArcObjects. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00080000001q000000

I want to use Mixed Feature Types. I have a point, polygon and line feature class and I want to use Near to compare all three of them with each other. This can be done one featureclass at a time like so (pseudocode logic):

  1. Create IFeatureIndex

  2. Store my feature class in IFeatureIndex.FeatureClass

  3. Use IIndexQuery.NearestFeature for every IGeometry in a feature class to get distance to the nearest feature

The problem I am running into is that I can only store one feature class in IFeatureIndex. I need to store three different feature classes (points, lines and polygons) to be able to properly execute my comparison. How can I do this? ESRI's feature that I linked above has managed to do this but there is unfortunately no way to peek at the code behind the geoprocessing tool that I know of.

Edit: I have solved this. See the answer below.

Best Answer

enter image description here

You might consider using a spatial cache via ISpatialCacheManager3. The documentation doesn't say if all the featureclasses in the cache need to be in the same workspace, see the Using spatial caching to optimize spatial queries section. I'd be very curious if that is the case.

Here's a snippet from that page:

// Open the feature classes used by the queries.
IFeatureClass blocksFeatureClass = featureWorkspace.OpenFeatureClass("Blocks");
IFeatureClass parcelsFeatureClass = featureWorkspace.OpenFeatureClass("Parcels");

// Fill the spatial cache.
ISpatialCacheManager spatialCacheManager = (ISpatialCacheManager)featureWorkspace;

// Check if the cache has been filled.
if (!spatialCacheManager.CacheIsFull)
{
    // If not full, fill the cache.
    spatialCacheManager.FillCache(cacheExtent);
}

// Execute spatial queries.

// Empty the cache.
spatialCacheManager.EmptyCache();