Permalink
Browse files

OGR-output: output fid if requested (#5207)

* outputformat must contain option "USE_FEATUREID=true"
* layer must have a ows_featureid metadata set
  • Loading branch information...
tbonfort committed Feb 26, 2016
1 parent 6ae2bc6 commit 4af7028c58c23eb9ebd1a1aa4b7ee388ada4333c
Showing with 150 additions and 3 deletions.
  1. +20 −2 mapogroutput.c
  2. +36 −0 msautotest/wxs/expected/wfsogr10_geojson.json
  3. +93 −0 msautotest/wxs/wfs_ogr_geojson.map
  4. +1 −1 print-test-results.sh
View
@@ -247,7 +247,7 @@ static void msOGRSetPoints( OGRGeometryH hGeom, lineObj *line, int bWant2DOutput
static int msOGRWriteShape( layerObj *map_layer, OGRLayerH hOGRLayer,
shapeObj *shape, gmlItemListObj *item_list,
- int nFirstOGRFieldIndex )
+ int nFirstOGRFieldIndex, const char *pszFeatureid )
{
OGRGeometryH hGeom = NULL;
@@ -489,6 +489,15 @@ static int msOGRWriteShape( layerObj *map_layer, OGRLayerH hOGRLayer,
for( i = 0; i < item_list->numitems; i++ ) {
gmlItemObj *item = item_list->items + i;
+ if(pszFeatureid && !strcmp(pszFeatureid, item->name)) {
+ char *endptr;
+ long feature_id = strtol(shape->values[i],&endptr,10);
+ if(endptr && *endptr==0) {
+ /* only set the featureid if it is numeric */
+ OGR_F_SetFID(hFeat, feature_id);
+ }
+ }
+
if( !item->visible )
continue;
@@ -689,6 +698,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
char **file_list = NULL;
int iLayer, i;
int bDataSourceNameIsRequestDir = FALSE;
+ int bUseFeatureId = MS_FALSE;
/* -------------------------------------------------------------------- */
/* Fetch the output format driver. */
@@ -713,6 +723,9 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
ds_options = CSLAddString( ds_options,
format->formatoptions[i] + 5 );
}
+ if(!strcasecmp("true",msGetOutputFormatOption(format,"USE_FEATUREID","false"))) {
+ bUseFeatureId = MS_TRUE;
+ }
/* ==================================================================== */
/* Determine the output datasource name to use. */
@@ -872,6 +885,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
char *pszWKT;
int reproject = MS_FALSE;
int nFirstOGRFieldIndex = -1;
+ const char *pszFeatureid = NULL;
if( !layer->resultcache )
continue;
@@ -902,6 +916,9 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
value = "Geometry";
}
+ if(bUseFeatureId)
+ pszFeatureid = msOWSLookupMetadata(&(layer->metadata), "FOG", "featureid");
+
if( strcasecmp(value,"Point") == 0 )
eGeomType = wkbPoint;
else if( strcasecmp(value,"LineString") == 0 )
@@ -1027,6 +1044,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
OGR_DS_Destroy( hDS );
msOGRCleanupDS( datasource_name );
+ msGMLFreeItems(item_list);
return MS_FAILURE;
}
@@ -1113,7 +1131,7 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
if( status == MS_SUCCESS )
status = msOGRWriteShape( layer, hOGRLayer, &resultshape,
- item_list, nFirstOGRFieldIndex );
+ item_list, nFirstOGRFieldIndex, pszFeatureid );
if(status != MS_SUCCESS) {
OGR_DS_Destroy( hDS );
@@ -0,0 +1,36 @@
+Content-Type: application/json; subtype=geojson; charset=utf-8
+
+{
+"type": "FeatureCollection",
+"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::3978" } },
+"features": [
+{ "type": "Feature", "id": 0, "properties": { "UNIQUE_KEY": "BACMK", "NAME": "\"Tignish", "CAPITAL": 0, "POP_CLASS": 1 }, "geometry": { "type": "Point", "coordinates": [ 2281604.25, 340848.9375 ] } },
+{ "type": "Feature", "id": 1215011, "properties": { "UNIQUE_KEY": "CAGYX", "NAME": "'Cheticamp", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2503805.5, 427872.65625 ] } },
+{ "type": "Feature", "id": 1209036, "properties": { "UNIQUE_KEY": "CBIKA", "NAME": "Sheet Harbour", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2499190.0, 194088.23438 ] } },
+{ "type": "Feature", "id": 1101036, "properties": { "UNIQUE_KEY": "BACII", "NAME": "'Souris'", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2434957.0, 347013.59375 ] } },
+{ "type": "Feature", "id": 1213006, "properties": { "UNIQUE_KEY": "CAGBW", "NAME": "\"Canso\"", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2578914.25, 292073.09375 ] } },
+{ "type": "Feature", "id": 1215002, "properties": { "UNIQUE_KEY": "CBELL", "NAME": "Port Hawkesbury", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2536072.75, 311524.96875 ] } },
+{ "type": "Feature", "id": 1214002, "properties": { "UNIQUE_KEY": "CAATB", "NAME": "Antigonish", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2494520.0, 285855.40625 ] } },
+{ "type": "Feature", "id": 1211008, "properties": { "UNIQUE_KEY": "CBKDH", "NAME": "Springhill", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2348711.75, 204294.0625 ] } },
+{ "type": "Feature", "id": 1208002, "properties": { "UNIQUE_KEY": "CBPAK", "NAME": "\"Wind\"sor", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2377598.0, 135734.70312 ] } },
+{ "type": "Feature", "id": 1206006, "properties": { "UNIQUE_KEY": "CAWAZ", "NAME": "Lunenburg", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2398677.25, 70608.14062 ] } },
+{ "type": "Feature", "id": 1204006, "properties": { "UNIQUE_KEY": "CAUWZ", "NAME": "Liverpool", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2388340.0, 19784.32227 ] } },
+{ "type": "Feature", "id": 1205016, "properties": { "UNIQUE_KEY": "CAZHC", "NAME": "Middleton", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2313364.75, 98278.92188 ] } },
+{ "type": "Feature", "id": 1203006, "properties": { "UNIQUE_KEY": "CAJOA", "NAME": "Digby", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2279399.0, 39858.0 ] } },
+{ "type": "Feature", "id": 1201008, "properties": { "UNIQUE_KEY": "CBIKP", "NAME": "Shelburne", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2359906.5, -30454.43555 ] } },
+{ "type": "Feature", "id": 1103025, "properties": { "UNIQUE_KEY": "BADSZ", "NAME": "Summerside", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2325561.75, 294362.25 ] } },
+{ "type": "Feature", "id": 1217009, "properties": { "UNIQUE_KEY": "CBQFA", "NAME": "Glace Bay", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2600377.0, 419421.71875 ] } },
+{ "type": "Feature", "id": 1212014, "properties": { "UNIQUE_KEY": "CBBJR", "NAME": "New Glasgow", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2449341.5, 253906.09375 ] } },
+{ "type": "Feature", "id": 1210006, "properties": { "UNIQUE_KEY": "CBMKT", "NAME": "Tr\"uro", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2418051.5, 205002.20312 ] } },
+{ "type": "Feature", "id": 1211011, "properties": { "UNIQUE_KEY": "CAAOO", "NAME": "Amherst", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2329295.75, 218397.28125 ] } },
+{ "type": "Feature", "id": 1207012, "properties": { "UNIQUE_KEY": "CASWE", "NAME": "Kentville", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2345781.25, 130999.54688 ] } },
+{ "type": "Feature", "id": 1206004, "properties": { "UNIQUE_KEY": "CAFBR", "NAME": "Bridgewater", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2382666.75, 60910.9375 ] } },
+{ "type": "Feature", "id": 1202006, "properties": { "UNIQUE_KEY": "CBPIB", "NAME": "Yarmouth", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2294923.75, -55344.50391 ] } },
+{ "type": "Feature", "id": 1217019, "properties": { "UNIQUE_KEY": "CBLHE", "NAME": "Sydney Mines", "CAPITAL": 0, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2574240.0, 416102.34375 ] } },
+{ "type": "Feature", "id": 1217014, "properties": { "UNIQUE_KEY": "CBLGX", "NAME": "Sydney", "CAPITAL": 0, "POP_CLASS": 4 }, "geometry": { "type": "Point", "coordinates": [ 2587598.0, 404010.53125 ] } },
+{ "type": "Feature", "id": 1209022, "properties": { "UNIQUE_KEY": "CAIYJ", "NAME": "Dartmouth", "CAPITAL": 0, "POP_CLASS": 5 }, "geometry": { "type": "Point", "coordinates": [ 2437026.0, 130358.35156 ] } },
+{ "type": "Feature", "id": 2401025, "properties": { "UNIQUE_KEY": "EGIIG", "NAME": "Fatima", "CAPITAL": 0, "POP_CLASS": 2 }, "geometry": { "type": "Point", "coordinates": [ 2402416.5, 461586.8125 ] } },
+{ "type": "Feature", "id": 1102075, "properties": { "UNIQUE_KEY": "BAARG", "NAME": "Charlottetown", "CAPITAL": 2, "POP_CLASS": 3 }, "geometry": { "type": "Point", "coordinates": [ 2378567.25, 305099.78125 ] } },
+{ "type": "Feature", "id": 1209021, "properties": { "UNIQUE_KEY": "CAPHL", "NAME": "Halifax", "CAPITAL": 2, "POP_CLASS": 6 }, "geometry": { "type": "Point", "coordinates": [ 2431943.75, 118985.38281 ] } }
+]
+}
@@ -0,0 +1,93 @@
+#
+# Test WFS
+#
+# REQUIRES: SUPPORTS=WFS INPUT=OGR
+#
+# Test OGR geojson output.
+# RUN_PARMS: wfsogr10_geojson.json [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=popplace_fid&OUTPUTFORMAT=geojson" > [RESULT]
+MAP
+
+NAME WFS_OGROUT_TEST
+STATUS ON
+SIZE 400 300
+EXTENT -67.5725 42 -58.9275 48.5
+UNITS METERS
+IMAGECOLOR 255 255 255
+SHAPEPATH ./data
+
+OUTPUTFORMAT
+ NAME "geojson"
+ DRIVER "OGR/GEOJSON"
+ MIMETYPE "application/json; subtype=geojson; charset=utf-8"
+ FORMATOPTION "STORAGE=stream"
+ FORMATOPTION "FORM=SIMPLE"
+ FORMATOPTION "USE_FEATUREID=true"
+ FORMATOPTION "LCO:COORDINATE_PRECISION=5"
+END
+#
+WEB
+
+ IMAGEPATH "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 EPSG:4269 EPSG:3978 EPSG:27700"
+ "wms_title" "Test simple wms"
+ "wms_onlineresource" "http://localhost/path/to/wms_simple?"
+ "wms_srs" "EPSG:4269 EPSG:4326 EPSG:3978"
+ "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"
+ "wms_feature_info_mime_type" "text/csv"
+ "ows_enable_request" "*"
+ END
+END
+
+PROJECTION
+ "+proj=latlong +datum=WGS84"
+END
+
+
+LAYER
+ NAME popplace_fid
+ CONNECTIONTYPE OGR
+ CONNECTION "data/popplace.shp"
+ DATA "popplace"
+
+ METADATA
+ "wfs_title" "popplace"
+ "wfs_description" "populated places"
+ "wfs_featureid" "SGC_CODE"
+ "wfs_getfeature_formatlist" "geojson"
+ "gml_include_items" "NAME,UNIQUE_KEY,CAPITAL,POP_RANGE"
+ "gml_POP_RANGE_alias" "POP_CLASS"
+ "gml_types" "auto"
+ END
+ TYPE POINT
+ STATUS ON
+ PROJECTION
+ "init=epsg:3978"
+ END
+END # Layer
+
+END # Map File
View
@@ -40,7 +40,7 @@ for testcase in "${tests[@]}"; do
echo "# $testcase => $failedtest"
echo "######################################"
#for txt, gml and xml files, print a diff
- if echo "$failedtest" | egrep -q "(txt|xml|gml|html)$"; then
+ if echo "$failedtest" | egrep -q "(txt|xml|gml|html|json)$"; then
$DIFF -u "../expected/$failedtest" "$failedtest"
fi
if echo "$failedtest" | egrep -q "(png|gif|tif)$"; then

0 comments on commit 4af7028

Please sign in to comment.