Creating thematic maps with openstreetmap data

A while ago I was asked to help in getting data from the OpenStreetMap database to create special maps for parcs/greens in the four major dutch cities.

Required:

Access to a postgresql database with the postgis extension, often the result of an osm2pgsql import.

All parcs in then Benelux to shape:

pgsql2shp -f parken -h <host> -u <username> <database> “select osm_id, leisure, “name”, transform(way,28992) as way from planet_osm_polygon where leisure=’park’”

A couple of important notes:

  • Because I need my data to be in the Dutch National Coordinate system, I will translate the data when exporting. Of course you can use any postgis supported coordinate system here.
  • Not all attributes for the objects are required. With the subset osm_id, leisure en “name” I limit the result.
  • -f parcs will create parcs.shp, parcs.shx, parcs.dbf and parcs.prj.

Al the waterbodies and waterways in the Benelux to shape:

(Because only parcs won’t create a readable map, I also extract some enhancing data)

pgsql2shp -f water -h -u   “select name, transform(way,28992) as way_rd from planet_osm_polygon where “natural”=’water’”

pgsql2shp -f waterwegen -h  -u   “select name, transform(way,28992) as way_rd from planet_osm_polygon where not waterway is null”

As with the previous statements, I again limit the returned attributes. The column natural is a reserved word in postgresql SQL syntax, that is why it needs to be quoted.

Getting the contours of our four major cities:

pgsql2shp -f amsterdam -h  -u   “select name, transform(way,28992) as way_rd from planet_osm_polygon where name=’Amsterdam’”
 
pgsql2shp -f rotterdam -h  -u   “select name, transform(way,28992) as way_rd from planet_osm_polygon where name=’Rotterdam’”
 
pgsql2shp -f denhaag -h  -u   “select name, transform(way,28992) as way_rd from planet_osm_polygon where name=’Den Haag’”
 
pgsql2shp -f utrecht -h  -u   “select name, transform(way,28992) as way_rd from planet_osm_polygon where name=’Amsterdam’”

Now let’s do Magic!

After creating all these shapefiles, I start qGIS, in my case qGIS 1.1.0. First I load all the shapes, giving me a layer per shapefile. This results in a random color scheme and layers in a random sequence [1]. I shift the layers and change the color schemes to my wishes [2]

Clip

The next thing that needs to be done is clip all the parcs and water based upon the boundaries of the cities. For this I use a qGIS toolset -> Geoprocessing tools -> clip. It is also possible to clip with the extract statement, but doing this visually enabled with qGIS gives me more control and is faster too. The result is [3]

Export as SVG

Finally I use an important feature of qGIS that prepares my map-image for post-processing; export as svg. For this you open the print composer (CTRL+P), add my mapview to the composition with “Add New Map”, position it and press the fourth button in the print composer: Export as SVG.

I have put the result online [4] for download so you can edit it in your favorite vector-graphic program, in my case this will be inkscape.


openstreetmap, gis