[OSM-dev] Playing with MapServer WMS and WFS

Jukka Rahkonen jukka.rahkonen at latuviitta.fi
Fri Sep 10 15:14:35 BST 2010


Hi,

I was experimenting with Mapserver WMS and WFS and even I feel ashamed to
advertise OGC services here I still put some links here below.

My source data is Finland.osm file imported into PostGIS with -k option
for getting all the tags. Sea and borders layers are from Vmap0. Images
are rendered on-demand, and data can be selected by editing the &tag= and
&value parameters.

A supermarketmap
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,borders,POI_free_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,6558020,1615375,7978444&SRS=EPSG:3067&STYLES=&tag=shop&value=supermarket

A fuelstationmap
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,borders,POI_free_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,6558020,1615375,7978444&SRS=EPSG:3067&STYLES=&tag=amenity&value=fuel

Just edit tag and value keys and you should see what ever map you like.

Same system works for lines, here is a fixed maxspeedmap where only the
maxpeed value has been made selectable.

http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,borders,maxspeed_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,6558020,1615375,7978444&SRS=EPSG:3067&STYLES=&maxspeed=100

URLs are ugly but worse is to come. The previous was showing the default
styles from the server, but user can send own styles with the requests.

Thin brown lines

http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,borders,maxspeed_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,6558020,1615375,7978444&SRS=EPSG:3067&STYLES=&maxspeed=100&SLD_BODY=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3CStyledLayerDescriptor+version%3D%221.0.0%22%3E%3CNamedLayer%3E%3CName%3Emaxspeed_query%3C%2FName%3E%3CUserStyle%3E%3CFeatureTypeStyle%3E%3CRule%3E%3CLineSymbolizer%3E%3CStroke%3E%3CCssParameter+name%3D%22stroke%22%3E%23E6550D%3C%2FCssParameter%3E%3CCssParameter+name%3D%22stroke-opacity%22%3E1.00%3C%2FCssParameter%3E%3CCssParameter+name%3D%22stroke-width%22%3E1.00%3C%2FCssParameter%3E%3C%2FStroke%3E%3C%2FLineSymbolizer%3E%3C%2FRule%3E%3C%2FFeatureTypeStyle%3E%3C%2FUserStyle%3E%3C%2FNamedLayer%3E%3C%2FStyledLayerDescriptor%3E

Wider green lines

http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,borders,maxspeed_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,6558020,1615375,7978444&SRS=EPSG:3067&STYLES=&maxspeed=100&SLD_BODY=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%3CStyledLayerDescriptor+version%3D%221.0.0%22%3E%3CNamedLayer%3E%3CName%3Emaxspeed_query%3C%2FName%3E%3CUserStyle%3E%3CFeatureTypeStyle%3E%3CRule%3E%3CLineSymbolizer%3E%3CStroke%3E%3CCssParameter+name%3D%22stroke%22%3E%2331A354%3C%2FCssParameter%3E%3CCssParameter+name%3D%22stroke-opacity%22%3E1.00%3C%2FCssParameter%3E%3CCssParameter+name%3D%22stroke-width%22%3E2.00%3C%2FCssParameter%3E%3C%2FStroke%3E%3C%2FLineSymbolizer%3E%3C%2FRule%3E%3C%2FFeatureTypeStyle%3E%3C%2FUserStyle%3E%3C%2FNamedLayer%3E%3C%2FStyledLayerDescriptor%3E

Search parameters "stroke" and "stroke-width" and play with them for
getting more styles. Or send getStyles request and look how the default
style is made

http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQUEST=GetStyles&SERVICE=WMS&VERSION=1.1.1&layers=maxspeed_query


If you are not interested in getting the data, use WFS request and server
will send vectors in gml format. It is GML3 in the following examples
using WFS version 1.1.0.  Change version to 1.0.0 and output will be GML2.

Get 10 toilets
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&service=wfs&version=1.1.0&request=getfeature&typename=POI_free_query&maxfeatures=10&tag=amenity&value=toilets

Get 100 restaurants
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&service=wfs&version=1.1.0&request=getfeature&typename=POI_free_query&maxfeatures=100&tag=amenity&value=restaurant

Again, edit tags and values and the data will change. All the combinations
that exist are supported. Increasing maxfeatures will give more results. 
WFS spatial filters are supported. Feel free to read about them and test.
One thing that I do not know yet is how to make attribute queries with the
standard WFS filters. Tags comes from the PostGIS hstore column and that
datatype is a bit odd to query.

And this is what is needed in the MapServer mapfile for publishing the
free poi query layer as WMS and WFS.

LAYER
    TYPE POINT
    STATUS ON
    PROJECTION
        "init=epsg:3067"
         #UTM because Web Mercator makes Finland ugly
    END
    NAME "POI_free_query"
    INCLUDE "/usr/map/connection.map"
    DATA "way from (select (way),osm_id,tags from osm_point where (tags
@>'%tag%=>%value%')) as foo using unique osm_id using srid=3067"
    #I feel that more recent MapServer versions demand validation
    #pattern for the variables but this one works even without
     METADATA
    "wfs_title" "free_tag_query"
    "gml_featureid" "osm_id"
    "gml_include_items" "osm_id,tags"
    END
    DUMP TRUE
    #DEBUG 5
    TEMPLATE "/usr/templates/mstemplate.html"
    CLASS
       STYLE
	  SIZE 10
	    SYMBOL "citycircle"
	    COLOR "#FF6767"
	    OUTLINECOLOR 0 0 0
	  END
       STYLE
          SIZE 2
          SYMBOL "citycircle"
          COLOR "#000000"
       END
    END
END


-Jukka Rahkonen-




More information about the dev mailing list