Opened 13 years ago

Closed 13 years ago

#2775 closed enhancement (fixed)

Shapefile reading ignores in-geometry bounding box

Reported by: crschmidt Owned by: warmerdam
Priority: normal Milestone: 1.7.0
Component: OGR_SF Version: 1.6.0
Severity: normal Keywords: Shape


The shapefile layer ignores the in-.shp geometry bounding box, meaning that calculating the bounds is an expensive operation -- especially for large polygons, where "orgnaizePolygon" needs to be called, with expensive point-in-polygon checks for inner/outer status by default.

Since Shapefiles have the bbox information built in, it would be helpful for cases where there is no .qix file to use this information, since it saves the more expensive check.

Another case that this helps accelerate is the case where there is a large filter in the root node of the spatial index (/.qix) file: In that case, *all* queries require the full organize polygon call in GetNextFeature?, because it is part of reading the geometry from the shapefile. The end result is that all queries against a layer -- even ones which intersect no features at all -- may take a long time, because every iteration of the layer has the expensive polygon organizing code called.

(Filed at the request of FrankW.)

Attachments (3)

shape.patch (9.4 KB) - added by crschmidt 13 years ago.
shape.2.patch (9.4 KB) - added by crschmidt 13 years ago.
shape.3.patch (3.5 KB) - added by crschmidt 13 years ago.

Download all attachments as: .zip

Change History (7)

Changed 13 years ago by crschmidt

Attachment: shape.patch added

comment:1 Changed 13 years ago by crschmidt

Changes in this patch:

New function: OGRShapeLayer::FetchShape?. Checks whether the layer has a BBOX filter, and if so, checks the shape first -- returning a feature if it matches, and nothing if it is outside.

New function:

 OGRGeometry *SHPReadOGRObject( SHPObject *psShape ) { 

This function is like the SHPReadOGRObject(SHPHandle, int) function used to be. the shp/int version is now just a wrapper around this that actually reads from the file: converting the SHPObject shape into an OGR Geometry is all moved into this new function.

SHPReadOGRFeature (..., psShape) -- take a psShape and build a feature from it. Currently, this is a cargo cult; I couldn't figure out the right way to abstract this out to reduce duplication of code.

Not completely done yet.

Changed 13 years ago by crschmidt

Attachment: shape.2.patch added

comment:2 Changed 13 years ago by crschmidt

Second patch is simpler, but has a possible performance hit, because it reads geometries from the file twice when querying with a spatial filter.

comment:3 Changed 13 years ago by crschmidt

(I should add that the first patch causes segfaults in most cases; it was my first attempt, but I don't have the C/C++ chops to make it actually work.)

Changed 13 years ago by crschmidt

Attachment: shape.3.patch added

comment:4 Changed 13 years ago by warmerdam

Keywords: Shape added
Resolution: fixed
Status: newclosed

Variation on the patch applied in trunk (r16076). Slightly altered to avoid rereading the shape, and to account for a few special cases, like reading .dbf files and handling SHPT_NULL shapes.

Thanks Chris!

Note: See TracTickets for help on using tickets.