I have the situation where I am doing a large number of intersections and I need to do them fast. The situation is I have a iMap with 1 or more layers and a series of envelopes, lots of envelopes. I have tried the following:

        long nFeatureCount;
        iExtent->PutCoords(ulX, ulY, lrX, lrY);
        // I created an array of all the layers feature classes at the outset
        for(int i=0; i<nFeatureClassCount; i++)

            iFeatureClasses[i]->FeatureCount(iSpatialFilter, &nFeatureCount);

            if(nFeatureCount > 0)
                return true; //we have an intersection


I also tried doing a select at the map level like so:

        long nFeatureCount;
        iExtent->PutCoords(ulX, ulY, lrX, lrY);
        ipMap->SelectByShape(iExtent, NULL, VARIANT_TRUE);

        if(nFeatureCount == 0)
            return false;
            return true;

Both of these work and the iMap seems to be a bit faster when I have 5 or so layers. I was just thinking someone had encountered this and might have a faster way. I saw someone had the idea of throwing all the geometries in a IGeometryBag but wouldn't that negate the spatial indexing?

  • What format is your source data? If it is a shapefile make sure a spatial index exists as this can significantly improve the spatial query. You don't describe or show what your data is. If it is some massive dataset covering the entire extent of your area of interest then a spatial index with have little improvement, at that point you may want to "Dice" up the data?
    – Hornbydd
    Feb 21 '14 at 11:45
  • The data is in determinate, geodb or shape. This isn't a one off thing for a single data set, it's piece of software that takes data and dices it up into sloppy map tiles. This query is needed to identify area that have no features. Feb 21 '14 at 18:46

You can easily set up spatial indexing on a geometry bag for faster spatial querying. This is how you would do so in vb.net (as an example):

    Dim spatialIndex As ISpatialIndex = CType(pGeometryBag, ISpatialIndex)
    spatialIndex.AllowIndexing = True

That said, i'm not at all sure if this would be any faster than your featureclass querying, perhaps someone else will have an idea.

  • Thanks this will help. I will test all three methods soon and report the results. Feb 21 '14 at 18:47

First, the geometry bag method id not work at all. The intersection had to have certain dimensional requirements that I could not guarantee I would meet and, after a bit of tinkering I gave up on that.

The ipMap->selectByShape method took 77 seconds on my test data set and the IFClass->FeatureCount method took 70 seconds. These results were roughly the same on other data sets with both being reasonable but FeatureCount being about 10% faster. Some important notes:

1) In both cases I got the feature classes, maps, extents already created and recycled from intersection to intersection.

2) I was running about 2,000-10,000 intersections in the test runs.

3) Factors that could effect these results would be density of data (empty areas take longer in the feature class method since it will have to loop over all feature classes) and number of layers/feature classes.

In my testing the results held even in cases where the number of feature classes was increased to about 10 or so, I can't comment on more than that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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