[OSM-dev] Getting information from relations.

Jukka Rahkonen jukka.rahkonen at latuviitta.fi
Tue Jan 24 12:30:37 GMT 2012

Frederik Ramm wrote:

>> * Some sort of application that answers to wfsGetFeatureInfo requests
and returns all the tags and relations tags about objects.
>> This last point is the missing bit, how can I achieve this? Do I have
>> code something from scratch or has anything like this been done before.
> The simplest way would probably be tweaking osm2pgsql/imposm so that the
>information that you care about is copied into the geometry tables,
most >likely making a separate geometry for each relation (e.g. this is
how >route relations are turned into geometries for things like
OpenCycleMap) >but possibly also merging the information from several
relations into one >resulting geometry object. That way, you can then
run a simple Mapserver >or Geoserver installation and GetFeatureInfo
will magically work.

You would probably want to use WFS GetFeature. GetFeatureInfo belongs to
Web Map Service (WMS) and it can be tweaked to return data as GML/XML,
KML, html or what ever but the main use is to let users click on a map and
ask server to send information about the feature that is closest to the
clicked point. Standard though optional feature of WMS and mostly missing
in OSM web maps.

Setting up WFS on top of tables imported with osm2pgsql is pretty easy
with Mapserver and Geoserver. However, Geoserver does not support
PostgreSQL hstore column at all so you'd be able to send just a fixed set
of tags. Mapserver can send also all the tags, even they are not queryable
with standard WFS calls. With vendor specific parameters and runtime
substitution you can query whatever you want with Mapserver. I will show
an example a bit later.

Third alternative is TinyOWS WFS. Configuring it to deliver osm_point,
osm_line and osm_polygon tables through WFS is extremely easy. TinyOWS can
also send all the tags from hstore column.

It looks like osm2pgsql does not merge route members into selfstanding
geometry objects. Therefore the following sample queries will send routes
as a short segments.

I pologise that the URLs are so ugly but it is how OGC has defined them.
It will be easier to read the filters by url-decoding them. Filters are
just XML and therefore computer friendly.

This request will send one hunder route features (route is not null in
osm_line) with geometry and ref and route attributes and also all the
tags. Geometry is not compulsory, just take is out from propertyname list
and you'll get just attributes. Plain attribute query may make sense
sometimes especially with spatial filters.,ref,tags,way

My server is using EPSG:3067 by default, if EPSG:4326 feels better then
ask for it,ref,tags,way&srsname=EPSG:4326

And if the Google projection and geojson feels even more good then do as
follows. You will see that TinyOWS does not respect selecting a list of
attributes with geojson output but it is just a bug.,ref,tags,way&srsname=EPSG:900913&outputformat=application/json

Increase the maxFeatures parameter and you will get more data. I do not
have any limit on server side.

Filters in WFS suit better for sending through http POST and the following
posted to will send data about route
number 503.

<wfs:GetFeature xmlns:ogc="http://www.opengis.net/ogc"
xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"
maxFeatures="1000" outputFormat="GML2"><wfs:Query
wildCard="*" singleChar="?"

Mapserver allows to use variables with runtime substitution which can make
http queries more understandable. The following is doing selection
directly from the osm_line hstore columns and every tag that exists can be
used for queries. Actuallu, even tags which do not exist. (tags @>
'highway=>primary') AND not (tags ? 'maxspeed') is selectign primary
highways which do not have maxspeed tag. Very flexible.
? 'route') AND (tags @> 'ref=>503')

-Jukka Rahkonen-

> Bye
> Frederik
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/listinfo/dev

More information about the dev mailing list