Tuesday 23 February 2010

Coastlines again

I really am an untidy person. Without the pressure from my better half I would live under a huge pile of stuff that should be in drawers or boxes or whatever. Code is, however, a different world and it has to be tidy.

I've just finished tidying up the coastline routines on my renderer. It is much better now, distilled into sensible classes and built around a simple state engine. There are a few tasks still to do but they are documented and have slots to put them in.  There is a lot of testing to do yet too.  I have been creating test .osm files that cover as many eventualities as needed, which for coastlines is more than I expected.

Now the tidy itch has been scratched I really can move on.

Crick in the neck

A cold gray day didn't tempt me out, except in the car.  We went to take a look at the villages to the east of Hull, and check a few bus stops against the NaPTAN import at the same time.

The quality of signing was very poor, only one stop had the NaPTAN code on it and a few stops with shelters had no signs at all - I guess these are working stops.  One of the stops had a sign we nearly missed, perched on top of a pole, level with the first floor windows, probably about five metres up. 

We have checked nearly 50% of the bus stops in East Yorkshire, but those that remain are getting further from home.

Sunday 21 February 2010


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.

Sunday 14 February 2010

Driffield and renders

Today we went out to look at the town of Driffield. It's a market town which is advertised as the Capital to the Wolds, though I'd expect it to be in the Wolds to be the capital, not perched outside the edge. It went well enough, almost all of what we mapped was new.  There is a substantial chunk of the town which looks mapped at first sight, but I suspect will need going over again.  The roads look traced from NPE, they have tags like highway=unclassified when I think they are residential and they have no names. So, we'll check them out on the ground and get the real picture.

I have also added some streams from NPE.  I saw the stream flowing under the road bridge and the only real way to add it was from the old maps. Yahoo is very low-res and there's a cloud in the way.

Driffield will take many visits to complete, but it should be a pleasant place to wander around.

I have been experimenting with rendering my own maps lately.  I started to look at Java 6 (1.6?) over the winter and now it's turned into a project to render maps.  I have started with a tile-based drawing because it is easy to compare it with a Mapnik-rendered tile.  In due course I do want to render a map that is a single png file of a chosen resolution and of a chosen area. It's mainly an exercise to force me to get results from writing Java and, as yet, it is a command-line program.  I've looked at Swing a bit and it could form the GUI for selecting the area to map.

The latest, almost solved, problem is how to draw the coastline.  They are drawn as open-ended ways so the sea is not a closed polygon to simply draw filled.  I have resorted to creating a flood-fill routine (based on the work of others of course) to flood-fill the sea once the coast is drawn.  It may also be useful with drawing multipolygons too.

The next issue to address is how to manage the style sheet. I've looked at MapCSS.  It's interesting, flexible and extendable. It would make a degree of compatibility with Richard's work too. Parsing MapCSS looks to be a real problem to me. I could just create an XML format for the style sheet, but who in their right mind wants to hand-edit an XML style sheet to get a map to render? So I'm still thinking.  Any ideas would be welcome.