[OSM-dev] Querying OSM data for a region

Paul Norman penorman at mac.com
Mon Nov 10 06:41:39 UTC 2014


The database you have created is a PostgreSQL database, and there are 
libraries in most languages for connecting to one.
>
> Sorry I wasn't clear. I understand that I can use a PostgreSQL driver 
> from any language. I was wondering if there is an OpenStreetMap 
> library/API which provides data access to the database. For instance 
> where I can run queries like "return all nodes with a tag within a 
> geometric bound". I thought there might be one since Mapnik and other 
> services might need similar data access APIs.
You do this from within the standard PostgreSQL drivers. Additionally, 
after the data has been processed by osm2pgsql, you no longer need to 
use OSM-specific software, but can use non-OSM tools like Mapnik, QGIS, 
or anything that interacts with a PostGIS database.

https://github.com/openstreetmap/osm2pgsql/blob/master/docs/analysis.md 
might help with writing some queries. It focuses more on queries for 
analysis, but should get you started.

> Ok. So all roads and streets should be available in planet_osm_lines 
> and planet_osm_polygons with "highway"/"landuse" or some similar 
> column on. Is there a document which explains these? I want to use the 
> data to 3D render roads, so probably I might need to use planet_osm_roads.

Depending on the classification of roads, you might not find the data in 
the roads table, but it will be in the line table.



More information about the dev mailing list