Skip to content
Permalink
Browse files

Shape tileindex: fix issues (crash and invalid result) related with i…

…nteractiosn between msTiledSHPNextShape() and msTiledSHPGetShape()
  • Loading branch information
rouault committed Mar 30, 2017
1 parent 0f7c181 commit 1aea33ab9a725dadf2358270570f3bf6b52d3b07
@@ -1934,6 +1934,10 @@ int msTiledSHPOpenFile(layerObj *layer)

msTiledSHPLayerInfo *tSHP=NULL;

if (layer->layerinfo != NULL) {
return MS_SUCCESS; // Nothing to do... layer is already opened
}

if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE )
return MS_FAILURE;

@@ -2206,6 +2210,7 @@ int msTiledSHPNextShape(layerObj *layer, shapeObj *shape)
continue;
} else if(status != MS_SUCCESS) {
msShapefileClose(tSHP->shpfile);
tSHP->tileshpfile->lastshape = -1;
return(MS_FAILURE);
}

@@ -2214,7 +2219,10 @@ int msTiledSHPNextShape(layerObj *layer, shapeObj *shape)
break;
}

if(status == MS_DONE) return(MS_DONE); /* no more tiles */
if(status == MS_DONE) {
tSHP->tileshpfile->lastshape = -1;
return(MS_DONE); /* no more tiles */
}
else {
msFreeShape(&tshape);
continue; /* we've got shapes */
@@ -2248,6 +2256,7 @@ int msTiledSHPNextShape(layerObj *layer, shapeObj *shape)
continue;
} else if(status != MS_SUCCESS) {
msShapefileClose(tSHP->shpfile);
tSHP->tileshpfile->lastshape = -1;
return(MS_FAILURE);
}

@@ -2256,7 +2265,10 @@ int msTiledSHPNextShape(layerObj *layer, shapeObj *shape)
}
} /* end for loop */

if(i == tSHP->tileshpfile->numshapes) return(MS_DONE); /* no more tiles */
if(i == tSHP->tileshpfile->numshapes) {
tSHP->tileshpfile->lastshape = -1;
return(MS_DONE); /* no more tiles */
}
else continue; /* we've got shapes */
}
}
@@ -2304,6 +2316,8 @@ int msTiledSHPGetShape(layerObj *layer, shapeObj *shape, resultObj *record)
return(MS_FAILURE);
}

msTileIndexAbsoluteDir(tiFileAbsDir, layer);

if((tileindex < 0) || (tileindex >= tSHP->tileshpfile->numshapes)) return(MS_FAILURE); /* invalid tile id */

