[gdal-dev] setting a spatial filter on a postgis layer gives wrong results

Even Rouault even.rouault at spatialys.com
Fri Jul 5 01:33:26 PDT 2019


On vendredi 5 juillet 2019 10:12:41 CEST Landry Breuil wrote:
> Hi,
> 
> initially saw this with gdal 2.2.3 on debian, and confirmed the
> behaviour is the same with gdal 3.0 on openbsd.
> 
> I'm doing a spatial join between an union of geometries filtered from a
> geopackage and a tileindex layer stored in postgis, and the spatial
> filter set on the postgis layer behaves weird, the provided result is as
> if the bbox of the spatial filter/geometry was used, instead of the
> filter itself.

This indeed exactly this. The PG driver implements spatial filtering only 
based on the envelope of the filter geometry, whereas the MEM driver uses the 
full geometry

Quoting
https://gdal.org/api/
ogrlayer_cpp.html#_CPPv4N8OGRLayer16SetSpatialFilterEP11OGRGeometry
"""
Currently this test is may be inaccurately implemented, but it is guaranteed 
that all features whose envelope (as returned by OGRGeometry::getEnvelope()) 
overlaps the envelope of the spatial filter will be returned. This can result 
in more shapes being returned that should strictly be the case.
"""

I guess the PG driver should be fixed. This is probably just an historical 
artifact.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list