[mapserver-users] How to apply WFS filters for PostGIS hstore data?

Rahkonen Jukka Jukka.Rahkonen at mmmtike.fi
Fri Sep 10 05:30:09 EDT 2010


Hi,
 
Got INSPIREd at FOSS4G and desided to have a try with paleogissic
MapServer
WMS and WFS services with OpenStreetMess (OSM) data.
 
I imported an OSM excerpt of Finland with osm2pgsql utility by using the
-k switch
for storing all the OSM tags and values into PostGIS.  They got all
dumped into  
one singe column "tags" which is of datatype "hstore"
http://www.postgresql.org/docs/8.4/static/hstore.html
<http://www.postgresql.org/docs/8.4/static/hstore.html> 
Then I created a few simple layers by querying tags and values from the
hstore.
See an example of layer definitions from the bottom of this message
 
Now it is possible to try how WMS behaves with hstore. By editing the
"tag" and "value" keys
it is possible to get what ever map you like.  I will try to keep my
demo service online 
at least for a week for testing.
 
A supermarketmap
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQU
EST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,bo
rders,POI_free_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,65
58020,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&REQU
EST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,bo
rders,POI_free_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,65
58020,1615375,7978444&SRS=EPSG:3067&STYLES=&tag=amenity&value=fuel
 
Hstore query works also with lines and polygons:
A maxspeedmap (fixed, only maxspeed value is selectable)
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQU
EST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,bo
rders,maxspeed_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,65
58020,1615375,7978444&SRS=EPSG:3067&STYLES=&maxspeed=100
<http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&REQ
UEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=1059&HEIGHT=687&LAYERS=sea,b
orders,maxspeed_query&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=-574187,6
558020,1615375,7978444&SRS=EPSG:3067&STYLES=&maxspeed=100> 
 
Then gml output from WFS, "Get 10 toilets"
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&serv
ice=wfs&version=1.1.0&request=getfeature&typename=POI_free_query&maxfeat
ures=10&tag=amenity&value=toilets
<http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&ser
vice=wfs&version=1.1.0&request=getfeature&typename=POI_free_query&maxfea
tures=10&tag=amenity&value=toilets> 
 
or "Get 100 restaurants"
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&serv
ice=wfs&version=1.1.0&request=getfeature&typename=POI_free_query&maxfeat
ures=100&tag=amenity&value=restaurant
 
If the service is up you will see that WFS is sending all the tags as a
one string, like this:
<ms:tags>
"name"=>"Fantasia", "amenity"=>"restaurant", "cuisine"=>"pizza",
"wheelchair"=>"yes", "opening_hours"=>"Mo-Fr 10:30-19:30; Sa
12:00-19:30; Su 13:00-19:30"
</ms:tags>
 
So both the WMS (including getFeatureInfo) and WFS are working very nice
if the query is done by sending  
extra parameters with the getMap or getFeature requests.  However, that
is not especially standard way 
to do queries. Thus this is my question:
Is is somehow possible to do selections from the hstore backend by using
WFS attribute filters?
 
There is an unfiltered feature type "tagsoup" available in my WFS
service
http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&serv
ice=wfs&version=1.1.0&request=getfeature&typename=tagsoup&maxfeatures=10
<http://188.64.1.61/cgi-bin/mapserv?map=/usr/map/osm-mapserver_i.map&ser
vice=wfs&version=1.1.0&request=getfeature&typename=tagsoup&maxfeatures=1
0> 
 
If someone gets interested in trying to apply WFS filters for this
feature type, just go ahead and tell if they work.

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 demands validation
     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-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20100910/34789621/attachment.html


More information about the mapserver-users mailing list