Hunting for Postboxes (part 1)

London, UK

Tuesday, January 28th 2014, 09:11 GMT

The new year brings new hobby projects! In this year, I am going to try to photograph as many UK postboxes as I can. For this I am going to build some apps and overview maps, but I will write more about those later. A teaser for a future post is here to the left ;-).

The first thing that I want my application(s) to do is to give a description of where a postbox is located and this post is the tale of how I went about just doing that.

My goal is to get from a longitude/latitude pair to the closest postbox's reference number (EC2 201), a description like (On Paul Street, on the
corner with Epworth Street), and a direction and distance (East, 86m).

The first thing I do is to look-up the closest postbox. I can very easily do that with the following aggrgation query in MongoDB:

I am using the aggregation framework instead of a normal query because the aggregation framework also can return the distance to the found object. The above returns $res, and our first result is located in $res['result'][0], which looks like:

highway is an OpenStreetMap tag that is also used for footpaths, service roads and alleys. These generally don't have names, so with the regular expression we restrict the query to only return "normal" roads. After executing this query, $road now contains:

We are interested only in the name (name=Brondesbury Road) and the geometry (l). Right now, we can already assemble the description NW6
14, on Brondesbury Road. But we also want to know the closest cross road, which we can find by finding all roads that intersect with our geometry (in l) by running the following query:

We are only interested in the roads that have a name and have a different name than the road we have run the intersection query for. In some cases, OpenStreetMap splits up a road in more than one segment carrying the same name. We discard both those in a loop and are then left with an array of intersecting road IDs in the $intersectingWays variable:

Again, the result in $res is in a similar format as before, so I won't repeat that. We use the aggrgation framework again so that we also get the distance of this intersecting road to the originally found postbox location. Depending on the distance to the intersecting road, we either use on the
corner of <roadname> (less thatn 25m) or near <roadname> if it's further away than 25m. For our example postbox, that makes NW6 14, on Brondesbury
Road, near Algernon Road which is illustrated by this image:

Flickr has a lot of photos of UK postboxes, and I think you can extract some via the reference in machine tags.

Many people don't accept data from FOIA requests as being free enough of copyright for most uses (a FOIA response does not equal a public domain release), and the data quality is rather limiting in most cases.

Great technical write up Derick. I have an idea what your project might be so I'll keep a listen out for it's release.

Add Comment

Name:

Email:

Will not be posted. Please leave empty instead of filling in garbage though!

Comment:

Please follow the reStructured Text format. Do not use the comment form to report issues in software, use the relevant issue tracker. I will not answer them here.