Skip to content

Commit

Permalink
[OGR] Propagate LIMIT to spatialite spatial filter sub-query, when po…
Browse files Browse the repository at this point in the history
…ssible
  • Loading branch information
rouault committed Aug 29, 2016
1 parent e6b66a6 commit e3ff20a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
27 changes: 25 additions & 2 deletions mapogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,7 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps
}
psInfo->rect = rect;

bool bOffsetAlreadyAdded = false;
// use spatial index
if (psInfo->dialect) {
if (EQUAL(psInfo->dialect, "PostgreSQL")) {
Expand Down Expand Up @@ -1983,7 +1984,29 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps
snprintf(points, 30*2*5, "%lf %lf,%lf %lf,%lf %lf,%lf %lf,%lf %lf", rect.minx, rect.miny, rect.maxx, rect.miny, rect.maxx, rect.maxy, rect.minx, rect.maxy, rect.minx, rect.miny);
filter = msStringConcatenate(filter, points);
msFree(points);
filter = msStringConcatenate(filter, "))'))");
filter = msStringConcatenate(filter, "))')");

// We put the limit in the sub-query, only if we don't have a
// order by later. We accept a startindex, provided there's no
// other attribute filter combined
if ( psInfo->bPaging && layer->maxfeatures >= 0 &&
(layer->startindex <= 0 || layer->filter.native_string == NULL) &&
layer->sortBy.nProperties == 0 )
{
char szLimit[50];
snprintf(szLimit, sizeof(szLimit), " LIMIT %d", layer->maxfeatures);
filter = msStringConcatenate(filter, szLimit);

if( layer->startindex > 0 && layer->filter.native_string == NULL )
{
bOffsetAlreadyAdded = true;
char szOffset[50];
snprintf(szOffset, sizeof(szOffset), " OFFSET %d", layer->startindex);
filter = msStringConcatenate(filter, szOffset);
}
}

filter = msStringConcatenate(filter, ")");
}
}

Expand Down Expand Up @@ -2024,7 +2047,7 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps
select = msStringConcatenate(select, szLimit);
}

if ( psInfo->bPaging && layer->startindex > 0 ) {
if ( !bOffsetAlreadyAdded && psInfo->bPaging && layer->startindex > 0 ) {
char szOffset[50];
snprintf(szOffset, sizeof(szOffset), " OFFSET %d", layer->startindex);
select = msStringConcatenate(select, szOffset);
Expand Down
14 changes: 7 additions & 7 deletions msautotest/wxs/expected/wfs_ogr_native_sql_37.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>656907.12000 4886687.84000</gml:lowerCorner>
<gml:upperCorner>656907.12000 4886687.84000</gml:upperCorner>
<gml:lowerCorner>641470.51000 4898995.21000</gml:lowerCorner>
<gml:upperCorner>641470.51000 4898995.21000</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>656907.12000 4886687.84000</gml:lowerCorner>
<gml:upperCorner>656907.12000 4886687.84000</gml:upperCorner>
<gml:lowerCorner>641470.51000 4898995.21000</gml:lowerCorner>
<gml:upperCorner>641470.51000 4898995.21000</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<ms:msGeometry>
<gml:Point gml:id=".1" srsName="urn:ogc:def:crs:EPSG::32632">
<gml:pos>656907.12000 4886687.84000</gml:pos>
<gml:pos>641470.51000 4898995.21000</gml:pos>
</gml:Point>
</ms:msGeometry>
<ms:name>Granaglione</ms:name>
<ms:peoples>2116</ms:peoples>
<ms:name>Sestola</ms:name>
<ms:peoples>2670</ms:peoples>
<ms:localcounc>1</ms:localcounc>
<ms:county>0</ms:county>
<ms:region>0</ms:region>
Expand Down
39 changes: 39 additions & 0 deletions msautotest/wxs/expected/wfs_ogr_native_sql_38.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Content-Type: text/xml; subtype="gml/3.2.1"; charset=UTF-8

<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=2.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=towns&amp;OUTPUTFORMAT=application%2Fgml%2Bxml%3B%20version%3D3.2 http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"
timeStamp="" numberMatched="unknown" numberReturned="1">
<wfs:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::32632">
<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>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>656907.12000 4886687.84000</gml:pos>
</gml:Point>
</ms:msGeometry>
<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>
</ms:towns>
</wfs:member>
</wfs:FeatureCollection>

1 change: 1 addition & 0 deletions msautotest/wxs/wfs_ogr_native_sql.map
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#
# Test COUNT, STARTINDEX
# RUN_PARMS: wfs_ogr_native_sql_37.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAMES=towns&COUNT=1&STARTINDEX=2" > [RESULT_DEVERSION]
# RUN_PARMS: wfs_ogr_native_sql_38.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=2.0.0&REQUEST=GetFeature&TYPENAMES=towns&COUNT=1&FILTER=<Filter><PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>Granaglione</Literal></PropertyIsEqualTo></Filter>" > [RESULT_DEVERSION]

MAP

Expand Down

0 comments on commit e3ff20a

Please sign in to comment.