Permalink
Browse files

OGR Spatialite: avoid useless CAST() in filter, and use join for spat…

…ial filtering.

SQLite cannot use attribute indexes if the WHERE clause use CAST(foo AS text) instead
of foo.

Rework the way spatial filtering is done to do a JOIN on the idx_table_geometry virtual
table instead of using the SpatialIndex virtual table. This will help the query planner
to use an attribute filter first when this is more relevant.

CREDITS: Funded by:
Regione Toscana - Settore Sistema Informativo Territoriale ed
Ambientale (CIG: 644544015A)
  • Loading branch information...
1 parent 3d52307 commit 22dc081f1060ca40e0b209e7bb3e9aa0ca8b5ac3 @rouault rouault committed Dec 1, 2016
View
Oops, something went wrong.
Binary file not shown.
@@ -0,0 +1,41 @@
+Content-Type: text/xml; charset=UTF-8
+
+<?xml version='1.0' encoding="UTF-8" ?>
+<wfs:FeatureCollection
+ xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
+ xmlns:wfs="http://www.opengis.net/wfs"
+ xmlns:gml="http://www.opengis.net/gml"
+ xmlns:ogc="http://www.opengis.net/ogc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
+ http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=road&amp;OUTPUTFORMAT=XMLSCHEMA">
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:3978">
+ <gml:coordinates>2442115.250000,245881.250000 2446614.500000,262496.843750</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <gml:featureMember>
+ <ms:road fid="road.1523">
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:3978">
+ <gml:coordinates>2442115.250000,245881.250000 2446614.500000,262496.843750</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:LineString srsName="EPSG:3978">
+ <gml:coordinates>2442115.250000,262496.843750 2442339.750000,261851.750000 2446590.500000,249634.640625 2446614.500000,245881.250000 </gml:coordinates>
+ </gml:LineString>
+ </ms:msGeometry>
+ <ms:FNODE_>754</ms:FNODE_>
+ <ms:TNODE_>785</ms:TNODE_>
+ <ms:LPOLY_>0</ms:LPOLY_>
+ <ms:RPOLY_>0</ms:RPOLY_>
+ <ms:LENGTH>17371.988</ms:LENGTH>
+ <ms:ROAD_ID>1523</ms:ROAD_ID>
+ <ms:F_CODE>67</ms:F_CODE>
+ <ms:NAME_E>Trans-Canada Highway</ms:NAME_E>
+ <ms:NAME_F>route Transcanadienne</ms:NAME_F>
+ </ms:road>
+ </gml:featureMember>
+</wfs:FeatureCollection>
+
@@ -0,0 +1,133 @@
+Content-Type: text/xml; charset=UTF-8
+
+<?xml version='1.0' encoding="UTF-8" ?>
+<wfs:FeatureCollection
+ xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
+ xmlns:wfs="http://www.opengis.net/wfs"
+ xmlns:gml="http://www.opengis.net/gml"
+ xmlns:ogc="http://www.opengis.net/ogc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
+ http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=towns_spatial_index_disabled&amp;OUTPUTFORMAT=XMLSCHEMA">
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>660036.840000,4879402.970000 690357.250000,4892926.890000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+<!-- WARNING: FeatureId item 'ID' not found in typename 'towns_spatial_index_disabled'. -->
+ <gml:featureMember>
+ <ms:towns_spatial_index_disabled>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>660036.840000,4885407.410000 660036.840000,4885407.410000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>660036.840000,4885407.410000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Sambuca Pistoiese</ms:name>
+ <ms:peoples>1604</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:towns_spatial_index_disabled>
+ </gml:featureMember>
+ <gml:featureMember>
+ <ms:towns_spatial_index_disabled>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>672279.270000,4879402.970000 672279.270000,4879402.970000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>672279.270000,4879402.970000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Vernio</ms:name>
+ <ms:peoples>5535</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:towns_spatial_index_disabled>
+ </gml:featureMember>
+ <gml:featureMember>
+ <ms:towns_spatial_index_disabled>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>666989.570000,4892926.890000 666989.570000,4892926.890000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>666989.570000,4892926.890000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Camugnano</ms:name>
+ <ms:peoples>2132</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:towns_spatial_index_disabled>
+ </gml:featureMember>
+ <gml:featureMember>
+ <ms:towns_spatial_index_disabled>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>662773.000000,4891987.410000 662773.000000,4891987.410000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>662773.000000,4891987.410000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Castel di Casio</ms:name>
+ <ms:peoples>3174</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:towns_spatial_index_disabled>
+ </gml:featureMember>
+ <gml:featureMember>
+ <ms:towns_spatial_index_disabled>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>673068.120000,4889949.750000 673068.120000,4889949.750000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>673068.120000,4889949.750000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Castiglione dei Pepoli</ms:name>
+ <ms:peoples>6008</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:towns_spatial_index_disabled>
+ </gml:featureMember>
+ <gml:featureMember>
+ <ms:towns_spatial_index_disabled>
+ <gml:boundedBy>
+ <gml:Box srsName="EPSG:32632">
+ <gml:coordinates>690357.250000,4888070.830000 690357.250000,4888070.830000</gml:coordinates>
+ </gml:Box>
+ </gml:boundedBy>
+ <ms:msGeometry>
+ <gml:Point srsName="EPSG:32632">
+ <gml:coordinates>690357.250000,4888070.830000</gml:coordinates>
+ </gml:Point>
+ </ms:msGeometry>
+ <ms:name>Firenzuola</ms:name>
+ <ms:peoples>4812</ms:peoples>
+ <ms:localcounc>1</ms:localcounc>
+ <ms:county>0</ms:county>
+ <ms:region>0</ms:region>
+ </ms:towns_spatial_index_disabled>
+ </gml:featureMember>
+</wfs:FeatureCollection>
+
@@ -12,26 +12,26 @@ Content-Type: text/xml; subtype="gml/3.2.1"; charset=UTF-8
next="http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=2.0.0&amp;REQUEST=GetFeature&amp;TYPENAMES=towns&amp;COUNT=1&amp;STARTINDEX=3">
<wfs:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::32632">
- <gml:lowerCorner>641470.51000 4898995.21000</gml:lowerCorner>
- <gml:upperCorner>641470.51000 4898995.21000</gml:upperCorner>
+ <gml:lowerCorner>656907.12000 4886687.84000</gml:lowerCorner>
+ <gml:upperCorner>656907.12000 4886687.84000</gml:upperCorner>
</gml:Envelope>
</wfs:boundedBy>
<!-- WARNING: FeatureId item 'ID' not found in typename 'towns'. -->
<wfs:member>
<ms:towns>
<gml:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::32632">
- <gml:lowerCorner>641470.51000 4898995.21000</gml:lowerCorner>
- <gml:upperCorner>641470.51000 4898995.21000</gml:upperCorner>
+ <gml:lowerCorner>656907.12000 4886687.84000</gml:lowerCorner>
+ <gml:upperCorner>656907.12000 4886687.84000</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<ms:msGeometry>
<gml:Point gml:id=".1" srsName="urn:ogc:def:crs:EPSG::32632">
- <gml:pos>641470.51000 4898995.21000</gml:pos>
+ <gml:pos>656907.12000 4886687.84000</gml:pos>
</gml:Point>
</ms:msGeometry>
- <ms:name>Sestola</ms:name>
- <ms:peoples>2670</ms:peoples>
+ <ms:name>Granaglione</ms:name>
+ <ms:peoples>2116</ms:peoples>
<ms:localcounc>1</ms:localcounc>
<ms:county>0</ms:county>
<ms:region>0</ms:region>
Oops, something went wrong.

0 comments on commit 22dc081

Please sign in to comment.