Other things on this site...

MCLD
music
Evolutionary sound
Listen to Flat Four Internet Radio
Learn about
The Molecules of HIV
MCLD
software
Make Oddmusic!
Make oddmusic!

How I made a nice map handout from OpenStreetMap

OpenStreetMap is a nice community-edited map of everything - and you can grab their data at any time. So in theory it should be the ideal thing to choose when you want to make a little map for an open-source conference or something like that.

screenshot of map handout. click for PDF

For our event this year I made these nice map handouts. It took a while! Quite tricky for a first-timer. But they're nice pretty vector PDF maps, with my own custom fonts, colour choices etc.

For anyone who fancies having a go, here's what I did:

  1. I followed the TileMill "30 minute tutorial" to install and set up TileMill on my Ubuntu laptop. It takes longer than 30 minutes - it's still a little bit tricky and there's a bit of a wait while it downloads a lump of data too.
  2. I started a new map project based on the example. I wanted to tweak it a bit - they use a CSS-like stylesheet language ("MSS") to specify what maps are supposed to look like, and it's nice that you can edit the stylesheets and see the changes immediately. However, I found it tricky to work out what to edit to have the effect I wanted. Here's what I managed to do:

    • I changed the font choice to match the visual style of our website. That bit is easy - find where there are some fonts specified, and put your preferred font at the FRONT of all the lists.
    • I wanted to direct people to specific buildings, but the default style doesn't show building names. However, I noticed that it does show names for cemeteries... in labels.mss on line 306 there was

          #area_label[type='cemetery'][zoom>=10] {
      

      and I can add buildings to that:

          #area_label[type='building'][zoom>=10], 
          #area_label[type='cemetery'][zoom>=10] {
      
    • The underground train line was being painted on top of the buildings, which looks confusing and silly. To fix this I had to rearrange the layers listed in the Layers panel - drag the "buildings" layer higher up the list, above the "roads" ones.

  3. When I'd got the map looking pretty good, I exported it as an SVG image.
  4. Then I quit TileMill and started up Inkscape, a really nice vector graphics program. I load the SVG that I saved in the previous step.
  5. I edited the image to highlight specific items:
    • The neatest way to do this is to select all and put it all into a layer, then select the items you want to highlight and move them to a new layer above. Once they're in a separate layer, it's easier to use Inkscape's selection tools to select all these items and perform tweaks like thickening the line-style or darkening the fill colour.
    • Selecting a "word" on the map is not so easy because each letter is a separate "object", and so is the shadow underneath. If there's a single word or street-name you're working on, it's handy to select all the letters and group them into a group (Ctrl+G), so you can treat them as a single unit.
    • You can also add extra annotations of your own, of course. I had to add tube-station icons manually, cos I couldn't find any way of getting TileMill to show those "point-of-interest"-type icons. I think there's supposed to be a way to do it, but I couldn't work it out.
  6. The next job is to clip the map image - the map includes various objects trailing off to different distances, it's not a neat rectangle. In Inkscape you can do a neat clipping like this:
    • Select all the map objects. If you've been doing as I described you'll need to use "Select all in all layers" (Ctrl+Shift+A).
    • Group them together (Ctrl+G).
    • Now use the rectangle tool to draw a rectangle which matches the clipping area you want to use.
    • Select the two items - the rectangle and the map-item-group - then right-click and choose "Set clip". Inkscape unites the two objects, using the rectangle to create a clipped version of the other.
  7. Now with your neatly-cropped rectangle map, you can draw things round the outside (e.g. put a title on).
  8. If you ever need to edit inside the map, Inkscape has an option for that - right-click and choose "Enter group" and you go inside the group, where you can edit things without disturbing the neat clipping etc.
  9. Once you're finished, you can export the final image as a PDF or suchlike.
Sunday 22nd April 2012 | IT | Permalink
Comments:
Name: Harry Wood
Website: http://harrywood.co.uk
Date: Tuesday 24th April 2012 10:53
This is neat! I did some inkscape tweaking of OpenStreetMap SVG myself on a couple of occasions. Blogged about it here: http://www.harrywood.co.uk/blog/2008/05/12/mapping-the-three-mills-loop/ But that was way back in 2008 before tile mill was around. More recently I did this one: http://flic.kr/p/9sTFKe

I guess it's worth noting that folks can skip steps 1,2 and 3 if the inkscape approach to customising is sufficient. So rather than using tile mill, go straight to SVG via the 'export' tab on the OpenStreetMap.org homepage. But certain types of styling are better, or only possible, by changing the rendering. I need to play with tile mill some time.

I found working with complex SVG in inkscape is kind of painful (slows the computer right down, and managing what is selected is fiddly and frustrating) but I wonder what could be improved with OpenStreetMap software to ease that pain. Probably not much, but I did encounter the same annoying problem that the SVG from Mapnik has separate objects for every letter, and twice over because of the halo effect. Would be a useful enhancement to Mapnik if it could be do grouping on those.

The trick of rectangle clipping with inkscape is new to me. Thanks for that!
Name: Dane Springmeyer
Website: http://dbsgeo.com
Email: dane art dbsgeo dort com
Date: Friday 27th April 2012 00:23
Yes, SVG coming out of TileMill or the OSM export are both coming out of Mapnik's Cairo backend, which does not cleanly group layers nor handle fonts well. We've long planned to write our own, native, svg renderer in Mapnik to target cleaner, more easily post-processable svg for inkscape directly. On the https://github.com/mapnik/mapnik/wiki/MapnikRenderers you'll find mention of the 'svg_renderer' which is a start to this, but still needs quite a bit of work.

Add your comments:

Name:
Email:
Website:
Comment:
I am a:
Everything is optional - and email addresses will be marmalised to protect you
Creative Commons License
Dan's blog articles may be re-used under the Creative Commons Attribution-Noncommercial-Share Alike 2.5 License. Click the link to see what that means...