possible to query openstreetmap (e.g: given lat/long distance to beach


I’m interested in knowing if openstreetmap has an API which makes it possible to ask queries as:
given lat/long, give the distance to the closest beach or given lat/long what are the closest beaches.

If not, is is possible to extract such information from a dump or similar? for instance beaches might be encoded as polygons (I’m just guessing here) made up of lat/long points which I could use as the basis for matching.
Is this data available, thanks in advance,


I can’t say anything about OpenStreetMap API, but if the data is imported into PostGIS then this mail and following ones in the thread may give one solution for finding the closest beaches:

Oracle Spatial has a special function for this task, this is worth reading even if you do not have plans to acquire Oracle Spatial licence:

And one standardised, but only partly working alternative is to set up a WFS service delivering OpenStreetMap data (very simple task to do by importing osm data into PostGIS with osm2pgsql and then publishing the point, line and polygon layers with Geoserver). It works only partly for you because WFS does not have “find the closest feature” function. It does, however, have “find within distance of” filter that is searching all the beaches which are closer than a given distance to a reference geometry. WFS standard is also worth reading even if the final aim is to build something that is tailored for OSM, and it is here:

Definitely possible. OSM data is made up of various data primitives, primarily nodes representing a point in space. Ways, which are the format of both line and polygon data in OSM, are made up of nodes. The other data primitive are relations which have ways and nodes as members. The juicy data is stored in “tags” which in the native XML format are stored in the k and v attributes of the XML data. An overview of the popular tags is available.

There are some things to watch out for. OSM is an open project and so there are lots of ways that beaches have been recorded into the database, not necessarily that consistently. Also you’ll need to parse all these data primitives to grab all the possible beaches that have been added - some may have been added as a POI, some as a way and some as a relation with various ways representing the actual geometry of the beach but with the beach tags on the relation.

To make a service like you are suggesting you could use a spatial RDBMS, like PostgreSQL with PostGIS, and store the OSM data you are interested in along with the lat/lon. Have a look at the information that JRA linked to and it will show you how to do this once you have your data in a PostgreSQL with PostGIS database.

There’s a good tutorial to get to OSM data into PostGIS. (http://richard.dev.openstreetmap.org/osm05.sql.gz) If you’re just interested in testing stuff first, you may want to try this link (http://richard.dev.openstreetmap.org/osm05.sql.gz) which is a 75mb dump of the SQL info, and should get you started. As far as querying the OSM data itself, I don’t think there’s a good way to do, but I could be wrong.