[OpenStreetMap talk-lu] OSM database interface
Frank Broniewski
brfr at metrico.lu
Tue Dec 4 07:55:32 GMT 2012
Hi all,
I've developed an read-only interface to our OSM world database and I
want to contribute this to the community in order to give something back.
It's a simple interface, as you can query features by key=value or by
OSM id. There're plans for a query language which allows broader queries
but I haven't started yet. Where're using the interface in our
OpenLayers Webapps and it's easy to integrate the URL as a Layer in
OpenLayers. Several outputformats are supported, namely GeoJSON, GML,
KML and GPX.
Things are best explained by example:
Query for restaurants:
http://www.gis-hosting.lu/osm2web/export/points/amenity/restaurant.geojson
Query for motorways:
http://www.gis-hosting.lu/osm2web/export/lines/highway/motorway.geojson
Query for restaurants:
http://www.gis-hosting.lu/osm2web/export/polygons/landuse/forest.geojson
... you get the idea: http://www.gis-hosting.lu/osm2web/export is a
fixed part of the URL, the next part tells about the geometry type you
want to retrieve, and the next two parts are the well known key=value
combinations from the map features page in the OSM wiki. The file
extension after the value part tells what kind of format you want to
retrieve. Simply add any of the above mentioned output formats in lower
case as file extension.
A mandatory parameter is a bounding box (bbox=minx,miny,maxx,maxy) in
order to limit the region of the query. At the moment I only check if
the parameter is set, but I don't check the size. So you could go ahead
and download all restaurants in the world - but I *strongly* discourage
that. So please keep your bounding box small. Downloading all
restaurants in Luxembourg isn't a deal though ...
There's one more thing I'd like to mention. We support all coordinate
systems in the well known Proj4 database. So if you want LUREF
coordinates, pass srid=2169 as an additional parameter. As a convenience
feature, the bounding box needs to have the same CRS as the srid. The
default srid is 3857, which is also the srid for the databases native
CRS. So you can pass in the the srid as an additional query param to
OpenLayers, add the BBOX Strategy and you're ready to go:
var layer = new OpenLayers.Layer.Vector(
'Restaurants in LUREF',
{
'strategies': [
new OpenLayers.Strategy.BBOX()
],
'protocol': new OpenLayers.Protocol.HTTP({
'url':
'http://www.gis-hosting.lu/osm2web/export/points/amenity/restaurant.geojson',
'format': new OpenLayers.Format.GeoJSON(),
'params': { 'srid': 2169 }
})
}
);
You probably need to set OpenLayers.ProxyHost [2] in order to use the
layer like this
The other URL I implemented takes a geometry type - any of points,
lines, polygons - and an OSM id as parameter and returns exactly one
feature.
http://www.gis-hosting.lu/osm2web/export/points/id/1887429277.gpx for
example is a hotel in Cape Verde. This URL doesn't take any additional
parameters and returns the data always in WGS84 coordinate reference system.
You'll get the full osm2pgsql schema, that means probably a lot of empty
values in your attributes. But that's difficult to change right now. In
the future I want to enhance the application further. The most important
thing for me right now is a enhanced query language and SRID/EPSG
support for the export by OSM id, but I don't have a timeline set up. I
also plan on caching features retrieved from the database in order to
speed up the deliverance through the web.
There's a bitbucket repo at [1] where any changes should show up.
I hope you'll find this project useful. Any feedback, positive or
negative, or any questions are welcome.
Thanks for reading the email up to the end :-),
Frank
[1] https://bitbucket.org/metrico/osm2web
[2] http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost
--
Frank BRONIEWSKI
METRICO s.à r.l.
géomètres
technologies d'information géographique
rue des Romains 36
L-5433 NIEDERDONVEN
tél.: +352 26 74 94 - 28
fax.: +352 26 74 94 99
http://www.metrico.lu
More information about the talk-lu
mailing list