It’s taking me a little while to figure out Mapnik. All of these OSM related tools say that they “support” PostGIS. But what they don’t explicity say, is that there are two different schemas floating around. One is what the production OSM database is stored as, and it contains the nodes, ways, and relations. The other is what mapnik uses to render and it just has the geometry primitives required to render (point, line, polygon). It also collapses all of the tags (i.e. attributes) into a seperate column in the table. So the table “planet_osm_point” (loaded from an osm file using osm2pgsql) has 56 columns, one for each tag (e.g. access, highly, leisure, etc.). I’m sure that it makes for fast rendering, but it’s not a paticularly efficient use of the database.

Not know this at first, made things painful. When I tried to use the mapnik tools to generate the xml stylesheet, it told me that the table didn’t exist:

hiebert@windy:~/code/svn/openstreetmap/applications/rendering/mapnik$ MAPNIK_PASSWORD=***** ./generate_xml.py osm.xml osm_bc.xml --dbname osm_bc --user hiebert --host localhost --port 5432
PostGIS: SRID warning, using srid=-1
Traceback (most recent call last):
  File "./generate_xml.py", line 201, in 
    serialize(template_xml,options)
  File "./generate_xml.py", line 77, in serialize
    mapnik.load_map(m,xml,True)
RuntimeError: PSQL error:
ERROR:  relation "planet_osm_polygon" does not exist
LINE 4:        from planet_osm_polygon
                    ^
Full sql was: 'select * from 
      (select way,aeroway,amenity,landuse,leisure,man_made,military,"natural",power,tourism,name,highway,
       case when religion in ('christian','jewish') then religion else 'INT-generic'::text end as religion
       from planet_osm_polygon
       where landuse is not null
          or leisure is not null
          or aeroway in ('apron','aerodrome')
          or amenity in ('parking','university','college','school','hospital','kindergarten','grave_yard')
          or military in ('barracks','danger_area')
          or "natural" in ('field','beach','desert','heath','mud','wood','sand','scrub')
          or power in ('station','sub_station','generator')
          or tourism in ('attraction','camp_site','caravan_site','picnic_site','zoo')
          or highway in ('services','rest_area')
       order by z_order,way_area desc
      ) as leisure
       limit 0'
 (encountered during parsing of layer 'landcover')


But after reading for a while on a zillion different wiki's I started to put the pieces together.  So the alternative approach that I think we'll use, is to keep all of our up-to-date OSM data in PostGIS using the OSM schema, then keep a seperate database that has the mapnik schema that we use for rendering.  Here is the creation of the mapnik db and the loading of the data:

postgres=# create database osm_bc_mapnik TEMPLATE template_postgis tablespace osmspace;
CREATE DATABASE
postgres=# \q
postgres@windy:/home/hiebert/code/svn/openstreetmap/applications/rendering/mapnik$ cd /home/data/gis/osm/
postgres@windy:/home/data/gis/osm$ cd pgimport_bc/
postgres@windy:/home/data/gis/osm/pgimport_bc$ ls
bc-latest.osm  pgdump
postgres@windy:/home/data/gis/osm/pgimport_bc$ osm2pgsql -c -d osm_bc_mapnik -l -U postgres -W -v bc-latest.osm 
osm2pgsql SVN version 0.69-

Password:
Using projection SRS 4326 (Latlong)
Setting up table: planet_osm_point
NOTICE:  table "planet_osm_point" does not exist, skipping
NOTICE:  table "planet_osm_point_tmp" does not exist, skipping
Setting up table: planet_osm_line
NOTICE:  table "planet_osm_line" does not exist, skipping
NOTICE:  table "planet_osm_line_tmp" does not exist, skipping
Setting up table: planet_osm_polygon
NOTICE:  table "planet_osm_polygon" does not exist, skipping
NOTICE:  table "planet_osm_polygon_tmp" does not exist, skipping
Setting up table: planet_osm_roads
NOTICE:  table "planet_osm_roads" does not exist, skipping
NOTICE:  table "planet_osm_roads_tmp" does not exist, skipping
Mid: Ram, scale=10000000

Reading in file: bc-latest.osm
Processing: Node(23948k) Way(1198k) Relation(9k)
Node stats: total(23948980), max(1401674780)
Way stats: total(1198178), max(126447217)
Relation stats: total(9207), max(1714552)

Writing way(1198k)

Writing rel(9k)
Committing transaction for planet_osm_roads
Sorting data and creating indexes for planet_osm_roads
Committing transaction for planet_osm_point
Sorting data and creating indexes for planet_osm_point
Committing transaction for planet_osm_line
Committing transaction for planet_osm_polygon
Sorting data and creating indexes for planet_osm_line
Sorting data and creating indexes for planet_osm_polygon
Completed planet_osm_point
Completed planet_osm_roads
Completed planet_osm_polygon
Completed planet_osm_line
So, now I have source data to use for mapnik, I just have to figure out how to actually render it. -----


blog comments powered by Disqus

Published

19 September 2011

Category

work

Tags