[mapserver-users] mapserver 5.6 CGI output GeoJSON format
Li Quansheng
quansheng.cs at gmail.com
Tue Apr 17 09:17:49 PDT 2012
hi guys,
I installed FGS 5.6.3 on my VM to do some studying, these days I want
to add WFS layer to my applyaction via openlayers, and I want to do
some WFS query to output GeoJSON, I do my best, now,there is one
problem I can't figure out.
my mapfile: (mapserver 5.6)
....
OUTPUTFORMAT
NAME "geojson"
DRIVER "TEMPLATE"
MIMETYPE "application/json; subtype=geojson"
FORMATOPTION "FILE=xj1JSON.tmpl"
END
...
METADATA
'ows_title' 'XJ-MAP' #OWS (OGC Web Services)
'ows_onlineresource'
'http://192.168.207.100/cgi-bin/mapserv?map=/opt/fgs/www/htdocs/xj1/xj1.map'
'ows_srs' 'EPSG:4326'
'wms_tile' 'xjmap'
'wms_onlineresource'
'http://192.168.207.100/cgi-bin/mapserv?map=/opt/fgs/www/htdocs/xj1/xj1.map'
'wms_srs' 'EPSG:4326 EPSG:900913'
"wfs_title" "xjmap"
"wfs_onlineresource"
"http://192.168.207.100/cgin-bin/mapserv?map=/opt/fgs/www/htdocs/xj1/xj1.map&"
"wfs_srs" "EPSG:4326 EPSG:900913" ## Recommended
"wfs_abstract" "xjmap WFS service." ## Recommended
"wfs_enable_request" "*" # necessary,“*” enables all requests
"wfs_encoding" "UTF-8"
END
....
LAYER
NAME 'tielu'
TYPE LINE
DUMP true
TEMPLATE fooOnlyForWMSGetFeatureInfo
EXTENT 70.409351 33.963843 99.420299 49.549665
CONNECTIONTYPE postgis
CONNECTION "host=localhost dbname=xj1 user=xxx password=xxx"
PROCESSING "CLOSE_CONNECTION=DEFER"
DATA "the_geom from tielu"
METADATA
'ows_title' 'tielu'
"wfs_title" "tielu" ##REQUIRED
"wfs_srs" "EPSG:4326" ## REQUIRED
"wfs_featureid" "gid"
#"wfs_getfeature_formatlist" "geojson" # mapserver 6.0 support
"gml_include_items" "all" ## Optional (serves all attributes for layer)
"gml_featureid" "gid" ## REQUIRED
"wfs_enable_request" "*"
END
STATUS OFF
TRANSPARENCY 100
PROJECTION
'proj=longlat'
'datum=WGS84'
'no_defs'
END
CLASS
NAME 'tielu'
STYLE
WIDTH 0.91
COLOR 164 229 51
END
END
END
....
the GeoJson outputformat template file xj1JSON.tmpl
// mapserver template
[resultset layer=tielu]
{
"type": "FeatureCollection",
"features": [
[feature limit=-1 feature trimlast=","]
{
"type": "Feature",
"id": "[gid]",
"geometry": {
"type": "MultiLineString",
"coordinates": [
"coordinates": [[[shpxy]]]
]
},
"properties": {
"gid": "[gid]",
"type": "[type]",
"name": "[name]"
}
},
[/feature]
]
}
[/resultset]
I want to output the "tielu" multiline layer , I can success execute
the http request,
http://192.168.207.100/cgi-bin/mapserv?map=/opt/fgs/www/htdocs/xj1/xj1.map&layer=tielu&mode=nquery&qformat=geojson
, It seemed that all the GeoJSON output is perfect except the output
coordinates of the colum the_geom.
the output is as flowings:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"id": "1",
"geometry": {
"type": "MultiLineString",
"coordinates": [
"coordinates": [[84,42 84,42 84,42 84,42 83,42 83,42 83,42 83,42
83,42 83,42]] //there is sth wrong here!
]
},
"properties": {
"gid": "1",
"type": "70",
"name": "name111"
}
},
....
]
}
I think sth wrong in my template file about "coordinates":
[[[shpxy]]], I do many google searching,try my best to correct the
file,I try
"coordinates": [[LONG], [LAT]] etc,
, but I failed, Could anyone give me some advice, thank you very much!
More information about the MapServer-users
mailing list