UMN Mapserver 6.1.2 and Openlayers 2.13 are running on the same local host. At the moment, I merely try to display restaurants and cafes of a local region as points/symbols on a map. Later, I would like to display corresponding information (like address, phonenumber etc.) in a popup. That's why I'd like to use a wfs-Layer. Until now, there seems to be a valid mapserver-response, but nothing shows up on the map.
The map file looks like:
MAP
NAME "WFS_server"
STATUS ON
EXTENT 1156474.1137249 7145329.3937763 1242083.5853923 7248519.3819469 # EPSG:900913
UNITS meters
IMAGECOLOR 255 255 255
PROJECTION
"init=epsg:900913"
END
#
# Start of web interface definition
#
WEB
IMAGEPATH "/var/www/tmp/"
IMAGEURL "/tmp/"
METADATA
"wfs_title" "WFS Demo"
"wfs_onlineresource" "http://localhost/cgi-bin/mapserv?map=/var/www/kroh/map/wfs.map"
"wfs_srs" "EPSG:900913 EPSG:4326"
"wfs_abstract" "Restaurants und Cafes"
"wfs_enable_request" "*"
END # metadata
END # web
##############################
# Start of layer definitions
##############################
#-------------------------------
# Restaurants und Cafes
#-------------------------------
LAYER
NAME "restaurant"
EXTENT 1156474.1137249 7145329.3937763 1242083.5853923 7248519.3819469
STATUS ON
DUMP TRUE
METADATA
"wfs_title" "restaurant"
"wfs_srs" "EPSG:900913"
"gml_include_items" "all"
"gml_featureid" "osm_id"
"wfs_enable_request" "*"
END # metadata
TYPE POINT
CONNECTIONTYPE postgis
CONNECTION "host=127.0.0.1 port=5432 dbname=kr-oh user=xxxxx password=yyyyyy"
DATA "way from ( SELECT * FROM planet_osm_point WHERE amenity='restaurant' OR amenity='cafe') as temp using unique osm_id using srid=900913"
PROJECTION
"init=epsg:900913"
END # projection
END #layer
END #mapfile
The correspondig javascript is:
var map;
var extent = new OpenLayers.Bounds(1156474.1137249,7145329.3937763,1242083.5853923,7248519.3819469).transform(new OpenLayers.Projection("EPSG:900913"));
function init() {
var map = new OpenLayers.Map('map', {
restrictedExtent: extent,
units : 'm',
projection : new OpenLayers.Projection("EPSG:900913"),
displayProjection : new OpenLayers.Projection("EPSG:900913")
});
var tileLayer = new OpenLayers.Layer.OSM('BackgroundLayer', 'tiles/${z}/${x}/${y}.png', {
isBaseLayer : true,
displayInLayerSwitcher: false,
});
var restaurants = new OpenLayers.Layer.Vector("restaurants", {
isBaseLayer: false,
strategies : [new OpenLayers.Strategy.Fixed()],
styleMap: new OpenLayers.StyleMap({ "default": rest}),
protocol : new OpenLayers.Protocol.WFS({
url : "http://localhost/cgi-bin/mapserv?map=/var/www/kroh/map/wfs.map",
featureType : "restaurant",
featurePrefix : 'ms',
version : "1.1.0",
geometryName : "msGeometry"
})
});
console.log(extent);
map.addLayers([tileLayer, restaurants]);
map.zoomToExtent(extent);
}
I am confused about the geometryName-property: Indeed, there is a ms:msGeometry-tag in the gml-response (see below). But the name of the geometry-column of my database table (planet-osm-point) is "way". Anyway, tried both without success.
Firebug shows me a server-response that seems to be valid (it is quite long, so i will post only the important part):
<?xml version='1.0' encoding="ISO-8859-1" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:gml="http://www.opengis.net/gml"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mapserver.gis.umn.edu/mapserver http://localhost/cgi-bin/mapserv?map=/var/www/kroh/map/wfs.map&SERVICE=WFS&VERSION=1.1.0&REQUEST=DescribeFeatureType&TYPENAME=ms:restaurant&OUTPUTFORMAT=text/xml;%20subtype=gml/3.1.1 http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:900913">
<gml:lowerCorner>1160727.706951 7148532.942024</gml:lowerCorner>
<gml:upperCorner>1234406.148319 7242238.824938</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<ms:restaurant gml:id="restaurant.600511988">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:900913">
<gml:lowerCorner>1160727.706951 7190240.196885</gml:lowerCorner>
<gml:upperCorner>1160727.706951 7190240.196885</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<ms:msGeometry>
<gml:Point srsName="EPSG:900913">
<gml:pos>1160727.706951 7190240.196885</gml:pos>
</gml:Point>
</ms:msGeometry>
<ms:osm_id>600511988</ms:osm_id>
<ms:access></ms:access>
<addr:housename></addr:housename>
<addr:housenumber>16-18</addr:housenumber>
<addr:interpolation></addr:interpolation>
<ms:admin_level></ms:admin_level>
<ms:aerialway></ms:aerialway>
<ms:aeroway></ms:aeroway>
<ms:amenity>restaurant</ms:amenity>
<ms:area></ms:area>
<ms:barrier></ms:barrier>
<ms:bicycle></ms:bicycle>
<ms:brand></ms:brand>
[...]
Firebug also reports an error in the network-tab (sorry, it's in german):
XML-Verarbeitungsfehler: Präfix nicht an einen Namespace gebunden Adresse: moz-nullprincipal:{0117c44f-41e1-4ff5-af78-62777d603394} Zeile Nr. 30, Spalte 9:
<addr:housename></addr:housename>
--------^
I would translate it like: xml-processerror: prefix not bound to a namespace. May be that helps?
Any ideas where are my mistakes or how to go about fixing this? Thanks in advance.
Best Answer
Thanks to your hints I found the solution elsewere. Maybe it also helps others:
If OSM data is imported into PostGIS with osm2pgsql the resulting attribute names containing colons (addr:streetname etc.) must be renamed. Otherwise WFS server is creating invalid XML. osm2pgsql is converting some tags into attributes, and WFS server is converting attributes into XML elements. "name" in XML element is defined to be of type NCName and NCName does not allow the use of colon character. Therefore addr:housenumber will lead to invalid XML.
Short: Renaming the DB-Columns (e.g addr:housenumber to addr_housenumber) solves the problem.
Many thanks anyway!