I'm new to OpenLayers and MapServer and I'm trying to serve a shapefile through a WFS but can't seem to get the data to display. When I use Firebug and HttpFox in Firefox I seem to be getting some data coming back, but it just won't get rendered on my web page. It is entirely possible that I have missed something simple but I can't see what. I've got the following in terms of my setup.
MapFile:
MAP
NAME "MapServerWFS"
STATUS on
SIZE 600 600
EXTENT 0 0 700000 1300000
UNITS METERS
SHAPEPATH "shp"
IMAGECOLOR 240 240 240
PROJECTION
"init=EPSG:27700"
END
WEB
TEMPLATE "template.html"
IMAGEPATH "C:/DevProjects/fgsv2/output/"
IMAGEURL "../output/"
METADATA
"wfs_title" "WFSDemo" ## REQUIRED
"wfs_onlineresource" "http://localhost/cgi-bin/mapserv.exe?map=C:/DevProjects/fgsv2/mapfile.map&" ## Recommended
"wfs_srs" "EPSG:27700" ## Recommended
"ows_srs" "EPSG:27700" ## Recommended
"wfs_abstract" "This text describes my WFS service. This should be some counties." ## Recommended
"wfs_enable_request" "*" # necessary
"wms_enable_request" "*" # necessary
"wms_title" "WMSDemo"
END
END
#this connects to a shapefile
LAYER
NAME "County"
DATA "County"
#CONNECTIONTYPE OGR
#CONNECTION "C:/devprojects/fgsv2/shp/County.shp"
STATUS ON
PROJECTION
"init=epsg:27700"
END
METADATA
"title" "County"
"wfs_title" "County" ##REQUIRED
"wfs_srs" "EPSG:27700" ## REQUIRED
"gml_include_items" "all" ## Optional (serves all attributes for layer)
"gml_featureid" "db_id" ## REQUIRED
"wfs_enable_request" "*"
END
EXTENT 0 0 700000 1300000
TYPE POLYGON
CLASS
NAME "County"
STYLE
color 100 250 250
outlinecolor 50 50 250
END
END
PROCESSING "CLOSE_CONNECTION=DEFER"
dump true
END #end of layer
END # end of map file
The data I'm using is English and Welsh Counties, so the projection is set to EPSG:27700. The OpenLayers map and layers bit is as follows:
var farm_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
farm_style.strokeWidth = 3;
farm_style.strokeColor = "#ff0000";
farm_style.fillOpacity = 0.5;
var mymap = new OpenLayers.Map({ div: "map",
layers: [
new OpenLayers.Layer.Vector("County", {
isBaseLayer: true,
strategies: [new OpenLayers.Strategy.BBOX()],
styleMap: new OpenLayers.StyleMap({ "default": farm_style}),
protocol: new OpenLayers.Protocol.WFS({
url: "http://localhost/cgi-bin/mapserv.exe?map=C:/DevProjects/fgsv2/mapfile.map",
version: "1.0.0",
featureType: "County",
featurePrefix:"ms",
featureNS: "http://mapserver.gis.umn.edu/mapserver"
})
})
,
],
center: [-1, 53],
zoom: 8
});
When I view the POST and Content through my Firefox addIns I can see
POST:
<wfs:GetFeature service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">
<wfs:Query typeName="ms:County">
<ogc:Filter>
<ogc:BBOX>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<gml:Box srsName="EPSG:4326">
<gml:coordinates decimal="." cs="," ts=" ">
-2.64794921875,51.35205078125 0.64794921875,54.64794921875
</gml:coordinates>
</gml:Box>
</ogc:BBOX>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
The reference to EPSG:4326 is abit confusing as I've made no mention of it elsewhere. Is it a default setting somewhere? The Content tab contains the following:
<wfs:FeatureCollection xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd http://mapserver.gis.umn.edu/mapserver http://localhost/cgi-bin/mapserv.exe?map=C:/DevProjects/fgsv2/mapfile.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=ms:County&OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG:27700">
<gml:coordinates>
294170.798523,90299.411200 655604.702242,588517.298279
</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:County fid="County.1">
<gml:boundedBy>
<gml:Box srsName="EPSG:27700">
<gml:coordinates>
320262.500400,378383.398000 361791.001700,422761.904601
</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:MultiPolygon srsName="EPSG:27700">
<gml:polygonMember>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>
330996.596900,394516.299901 338224.102200,379434.497000 328536.798900,380475.199200 326182.199000,378383.398000 320262.500400,388522.196000 330996.596900,394516.299901
</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</gml:polygonMember>
<gml:polygonMember>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>
330871.099200,405417.000200 335362.999800,402517.699900 337285.798200,405717.803700 344062.801400,398931.696000 348231.000800,404146.903200 351662.604000,402905.498700 361791.001700,394518.799500 355128.200600,395322.399401 354161.500000,387836.602400 350551.103500,389713.904500 344678.600001,382585.295100 334583.800700,388194.599500 326895.800900,406184.799700 336963.201600,422761.904601 330871.099200,405417.000200
</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
</gml:polygonMember>
</gml:MultiPolygon>
</ms:msGeometry>
<ms:OBJECTID>1 </ms:OBJECTID>
<ms:COUNTY_STR>Merseyside </ms:COUNTY_STR>
<ms:PMS_REGION>7 </ms:PMS_REGION>
<ms:COUNTRY>ENGLAND </ms:COUNTRY>
<ms:SNAC_GOR>North West </ms:SNAC_GOR>
<ms:SHAPE_LEN>2.19563981295e+005 </ms:SHAPE_LEN>
<ms:EARegion>3 </ms:EARegion>
<ms:db_id>1 </ms:db_id>
<ms:updateID>0 </ms:updateID>
<ms:ET_ID>0 </ms:ET_ID>
<ms:ET_X>344814.69641 </ms:ET_X>
<ms:ET_Y>389730.08240 </ms:ET_Y>
<ms:Distance>0.00000000 </ms:Distance>
</ms:County>
</gml:featureMember>
<gml:featureMember>
<ms:County fid="County.2">
<gml:boundedBy>
<gml:Box srsName="EPSG:27700">
<gml:coordinates>
411883.903568,379684.895552 475119.498243,418312.098600
</gml:coordinates>
</gml:Box>
</gml:boundedBy>
These co-ordinates are correct for the data I'm trying to serve so I'm happy that things are appearing to be read ok. Panning and zooming in the map div on my test page will result in the content being altered based on a different bounding box, I just can't see anything. Am I missing some styling information somewhere? I've searched for solutions to this but nothing has worked. There's no proxy set up but my understanding is that for a completely local setup, a proxy is not required.
Please can someone take a look at the setup I have and let me know if I've missed something obvious.
Best Answer
Thanks to @iant for his comments with regards to proj4js, I've now got the mapping sorted. My mapfile uses a "EPSG:27700" for the map and layer projections (as posted originally). Within the calls to OpenLayers I now explicitly set the projection and displayProjection as below:
The XML Post now references "EPSG:900913" as the SRSName for the box used to query the data. The XML now references "EPSG:27700" when returning the coordinates of the features.