Sunday 21 February 2010

Coastlines

I've been looking at how to render my own maps. It started as an exercise in learning Java but has become a tussle with coastlines.  In OSM the coastlines are stored as a collection of ways with natural=coastline tags.  They can have other tags too of course.  These ways should join up.  The big issue is that they don't individually form a polygon which can be filled to make up the sea. 

My renderer-to-be is working on a .osm file.  Depending on where that file covers it might contain coastline ways and they might be complex.  It has proved harder than I thought create a filled-in coastline.  Drawing the ways is very straightforward. I found a flood-fill routine (Java doesn't seem to have one built in) and tried to use it to fill from the way to the edges. This is harder than I expected because the twists and turns of coastlines.

I then decided to work differently and create polygons (which Java is good at filling) that are made up from the way and the edges of the canvas to draw on.  Because the land is always on the left of a coastline way, I can work out which part to fill.  Finally this seems to work.

There is more work to do to improve the handling of multiple, unconnected sections of coastline on a map, such as drawing a section of a peninsular or a section of an estuary. There is still an issue of a closed way: is it an island or a lake (some lakes are drawn with coastline rather than natural=water). Clockwise closed ways are lakes and anti-clockwise closed ways are islands. I want to review the way I manage the classes around this too. 

I'm going to move on to other stuff for now and return to coastlines later.  Next is a style sheet.  I've looked at MapCSS and I've looked at Maperitive's style sheet. I think I prefer the latter.  It seems to use a system of identifying what an object is and then how to draw it.  This allows similar things to be treated similarly: amenity=graveyard and landuse=cemetery could both be identified as a graveyard and drawn in the same way.  This is exactly how I expected to work.  Maperitive also has built in support for zoom levels, which don't have to be integer values. So that looks the next task.

I don't know how far I'll get before the weather improves.  Then there will be more draws to be outside: walking, cycling, mapping, working the allotment etc. We have managed to work on Driffield.  There's also the town of Hornsea and about 40+ more villages to complete in East Yorkshire.  Completing all of the roads and villages in the county is high on my list for this year.

No comments: