[OSM-dev] Writing an OSM map application
jburgess777 at googlemail.com
Thu Mar 29 21:02:46 BST 2007
On Thu, 2007-03-29 at 16:58 +0200, Andreas Volz wrote:
> Am Sat, 24 Mar 2007 22:35:58 +0000 schrieb Jon Burgess:
> > > Is it possible to use only the germany.osm instead of world.osm if I
> > > need germany only?
> > Sure, you can load whatever .osm file that you feel like. The
> > resulting mapnik output will obviously just contain the data from
> > your .osm file.
> > The only restriction is the the osm file should be 'correctly' order
> > in the sequence: nodes, segments, ways. The planet.osm and josm output
> > files are fine. The planetosm-excerpt-tags.pl script writes its output
> > in the order: ways, segments, nodes and this confuses the old
> > osm2pgsql code (I think the experimental version should produce the
> > correct output in this case).
> Regarding to the last svn access you wrote in osm2pgsql. Are you the
> main developer? So here some more questions:
> Could you write your contact into the readme.txt or a authors file?
I wrote most of the C implementation, but others have contributed too.
For many things the osm-dev list is probably the better place to ask
questions since your likely to get a better response and it gets
archived so that others can see the questions and answers.
The wiki and mailing list links are in the readme.txt.
> I got all working and could search in the database with psql. It's
> really eays to understand simple searches. But do you've some docs
> about the database scheme or example queries? There're three tables
> which are in some way linked. But without documentation the complex
> searches aren't so easy.
The main purpose of osm2pgsql is an intermediate processing tool for
mapnik. As such, it tends to get twisted to support the needs of mapnik
rather than the needs of the general purpose Postgres user (this is
noted in the readme.txt).
"\d" should tell you a lot about the format of the main tables:
List of relations
Schema | Name | Type | Owner
public | planet_osm_line | table | jburgess
public | planet_osm_point | table | jburgess
public | planet_osm_polygon | table | jburgess
public | planet_osm_roads | table | jburgess
gis=> \d planet_osm_line
Column | Type | Modifiers
osm_id | integer |
name | text |
place | text |
landuse | text |
... [ lots of stuff deleted ] ...
way | geometry | not null
z_order | integer | default 0
Each of the tables contains a subset of the planet.osm file representing
a particular geometry type
- Point contains nodes which have interesting tags (e.g. place=city,
- Line contains ways with interesting tags (e.g. highway=motorway,
- Polygon contains ways which form an enclosed area (e.g.
The DB columns are used as follows:
- osm_id = the planet.osm ID of the node(point) or way(line,polygon)
- name, place, landuse, ... = the value of the given key, if present on
the node/way. If the tag is not present, the value is NULL. Only a
subset of all possible tags are stored in the DB. Only ones rendered in
the osm.xml are actually interesting to mapnik.
- way = PostGIS geometry describing the physical layout of the object.
Querying specific data requires knowlege of SQL and the OSM key/value
gis=> select osm_id,astext(way),name from planet_osm_point where amenity='cinema' limit 5;
osm_id | astext | name
26236284 | POINT(-79.7160836579093 43.6802306464618) |
26206699 | POINT(51.4051989797638 35.7066045032235) | Cinema Felestin
26206700 | POINT(51.3994885141459 35.7058460359352) | Cinema Asr-e Jadid
20979630 | POINT(151.225781789807 -33.8943079539886) | Paris Cinema
20979684 | POINT(151.226855394904 -33.8946830511095) | Hoyts
Mapnik renders the data in each table by applying the rules in the
> How could I get e.g. all highways in a given bounding box?
The 'way' column contains the geo info and is the one which you need to
use in your WHERE clause. e.g.
gis=> select osm_id,highway,name from planet_osm_line where highway is not null and way && GeomFromText('POLYGON((0 52, 0.1 52, 0.1 52.1, 0 52.1, 0 52))',4326);
osm_id | highway | name
4273848 | unclassified |
3977133 | trunk | to Royston (tbc)
4004841 | trunk |
4019198 | trunk |
4019199 | trunk |
4238966 | unclassified |
See the Postgis docs for details, e.g.
Note that the 'ref' key is not included in the DB at the moment which is
a bit of a flaw for many roads.
More information about the dev