Tuesday, 12 September 2017

javascript - Querying MapServer using WFS functionality


I'm trying to display a shapefile using OpenLayers and Mapserver. Instead of overlaying it as a png, I want to return a vector, in this case a KML file. My HTML file (located in the same folder as mapserv on my server contains the following html/javascript:




OpenLayers Example











The shapefile, MLSOA, is projected using EPSG:27700. My mapfile, is called wfs.map is as follows:


MAP # start of map file

NAME demo
STATUS ON
SIZE 420 300
EXTENT 82299.5 5002.78 655979.76 657599.55
UNITS METERS
SHAPEPATH "shapefiles"

IMAGECOLOR 255 255 255
PROJECTION
"init=epsg:27700"
END

OUTPUTFORMAT
NAME "kml"
DRIVER KML
MIMETYPE "application/vnd.google-earth.kml.xml"
IMAGEMODE RGB

EXTENSION "kml"
END

WEB
#TEMPLATE "template.html"
IMAGEPATH "/home/webapps/htdocs/output/"
IMAGEURL "/output/"
METADATA
"wfs_title" "MLSOA"
"wfs_version" "1.0.0"

"wfs_connectiontimeout" "60"
"wfs_maxfeatures" "10"
"wfs_enable_request" "*"
END
END

LAYER
NAME "MLSOA"
TYPE POLYGON
STATUS DEFAULT

CONNECTION "http://mysite.com/mapserv.cgi/wfs?&map=wfs.map&"
CONNECTIONTYPE WFS
CLASS
STYLE
COLOR 255 128 128
OUTLINECOLOR 96 96 96
END
END
END
END


To check that this works, when I run:


http://mysite.com/mapserv.cgi/wfs?map=/home/urbmet/webapps/htdocs/wfs.map&SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.0.0

I get the following output.




so I assume that it is working ok. However when I open my HTML file, the post query appears to run ok (as far as I understand):







the_geom

-55.50109375,43.134977942511 55.24109375,59.593781185019







but the response from the server is as follows:





msWFSGetFeature(): WFS server error. FLTApplyFilterToLayer() failed
msWFSLayerWhichShapes(): WFS connection error. WFS request produced unexpected output (junk?) for layer MLSOA.
msBuildWFSLayerPostRequest(): WFS connection error. MapServer supports only WFS 1.0.0 or 0.0.14 (please verify the version metadata wfs_version).
msWFSLayerWhichShapes(): WFS connection error. WFS request produced unexpected output (junk?) for layer MLSOA.
msWFSLayerWhichShapes(): WFS connection error. WFS request produced unexpected output (junk?) for layer MLSOA.

msBuildWFSLayerPostRequest(): WFS connection error. MapServer supports only WFS 1.0.0 or 0.0.14 (please verify the version metadata wfs_version).



I'm not sure what to do to fix this error message. I've checked that Openlayers is sending a query with version: "1.0.0" encoded, but the other errors are not as clear. What can I do to fix this?



Answer



Your MAP file seems to indicate that your LAYER is coming from another WFS server using CONNECTIONTYPE WFS - are you sure you mean to do this?


If you just want to enable WFS for a layer using data on your server then just define a standard LAYER.


 LAYER
NAME 'MLSOA'

TYPE POLYGON
DATA "C:/path/shapefile.shp"
CLASS
STYLE
COLOR 255 128 128
OUTLINECOLOR 96 96 96
END
END
END


You'll need to request your WFS using the srsName of the OpenLayers map (EPSG:900913 by default - plus you will have to add this projection definition to your MAP file). Also use version 1.1.0 and add an srsName to your query string. Details and notes (of a not particularly pleasant process!) at:


http://geographika.co.uk/mapserver-openlayers-and-the-wfs-maze


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...