Back to 5.0.0-doc main page
about GetShapefileExtent()
Starting since version 5.0.0 libspatialite supports a new SQL function related to VirtualShape Tables that is specifically intended to quickly retrieve the Full Extent of the underlaying Shapefile.Just a short recall about Shapefiles:
- Any Shapefile is always expected to declare its own full extent (aka overal BBOX) within its Header Block.
- So there is no need to perform a (slow) full-table-scan in order to compute the full extent, simply because this information is contained in the header declaration and is thus immediately available.
- Since VirtualShapes are always considered by SpatiaLite as read-only Tables, the BBOX declaration found in the header block can never change.
The new GetShapefileExtent() SQL function directly queries the full extent declared into the shapefile's header block, so it's expected to be very fast even when the shapefile contains an huge number of Features.
Example
We'll start by creating a VirtualShape Table:CREATE VIRTUAL TABLE test USING VirtualShape('./someshapefile', 'CP1252', 4326);and now we are ready to check the VirualShape's Full Extent:
SELECT AsEWKT(GetShapefileExtent('test')); ------- SRID=4326;POLYGON((6.626621360000058 35.49285259200007,18.52038155300005 35.49285259200007,18.52038155300005 47.09178374200007,6.626621360000058 47.09178374200007,6.626621360000058 35.49285259200007))Please note:
- A Geometry of the Polygon type (namely a rectangle) has been returned and it represents the shapefile's BBOX.
- If any error occurs (argument of the wrong type or not existing VirtualShape) then a NULL will be returned.
Caveat |
---|
If two (or more) VirtualShapes exist within the same DB connection exactly sharing an identical Table-name (obviously, each one being located on a different ATTACHED-DB) the result returned by GetShapefileExtent() will be unpredictable. |
Back to 5.0.0-doc main page