This project is read-only.

Shapefile.IsSpatialIndexValid Issue?

Jan 9, 2013 at 4:16 PM

Hi All,

This function returns false for all of my shapefiles, which come from several different sources. I've tried Shapefile.FixUpShapes but IsSpatialIndexValid continues to return false. Has anyone else seen this? I understand ESRI has a "Shapechecker" tool that will rebuild a .shx, but I don't have an easy way to test this.

By the way, all but one of my shapefiles appear to work fine. I was driven to explore IsSpatialIndexValid because Shapefile.SelectShapes produces incorrect results on one of my shapefiles--which works fine--after I perform a Shapefile.Dissolve to create a new shapefile. Interestingly, in this case Shape.Distance produces the correct results in spite of the .SelectShapes issue. So this is an effective workaround if anyone has experienced the same issue.

Don Rahmlow
Readfield, ME, US 

Jan 11, 2013 at 7:44 AM

Hi Don,

Spatial indexes are specific to MapWindow. Meaning you have to create a spatial index with MapWindow first before IsSpatialIndexValid() will return true.
You can also look at HasSpatialIndex:

About your SelectShapes issue. Did you try running FixUpShapes() on that file? You can also use HasInvalidShapes() first, if it returns false you don't need to fix it first.


Jan 11, 2013 at 4:14 PM

Hi Paul,

Thanks much for the quick response. Regarding my SelectShapes issue, I can't find the HasInvalidShapes() function, but, no matter, as FixUpShapes() does not help anyway.

To summarize the strange behavior, which seems impossible to me, it has to be my problem or simply an illusion, yet I can't find anything I am doing that is wrong:

  1. Open sf1
  2. Test functionality of SelectShapes; works fine
  3. Merge sf1 to create sf2
  4. FixUpShapes sf2
  5. Exercise SelectShapes; sometimes selects shapes that lie well outside the tolerance (which is zero)

While I realize that (a) it is unrealistic to hope this can/will be "fixed" programmatically, and (b) there is an effective workaround (using Shape.Distance as a secondary confirming test), if you would like to take a look just out of academic curiosity I'd be happy to send you a simple sample VS project and shapefile. I have spent many hours scratching my head on this one. You can draw a bounding box where there are no shapes, yet a shape gets selected!

By the way, the merged shapefile appears to perform as it should for all other functions, and in other GIS packages (QGIS), although I don't know of a good way to test the equivalent of SelectShapes there.

Thank you and have a wonderful weekend!


Jan 14, 2013 at 8:05 AM

Hi Don,

Can you send or attach the shapefile? I will have a look at it.