Permalink
Browse files

[OGR] Do not install spatial filter on a layer without geometry to av…

…oid a OGR error to be triggered at msOGRFileNextShape() time (typical of a SQLite/Spatialite/GPKG SQL select layer that returns zero records) (#5317)
  • Loading branch information...
rouault committed Sep 2, 2016
1 parent 2f547e1 commit 9b8a907eb6bf076b0ab1399a55245662294c0ce1
Showing with 68 additions and 25 deletions.
  1. +27 −25 mapogr.cpp
  2. +16 −0 msautotest/wxs/expected/wfs_ogr_native_sql_39.xml
  3. +25 −0 msautotest/wxs/wfs_ogr_native_sql.map
View
@@ -2087,31 +2087,33 @@ static int msOGRFileWhichShapes(layerObj *layer, rectObj rect, msOGRFileInfo *ps
ACQUIRE_OGR_LOCK;
if (rect.minx == rect.maxx && rect.miny == rect.maxy) {
OGRGeometryH hSpatialFilterPoint = OGR_G_CreateGeometry( wkbPoint );
OGR_G_SetPoint_2D( hSpatialFilterPoint, 0, rect.minx, rect.miny );
OGR_L_SetSpatialFilter( psInfo->hLayer, hSpatialFilterPoint );
OGR_G_DestroyGeometry( hSpatialFilterPoint );
} else if (rect.minx == rect.maxx || rect.miny == rect.maxy) {
OGRGeometryH hSpatialFilterLine = OGR_G_CreateGeometry( wkbLineString );
OGR_G_AddPoint_2D( hSpatialFilterLine, rect.minx, rect.miny );
OGR_G_AddPoint_2D( hSpatialFilterLine, rect.maxx, rect.maxy );
OGR_L_SetSpatialFilter( psInfo->hLayer, hSpatialFilterLine );
OGR_G_DestroyGeometry( hSpatialFilterLine );
} else {
OGRGeometryH hSpatialFilterPolygon = OGR_G_CreateGeometry( wkbPolygon );
OGRGeometryH hRing = OGR_G_CreateGeometry( wkbLinearRing );
OGR_G_AddPoint_2D( hRing, rect.minx, rect.miny);
OGR_G_AddPoint_2D( hRing, rect.maxx, rect.miny);
OGR_G_AddPoint_2D( hRing, rect.maxx, rect.maxy);
OGR_G_AddPoint_2D( hRing, rect.minx, rect.maxy);
OGR_G_AddPoint_2D( hRing, rect.minx, rect.miny);
OGR_G_AddGeometryDirectly( hSpatialFilterPolygon, hRing );
OGR_L_SetSpatialFilter( psInfo->hLayer, hSpatialFilterPolygon );
OGR_G_DestroyGeometry( hSpatialFilterPolygon );
if( OGR_L_GetGeomType( psInfo->hLayer ) != wkbNone ) {
if (rect.minx == rect.maxx && rect.miny == rect.maxy) {
OGRGeometryH hSpatialFilterPoint = OGR_G_CreateGeometry( wkbPoint );
OGR_G_SetPoint_2D( hSpatialFilterPoint, 0, rect.minx, rect.miny );
OGR_L_SetSpatialFilter( psInfo->hLayer, hSpatialFilterPoint );
OGR_G_DestroyGeometry( hSpatialFilterPoint );
} else if (rect.minx == rect.maxx || rect.miny == rect.maxy) {
OGRGeometryH hSpatialFilterLine = OGR_G_CreateGeometry( wkbLineString );
OGR_G_AddPoint_2D( hSpatialFilterLine, rect.minx, rect.miny );
OGR_G_AddPoint_2D( hSpatialFilterLine, rect.maxx, rect.maxy );
OGR_L_SetSpatialFilter( psInfo->hLayer, hSpatialFilterLine );
OGR_G_DestroyGeometry( hSpatialFilterLine );
} else {
OGRGeometryH hSpatialFilterPolygon = OGR_G_CreateGeometry( wkbPolygon );
OGRGeometryH hRing = OGR_G_CreateGeometry( wkbLinearRing );
OGR_G_AddPoint_2D( hRing, rect.minx, rect.miny);
OGR_G_AddPoint_2D( hRing, rect.maxx, rect.miny);
OGR_G_AddPoint_2D( hRing, rect.maxx, rect.maxy);
OGR_G_AddPoint_2D( hRing, rect.minx, rect.maxy);
OGR_G_AddPoint_2D( hRing, rect.minx, rect.miny);
OGR_G_AddGeometryDirectly( hSpatialFilterPolygon, hRing );
OGR_L_SetSpatialFilter( psInfo->hLayer, hSpatialFilterPolygon );
OGR_G_DestroyGeometry( hSpatialFilterPolygon );
}
}
psInfo->rect = rect;
@@ -0,0 +1,16 @@
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=select_zero_feature&amp;OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:null>missing</gml:null>
</gml:boundedBy>
</wfs:FeatureCollection>
@@ -77,6 +77,9 @@
# 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]
#
# Spatial query on a layer (unoptimized case with a 'SELECT ... FROM ... WHERE' DATA statement) that returns zero features
# RUN_PARMS: wfs_ogr_native_sql_39.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=select_zero_feature&OUTPUTFORMAT=GML2&FILTER=<Filter><BBOX><PropertyName>Geometry</PropertyName><Box srsName='EPSG:32632'><coordinates>659159,4877386 696879,4898059</coordinates></Box></BBOX></Filter>" > [RESULT]
MAP
@@ -222,4 +225,26 @@ LAYER
TEMPLATE "wfs_ogr_native_sql.map"
END # Layer
LAYER
NAME select_zero_feature
DATA "SELECT * FROM towns WHERE 0"
CONNECTIONTYPE OGR
CONNECTION "./data/db.sqlite"
PROCESSING "NATIVE_SQL=YES"
METADATA
"ows_title" "select_zero_feature"
"wfs_featureid" "ID"
"gml_include_items" "all"
"gml_types" "auto"
"wfs_getfeature_formatlist" "ogrgml"
END
TYPE POINT
STATUS ON
PROJECTION
"init=epsg:32632"
END
TEMPLATE "wfs_ogr_native_sql.map"
END # Layer
END # Map File

0 comments on commit 9b8a907

Please sign in to comment.