[OSM-dev] Free OSM tag queries, WMS and WFS

Jukka Rahkonen jukka.rahkonen at latuviitta.fi
Fri Aug 19 08:59:12 BST 2011


Hi,

Probably only Mapserver supports exactly this out-of-the-box. I mean the
combination where user can do free SQL selections from PostGIS hstore
column and WMS and WFS are working hand in hand so that the selected data
can be either visualised on a map (WMS) or downloaded as vector data
(WFS). But it is mainly hstore that is special. On the other hand, with
the OSM data model the only comprehensive way to find data in to go to the
tags. Because all that is needed is to tranfer the user input into the SQL
that is made against PostGIS it should be easy to add hstore query support
for other WMS servers as vendor option. I understand if developers do not
want to do it. It opens the system for SQL injection danger and hstore is
a specific PostgreSQL feature and same system would not work with Oracle
or other data sources.

I have used the variable subsititution/runtime substitution mechanism
http://mapserver.org/cgi/runsub.html
http://mapserver.org/mapfile/variable_sub.html

The &sql parameter in the request is used as a SQL WHERE clause which
selects the data from the PostGIS table. If &sql parameter is not given
the default values are used - amemity=toilets, highway=motorway, and
building=yes for OSM points, lines, and polygons, respectively. I have
made a simple validation rule for the &sql parameter but I am pretty sure
it is not good enough for some clever SQL injection. Sql parameter can
naturally be used for all the data that exists in the database and not
only for OSM data.

When it comes to the vector data downloads, Mapserver 6.0 gives
interesting possibilities for that. In addition to the compulsory GML that
WFS services are generating by default, Mapserver should now be able to
send the output data in any of the vector formats supported by OGR for
writing. They are marked as Creation=Yes on this list
http://gdal.org/ogr/ogr_formats.html
Moreover, one of those formats is GPSBabel
http://gdal.org/ogr/drv_gpsbabel.html
This means that Mapserver WFS can be configured to output WFS data in any
of the formats which are marked as Write=yes on this list
http://www.gpsbabel.org/capabilities.shtml can be used.

I have had no time yet to play with GPSBabel output yet but if it works as
documented it should be rather easy to make a service that lets user to
select OSM POIs with "amenity=resturant" and "cuisine=pizza" and get the
output as a Garmin POI file with coordinates, restaurant names and phone
numbers. Or all the noname streets or FIXMEs.

As I said, apart from the hstore and tags using filters with WMS map
layers is nothing special. It is also a non-mandatory feature of the
standard. Same OGC filters can be used both for WMS and WFS and the most
simple example looks like this

filter=
<Filter  xmlns:ogc="http://www.opengis.net/ogc">
<PropertyIsEqualTo>
<PropertyName>tows:amenity</PropertyName>
<Literal>waste_basket</Literal>
</PropertyIsEqualTo></Filter>

Because OGC filters are not so nice to write some WMS servers have an
alternative for those. Geoserver is using an much-easier-to-write
CQL_QUERY system, and QGis Mapserver seems to use FILTER. I know for sure
that Geoserver cannot query anything from hstore column. I do not know if
QGis Mapserver can use stuff like &sql=(tags @>'highway=>primary') AND not
(tags ? 'maxspeed') in FILTER and I have never tried Mapnik OGC server.

-Jukka Rahkonen-



BG wrote:
> hej,
> that's great and usable. does it work only with the mapserver wms or
does it too with any other wms?
>
>
> On 18.08.2011 16:37, Jukka Rahkonen wrote:
>> Hi,
>> This is not invented here and thus perhaps not so interesting, but
anyway.
>> By using copy-paste and a browser it is possible
>> 1. Select by OSM tags all the primary highways and show them on a map
188.64.1.61/cgi-bin/ms_ows?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=563&HEIGHT=437&LAYERS=sea,borders,osm_viivat&TRANSPARENT=TRUE&FORMAT=image/png&BBOX=-369151.98300283286,6597900.0,1511076.628895184,8057331.444759207&SRS=EPSG:3067&STYLES=&sql=(tags
@>  'highway=>primary')
>> 2. Select by OSM tags all the primary highways without maxspeed tag.
Hint
>> for a mappers to improve quality?
>> 188.64.1.61/cgi-bin/ms_ows?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=563&HEIGHT=437&LAYERS=sea,borders,osm_viivat&TRANSPARENT=TRUE&FORMAT=image/png&BBOX=-369151.98300283286,6597900.0,1511076.628895184,8057331.444759207&SRS=EPSG:3067&STYLES=&sql=(tags
@>  'highway=>primary') AND not (tags ? 'maxspeed')
>> 3. Download the data that was used for rendering the previous primary
way
>> without maxspeed tag map.
>> 188.64.1.61/ms_ows?service=wfs&version=1.0.0&request=getfeature&typename=osm_viivat&sql=(tags
@>  'highway=>primary') AND not (tags ? 'maxspeed')
>> No own development done, just playing with existing possibilities of
MapServer WMS and WFS and osm2pgsql with hstore. Actually data
>> interoperability without imports is demostrated as well because layers
sea
>> and borders are not OSM data. It is a live service, feel free to try
other
>> free tag queries.
>> -Jukka Rahkonen-
>> _______________________________________________
>> dev mailing list
>> dev at openstreetmap.org
>> http://lists.openstreetmap.org/listinfo/dev
>
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/listinfo/dev
>











More information about the dev mailing list