Skip to content

Commit

Permalink
WFS: fix paging with GPKG/Spatialite datasources and non-point geomet…
Browse files Browse the repository at this point in the history
…ries (fixes MapServer#6325)
  • Loading branch information
rouault authored and RoelvandenBerg committed Jun 2, 2021
1 parent 7c05724 commit 20ef0a2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
24 changes: 20 additions & 4 deletions mapogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2368,16 +2368,32 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps
msFree(points);
filter = msStringConcatenate(filter, "))");
}
else if( psInfo->dialect && EQUAL(psInfo->dialect, "Spatialite") &&
psInfo->pszMainTableName != NULL && !psInfo->bHasSpatialIndex )
else if( psInfo->dialect &&
(EQUAL(psInfo->dialect, "Spatialite") ||
EQUAL(psInfo->dialect, "GPKG")) &&
psInfo->pszMainTableName != NULL )
{
const bool isGPKG = EQUAL(psInfo->dialect, "GPKG");
if (filter) filter = msStringConcatenate(filter, " AND");
const char *col = OGR_L_GetGeometryColumn(psInfo->hLayer); // which geom field??
filter = msStringConcatenate(filter, " MbrIntersects(\"");
filter = msStringConcatenate(filter, " Intersects(");
if( isGPKG )
{
// Casting GeoPackage geometries to spatialie ones is done
// automatically normally, since GDAL enables the
// "amphibious" mode, but without it
// explicilty specified, spatialite 4.3.0a does an
// out-of-bounds access.
filter = msStringConcatenate(filter, "GeomFromGPB(");
}
filter = msStringConcatenate(filter, "\"");
char* escaped = msLayerEscapePropertyName(layer, col);
filter = msStringConcatenate(filter, escaped);
msFree(escaped);
filter = msStringConcatenate(filter, "\", BuildMbr(");
filter = msStringConcatenate(filter, "\"");
if( isGPKG )
filter = msStringConcatenate(filter, ")");
filter = msStringConcatenate(filter, ", BuildMbr(");
char *points = (char *)msSmallMalloc(30*2*5);
snprintf(points, 30*4, "%lf,%lf,%lf,%lf", rect.minx, rect.miny, rect.maxx, rect.maxy);
filter = msStringConcatenate(filter, points);
Expand Down
36 changes: 36 additions & 0 deletions msautotest/wxs/expected/wfs_ogr_gpkg_issue_6325.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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=test_6325&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"
next="http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=2.0.0&amp;REQUEST=GetFeature&amp;TYPENAMES=test_6325&amp;BBOX=0.75%2C0.75%2C9%2C9&amp;COUNT=1&amp;STARTINDEX=1">
<wfs:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326">
<gml:lowerCorner>0.00000 0.00000</gml:lowerCorner>
<gml:upperCorner>10.00000 10.00000</gml:upperCorner>
</gml:Envelope>
</wfs:boundedBy>
<wfs:member>
<ms:test_6325 gml:id="test_6325.2">
<gml:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326">
<gml:lowerCorner>0.00000 0.00000</gml:lowerCorner>
<gml:upperCorner>10.00000 10.00000</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<ms:msGeometry>
<gml:LineString gml:id="test_6325.2.1" srsName="urn:ogc:def:crs:EPSG::4326">
<gml:posList srsDimension="2">0.00000 0.00000 10.00000 10.00000 </gml:posList>
</gml:LineString>
</ms:msGeometry>
<ms:id>2</ms:id>
<ms:WKT>LINESTRING(0 0,10 10)</ms:WKT>
</ms:test_6325>
</wfs:member>
</wfs:FeatureCollection>

0 comments on commit 20ef0a2

Please sign in to comment.