Skip to content

Commit 1aea33a

Browse files
committed
Shape tileindex: fix issues (crash and invalid result) related with interactiosn between msTiledSHPNextShape() and msTiledSHPGetShape()
1 parent 0f7c181 commit 1aea33a

5 files changed

+136
-3
lines changed

mapshape.c

+17-2
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,10 @@ int msTiledSHPOpenFile(layerObj *layer)
19341934

19351935
msTiledSHPLayerInfo *tSHP=NULL;
19361936

1937+
if (layer->layerinfo != NULL) {
1938+
return MS_SUCCESS; // Nothing to do... layer is already opened
1939+
}
1940+
19371941
if ( msCheckParentPointer(layer->map,"map")==MS_FAILURE )
19381942
return MS_FAILURE;
19391943

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

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

2217-
if(status == MS_DONE) return(MS_DONE); /* no more tiles */
2222+
if(status == MS_DONE) {
2223+
tSHP->tileshpfile->lastshape = -1;
2224+
return(MS_DONE); /* no more tiles */
2225+
}
22182226
else {
22192227
msFreeShape(&tshape);
22202228
continue; /* we've got shapes */
@@ -2248,6 +2256,7 @@ int msTiledSHPNextShape(layerObj *layer, shapeObj *shape)
22482256
continue;
22492257
} else if(status != MS_SUCCESS) {
22502258
msShapefileClose(tSHP->shpfile);
2259+
tSHP->tileshpfile->lastshape = -1;
22512260
return(MS_FAILURE);
22522261
}
22532262

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

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

2319+
msTileIndexAbsoluteDir(tiFileAbsDir, layer);
2320+
23072321
if((tileindex < 0) || (tileindex >= tSHP->tileshpfile->numshapes)) return(MS_FAILURE); /* invalid tile id */
23082322

23092323
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)
23322346

23332347
msSHPReadShape(tSHP->shpfile->hSHP, shapeindex, shape);
23342348
tSHP->shpfile->lastshape = shapeindex;
2349+
tSHP->tileshpfile->lastshape = tileindex;
23352350

23362351
if(layer->numitems > 0 && layer->iteminfo) {
23372352
shape->numvalues = layer->numitems;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Content-Type: text/xml; subtype="gml/3.2.1"; charset=UTF-8
2+
3+
<?xml version='1.0' encoding="UTF-8" ?>
4+
<wfs:FeatureCollection
5+
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
6+
xmlns:gml="http://www.opengis.net/gml/3.2"
7+
xmlns:wfs="http://www.opengis.net/wfs/2.0"
8+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
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"
10+
timeStamp="" numberMatched="1" numberReturned="1">
11+
<wfs:boundedBy>
12+
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326">
13+
<gml:lowerCorner>49.00000 2.00000</gml:lowerCorner>
14+
<gml:upperCorner>49.00000 2.00000</gml:upperCorner>
15+
</gml:Envelope>
16+
</wfs:boundedBy>
17+
<wfs:member>
18+
<ms:test gml:id="test.1">
19+
<gml:boundedBy>
20+
<gml:Envelope srsName="urn:ogc:def:crs:EPSG::4326">
21+
<gml:lowerCorner>49.00000 2.00000</gml:lowerCorner>
22+
<gml:upperCorner>49.00000 2.00000</gml:upperCorner>
23+
</gml:Envelope>
24+
</gml:boundedBy>
25+
<ms:msGeometry>
26+
<gml:Point gml:id="test.1.1" srsName="urn:ogc:def:crs:EPSG::4326">
27+
<gml:pos>49.00000 2.00000</gml:pos>
28+
</gml:Point>
29+
</ms:msGeometry>
30+
</ms:test>
31+
</wfs:member>
32+
</wfs:FeatureCollection>
33+

msautotest/wxs/wfs_shp_tileindex_of_shp.map msautotest/wxs/wfs_ogr_tileindex_of_shp.map

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# REQUIRES: INPUT=OGR SUPPORTS=WFS
55
#
66
# In the logs, point_3_50.shp shouldn't appear
7-
# 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]
7+
# 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]
88

99
MAP
1010

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#
2+
# Test WFS : shapefile tileindex of shapefiles (#5291)
3+
#
4+
# REQUIRES: INPUT=OGR SUPPORTS=WFS
5+
#
6+
# In the logs, point_3_50.shp shouldn't appear
7+
# 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]
8+
9+
MAP
10+
11+
NAME WFS_TEST
12+
STATUS ON
13+
SIZE 400 300
14+
EXTENT 1 48 4 51
15+
IMAGECOLOR 255 255 255
16+
SHAPEPATH "data"
17+
18+
#
19+
# Start of web interface definition
20+
#
21+
WEB
22+
23+
IMAGEPATH "/tmp/ms_tmp/"
24+
IMAGEURL "/ms_tmp/"
25+
26+
METADATA
27+
"ows_updatesequence" "123"
28+
"wfs_title" "Test simple wfs"
29+
"wfs_onlineresource" "http://localhost/path/to/wfs_simple?"
30+
"wfs_srs" "EPSG:4326"
31+
"ows_abstract" "Test WFS Abstract"
32+
"ows_keywordlist" "ogc,wfs,gml,om"
33+
"ows_service_onlineresource" "http://localhost"
34+
"ows_fees" "none"
35+
"ows_accessconstraints" "none"
36+
"ows_addresstype" "postal"
37+
"ows_address" "123 SomeRoad Road"
38+
"ows_city" "Toronto"
39+
"ows_stateorprovince" "Ontario"
40+
"ows_postcode" "xxx-xxx"
41+
"ows_country" "Canada"
42+
"ows_contactelectronicmailaddress" "tomkralidis@xxxxxxx.xxx"
43+
"ows_contactvoicetelephone" "+xx-xxx-xxx-xxxx"
44+
"ows_contactfacsimiletelephone" "+xx-xxx-xxx-xxxx"
45+
"ows_contactperson" "Tom Kralidis"
46+
"ows_contactorganization" "MapServer"
47+
"ows_contactposition" "self"
48+
"ows_hoursofservice" "0800h - 1600h EST"
49+
"ows_contactinstructions" "during hours of service"
50+
"ows_role" "staff"
51+
"ows_enable_request" "*"
52+
END
53+
END
54+
55+
PROJECTION
56+
"init=epsg:4326"
57+
END
58+
59+
60+
#
61+
# Start of layer definitions
62+
#
63+
64+
65+
LAYER
66+
NAME test
67+
TILEINDEX "shp_tileindex_of_shp.shp"
68+
TILEITEM "LOCATION"
69+
METADATA
70+
"wfs_title" "test"
71+
"wfs_description" "test"
72+
"wfs_featureid" "id"
73+
END
74+
TYPE POINT
75+
STATUS ON
76+
EXTENT 1 48 4 51
77+
PROJECTION
78+
"init=epsg:4326"
79+
END
80+
81+
DUMP TRUE
82+
END # Layer
83+
84+
85+
END # Map File

0 commit comments

Comments
 (0)