[gdal-dev] Proposed changed to solve inconsistant spatial filtering for null or empty geometries
Even Rouault
even.rouault at spatialys.com
Wed Nov 1 04:02:42 PDT 2017
Hi,
Nyall Dawson pointed to me in
https://github.com/qgis/QGIS/pull/5501#issuecomment-340934947 about a weird behaviour
of OGR spatial filtering regarding null and empty geometries.
To make it concrete, consider the following CSV file
id,WKT
1,"POLYGON EMPTY"
2,
3,"POLYGON ((0 0,0 1,1 1,0 0))"
$ ogrinfo test.csv -al -spat 0 0 1 1 -q
Layer name: test
OGRFeature(test):1
id (String) = 1
WKT (String) = POLYGON EMPTY
POLYGON EMPTY
OGRFeature(test):2
id (String) = 2
WKT (String) =
OGRFeature(test):3
id (String) = 3
WKT (String) = POLYGON ((0 0,0 1,1 1,0 0))
POLYGON ((0 0,0 1,1 1,0 0))
$ ogrinfo test.csv -al -spat 1 1 2 2 -q
Layer name: test
OGRFeature(test):2
id (String) = 2
WKT (String) =
OGRFeature(test):3
id (String) = 3
WKT (String) = POLYGON ((0 0,0 1,1 1,0 0))
POLYGON ((0 0,0 1,1 1,0 0))
So features with null geometries (FID 2) are always selected. And for a feature with an empty
geometry (FID 1), it is selected by the -spat 0 0 1 1 filter since internally the envelope of
POLYGON EMPTY is computed as xmin=xmax=ymin=ymax=0, but not by -spat 1 1 2 2
If ingesting this file into PostGIS and doing the same test, we get:
$ ogrinfo pg:dbname=autotest test -spat 0 0 1 1 -q
Layer name: test
OGRFeature(test):3
id (String) = 3
wkt (String) = POLYGON ((0 0,0 1,1 1,0 0))
POLYGON ((0 0,0 1,1 1,0 0))
$ ogrinfo pg:dbname=autotest test -spat 1 1 2 2 -q
Layer name: test
OGRFeature(test):3
id (String) = 3
wkt (String) = POLYGON ((0 0,0 1,1 1,0 0))
POLYGON ((0 0,0 1,1 1,0 0))
So null or empty geometries are never selected when a spatial filter is set. This last behaviour
seems to be the most logical for me, and I'd propose we adopt it for non-SQL based drivers
as well.
(note: the current behaviour dates back to the initial introduction of spatial filtering in OGR
per https://trac.osgeo.org/gdal/changeset/7191 , 13 years ago )
Any thought ?
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20171101/31458354/attachment-0001.html>
More information about the gdal-dev
mailing list