if(tileindex != tSHP->tileshpfile->lastshape) { /* correct tile is not currenly open so open the correct tile */
@@ -2332,6 +2346,7 @@ int msTiledSHPGetShape(layerObj *layer, shapeObj *shape, resultObj *record)

msSHPReadShape(tSHP->shpfile->hSHP, shapeindex, shape);
tSHP->shpfile->lastshape = shapeindex;
tSHP->tileshpfile->lastshape = tileindex;

if(layer->numitems > 0 && layer->iteminfo) {
shape->numvalues = layer->numitems;
@@ -0,0 +1,33 @@
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=ms:test&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="1" numberReturned="1">
<wfs:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326">
<gml:lowerCorner>49.00000 2.00000</gml:lowerCorner>
<gml:upperCorner>49.00000 2.00000</gml:upperCorner>
</gml:Envelope>
</wfs:boundedBy>
<wfs:member>
<ms:test gml:id="test.1">
<gml:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326">
<gml:lowerCorner>49.00000 2.00000</gml:lowerCorner>
<gml:upperCorner>49.00000 2.00000</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<ms:msGeometry>
<gml:Point gml:id="test.1.1" srsName="urn:ogc:def:crs:EPSG::4326">
<gml:pos>49.00000 2.00000</gml:pos>
</gml:Point>
</ms:msGeometry>
</ms:test>
</wfs:member>
</wfs:FeatureCollection>

@@ -4,7 +4,7 @@
# REQUIRES: INPUT=OGR SUPPORTS=WFS
#
# In the logs, point_3_50.shp shouldn't appear
# RUN_PARMS: wfs_shp_tileindex_of_shp_bbox_filter.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&REQUEST=GetFeature&SERVICE=WFS&TYPENAMES=ms:test&VERSION=2.0.0&FILTER=<Filter><BBOX><Envelope srsName='urn:ogc:def:crs:EPSG::4326'><lowerCorner>48.9 1.9</lowerCorner><upperCorner>49.1 2.1</upperCorner></Envelope></BBOX></Filter>" > [RESULT_DEVERSION]
# RUN_PARMS: wfs_ogr_tileindex_of_shp_bbox_filter.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&REQUEST=GetFeature&SERVICE=WFS&TYPENAMES=ms:test&VERSION=2.0.0&FILTER=<Filter><BBOX><Envelope srsName='urn:ogc:def:crs:EPSG::4326'><lowerCorner>48.9 1.9</lowerCorner><upperCorner>49.1 2.1</upperCorner></Envelope></BBOX></Filter>" > [RESULT_DEVERSION]

MAP

@@ -0,0 +1,85 @@
#
# Test WFS : shapefile tileindex of shapefiles (#5291)
#
# REQUIRES: INPUT=OGR SUPPORTS=WFS
#
# In the logs, point_3_50.shp shouldn't appear
# RUN_PARMS: wfs_shape_tileindex_of_shp_bbox_filter.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&REQUEST=GetFeature&SERVICE=WFS&TYPENAMES=ms:test&VERSION=2.0.0&FILTER=<Filter><BBOX><Envelope srsName='urn:ogc:def:crs:EPSG::4326'><lowerCorner>48.9 1.9</lowerCorner><upperCorner>49.1 2.1</upperCorner></Envelope></BBOX></Filter>" > [RESULT_DEVERSION]

MAP

NAME WFS_TEST
STATUS ON
SIZE 400 300
EXTENT 1 48 4 51
IMAGECOLOR 255 255 255
SHAPEPATH "data"

#
# Start of web interface definition
#
WEB

IMAGEPATH "/tmp/ms_tmp/"
IMAGEURL "/ms_tmp/"

METADATA
"ows_updatesequence" "123"
"wfs_title" "Test simple wfs"
"wfs_onlineresource" "http://localhost/path/to/wfs_simple?"
"wfs_srs" "EPSG:4326"
"ows_abstract" "Test WFS Abstract"
"ows_keywordlist" "ogc,wfs,gml,om"
"ows_service_onlineresource" "http://localhost"
"ows_fees" "none"
"ows_accessconstraints" "none"
"ows_addresstype" "postal"
"ows_address" "123 SomeRoad Road"
"ows_city" "Toronto"
"ows_stateorprovince" "Ontario"
"ows_postcode" "xxx-xxx"
"ows_country" "Canada"
"ows_contactelectronicmailaddress" "tomkralidis@xxxxxxx.xxx"
"ows_contactvoicetelephone" "+xx-xxx-xxx-xxxx"
"ows_contactfacsimiletelephone" "+xx-xxx-xxx-xxxx"
"ows_contactperson" "Tom Kralidis"
"ows_contactorganization" "MapServer"
"ows_contactposition" "self"
"ows_hoursofservice" "0800h - 1600h EST"
"ows_contactinstructions" "during hours of service"
"ows_role" "staff"
"ows_enable_request" "*"
END
END

PROJECTION
"init=epsg:4326"
END


#
# Start of layer definitions
#


LAYER
NAME test
TILEINDEX "shp_tileindex_of_shp.shp"
TILEITEM "LOCATION"
METADATA
"wfs_title" "test"
"wfs_description" "test"
"wfs_featureid" "id"
END
TYPE POINT
STATUS ON
EXTENT 1 48 4 51
PROJECTION
"init=epsg:4326"
END

DUMP TRUE
END # Layer


END # Map File

0 comments on commit 1aea33a

Please sign in to comment.
You can’t perform that action at this time.