Categories
OpenLayers

OpenLayers 101

[Updated] Here’s a simple one-file way to get an OpenLayers map on a website. This is all the code you need, including the HTML, Javascript and CSS.

This particular example simply shows an OpenStreetMap map. It is up to you to add additional layers, be them from raster sources, or vector data. It’s been updated for the simpler syntax used for OpenLayers 2.13.1, and also HTML 5.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My OpenStreetMap Map</title>
<script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js">
</script>
<script type="text/javascript">
var map;

function init() 
{
    map = new OpenLayers.Map ("map", 
    {
        controls:[
            new OpenLayers.Control.Navigation(),
            new OpenLayers.Control.PanZoomBar(),
            new OpenLayers.Control.Attribution(),
        new OpenLayers.Control.LayerSwitcher()],
        projection: "EPSG:900913",
        displayProjection: "EPSG:4326"
    });
    
    layerMapnik = new OpenLayers.Layer.OSM(
    	null, null, { numZoomLevels: 15 });
    map.addLayer(layerMapnik);
    var start = new OpenLayers.LonLat(-3.5, 56.5);
    map.setCenter(start.transform("EPSG:4326", "EPSG:900913"), 7);
}
</script>
</head>
<body onload="init();" style="margin: 0;">
<div id="map" 
    style="position: absolute; width: 100%; height: 100%;">
</div>
</body>
</html>
 

Here’s what it looks like:
ol101v2

Categories
OpenStreetMap Technical

Converting OS Eastings/Northings to Grid References in Python

[Updated] I needed to programatically convert a series of Ordnance Survey easting and northings (e.g. 325940, 673060) to “six-figure” grid references (e.g. NT259731) for a project I’m currently working on. It’s a pretty straightforward conversion – no reprojection, just a different way of expressing the same position on the British National Grid.

The specific use is that the 1km x 1km tiles from NPEMap are coding according to eastings & northings, but the calibration files required by TimSC‘s warp-gbos require grid references for the corners and calibration points.

Such a procedure is already well catered for in Perl, PHP and Javascript. Here is a straightforward conversion of some Javascript I found here into Python:

# Derived from # http://www.movable-type.co.uk/scripts/latlong-gridref.html def getOSGridReference(e, n): import math # Note no I gridChars = "ABCDEFGHJKLMNOPQRSTUVWXYZ" # get the 100km-grid indices e100k = math.floor(e/100000) n100k = math.floor(n/100000) if e100k6 or n100k12: return '' # translate those into numeric equivalents # of the grid letters l1 = (19-n100k)-(19-n100k)%5+math.floor((e100k+10)/5) l2 = (19-n100k)*5%25 + e100k%5 letPair = gridChars[int(l1)] + gridChars[int(l2)] # strip 100km-grid indices from easting & northing, # round to 100m e100m = math.trunc(round(float(e)/100)) egr = str(e100m).rjust(4, "0")[1:] if n >= 1000000: n = n - 1000000 # Fix Shetland northings n100m = math.trunc(round(float(n)/100)) ngr = str(n100m).rjust(4, "0")[1:] return letPair + egr + ngr # test print getOSGridReference(96000,906000) # NA960060 print getOSGridReference(465149, 1214051) # HP651141  

[Update – fixed a bug that gave the wrong grid references for the Shetland Islands – their northings have seven figures, and similarly places in the far west or south that only have five figure easting or northings respectively :oops:]

Categories
Orienteering

Orienteering 101

Velika Planina Village (1628)


Making lists of orienteering maps seem to be popular at the moment. Following the CompassSport 99 which featured a map in each of the UK’s ceremonial counties, and the Attackpoint 51 which does the same for US states, a project has launched to build a list of the top 101 unmissable orienteering maps around the world. It’s a collaboration between Jan Kocbach of WorldOfO and Ivan Nagy of OO.Cup. They are planning on making it into a book – If this comes to fruition as a coffee-table book of amazing photographs and maps (and I know Ivan takes good photos, the OO.Cup pages always look great!) then it looks like I already know what I’ll be getting people for Christmas.

I’m not sure if the emphasis will be on the best areas technically (and toughest physically), the areas that are most enjoyable to run in, or are in the most spectacular situations – the three types are subtly different, and the very best maps probably need to fufill at least two of these three criteria.

In terms of best technical areas that I’ve run on, The Trossachs in Scotland has got to be up there, along with most areas in Sweden I’ve run in – particularly Lunsen near Uppsala which was the venue of the Varsity Match in 2008. The most enjoyable race I’ve run in is probably Venice, and running around and through the Cite de Carcassonne in the south of France was pretty spectacular. Some of the urban events that are currently popular in the UK would rate quite highly as spectacular, I think, including Oxford in 2006, and my own City of London Race – particularly if we do have it on both sides of the River Thames in 2010.

An area that fulfils all three of the criteria without doubt though is Trockener Steg, which was Day 3 of the Swiss O Week in Zermatt in 2006. In fact, the whole week was superb, but this was my favourite map of all, particularly the running on the amazingly complex, recently glaciated rocks. The views to the Matterhorn were stunning, the orienteering was fiendishly complex and it was great fun.

(Article updated to clarify the project organisers, and add some nice photos.)

Day 3 Finish (4269)

Categories
Orienteering

Pub-O

While digging through some old directories, I came across this artwork for an OUOC social back in 1999:

[Update – I believe this may be the work of the legendary OCCO President and true recreational orienteer, The Boy Nailest.]

Categories
Technical

Simple Choropleth Maps in Quantum GIS

It’s straightforward to create attractive choropleth maps in Quantum GIS, but there are a few things that can trip you up in the process.

The choropleth map I want to show is the distribution of deliberate fire-starting across London. A more advanced analysis would weight by ward area or population size, but I’m just showing the raw results, on the probably flawed assumption that wards in London have approximately equal populations and don’t vary in size hugely. Here’s how to do it, in Quantum GIS 1.4 “Enceladus” which was released a few days ago.

1. My boundary spatial data is a shapefile of the wards of London, which Quantum GIS can load without a problem, but my statistical data is in the form of a CSV file, showing the numbers of deliberate fires in each ward. It’s supplied by the new London Datastore, and CSV should not be a problem, but unfortunately the “Join attributes” functionality in Quantum GIS needs the data in DBF format.

Annoyingly, the most recent versions of Microsoft Office applications do not allow you to save data files as DBFs. However, OpenOffice will allow the conversion.

The big gotcha is that Quantum GIS is quite happy to load the CSV file as a layer, and will not complain if you select it as a vector layer to join in the “Join attributes” dialog box. It will simply go ahead and produce a result shapefile containing no data. This was the monitor-throwing bit. You have to instead select “Join dbf table”, and as the caption suggests, it needs to be a DBF.

There is also a bug in the “Join attributes” dialog box – available table columns are not removed when you select different layers in the drop downs, they just get appended to the list, so be careful to select the correct one.

I’ve used the “Continuous Color” option for the symbology setting as this allows me to quickly change the colours and remove the outlines – using “Graduated Symbol” would be a more authentic choropleth as the map would show discrete colours for each grouping.

Here is the resulting choropleth map, with the default adornments. Looks rather nice!

Categories
Orienteering

Drawing Nice ISSOM Buildings in Illustrator

ISSOM orienteering maps show buildings in plan view. Many buildings edges are orthogonal (i.e. at right angles to each other) – here’s how to draw these buildings neatly and correctly in Adobe Illustrator CS3, and also ensure that parallel building features are lined up correctly.

1. Measure the angle that the building is at, on your basemap:

2. Open up Preferences and go to the General tab. Enter the measured angle in the “Constrain Angle” box:

3. Draw the vertices of the building. Holding down Shift will now constrain subsequent vertices to the constrain angle (and +/- 45 degrees and 90 degrees from it) rather than to the horizontal and vertical of your screen.

4. Using Smart Guides in conjunction with setting the constrain angle will help line up parallel features, allowing buildings to be drawn quickly and accurately. A quirk of switching on Smart Guides, is that you will normally then need to click to reselect any existing node, vertex or partially-drawn building.

Smart Guides are very useful, but can be annoying when drawing very complex buildings with shallow or unusual angles – I typically switch them on or off repeatedly when tracing such buildings, and memorise and jump between two or more constrain angles for different “wings” of the building.

The background imagery used in this example, by the way, is recently released imagery showing the extent of the earthquake damage in Port-au-Prince, Haiti. The OpenStreetMap community is working to quickly complete a map of the city to aid the rescue effort.

Categories
Leisure Notes Orienteering

Review of the Year 2009: Part 1

2009 was a year in which I started to do less orienteering (after 13 years in the sport), a bit more running, and a lot more cycling. It was also almost an injury-free year.

January

The year started with a training score exercise in Aird’s Park, near Oban, on New Year’s Day. “Park” is a highly misleading name for the area, it was extremely physical with tussocks and marshes everywhere. Managed to finish second, but only because most of the good people misjudged the time back to the start and got penalties. I was up in the Scottish Highlands on the annual JOK New Year hillwalking trip, so the following day it was back to the Munros – and what a day. The four eastern Mamores climbed in cold and crisp conditions, finishing well after dark.

The only other orienteering in January was two London street-Os – an LOK race in Hampstead and a SLOW race in Wimbledon. They were very hilly, and I got a late penalty at both. And also a weekend of city races – on the Saturday the second Edinburgh Street Race which I enjoyed even more than the first, especially as I didn’t get disqualified this time – and then on the Sunday, having travelled right back to London, it was up again to Lincoln for their own City Race, again the second time I have run it. Again, a great race, and even better than the one before. This time, we got to run right through Lincoln Castle – up the drawbridge, across the battlements and out through the gate. A race with a definite “wow” factor.

On the summit ridge of Binnein Mor (5290)

February

In February I was quite preoccupied with planning for the JOK Chasing Sprint, which was near Watford. A few chilly weekends were spent surveying the courses. There was also another SLOW street-O, at Kingston, where I again got a late penalty!

Also, I got back up in the Highlands, for one day only. Sleeper to Glasgow, early morning train up, six damp hours in the hills around Loch Ossian (some snow, but a big thaw was on) and then back on the train overnight to London. I’m doing it all again next month.

Finally, I got to use my mountain bike on “proper” terrain as opposed to the streets of London – a two hour lap of the “Red trail” singletrack at Bedgebury Forest in Kent – a warm-up for a weekend singletracking in Wales. My cheapo-MTB held up just fine, which was more than could be said for Chris’s hire bike.

View down to Loch Ossian (5361)

March

The first terrain orienteering of the year – BUCS in SW London. Oxford was organising it on SLOW areas. I went very wrong indeed at the individual race – probably lack of practice. The relay was a bit better but I was still a bit clueless. At least I was a bit better at the next SLOW street-O two days later, in Surbiton. Didn’t get a late penalty for once.

The next weekend it was time for my first mega-cycle of the year – over 10 hours in the saddle, as I tried (and failed) to get to Eastbourne. My mistake, perhaps, was following the National Cycle Network route (21) strictly, even where it goes off the road to go up a bumpy, muddy track, only to rejoin the road a couple of km later. It did this many times. Some sections were very pleasant, such as the bit around Eridge. But, 140km after leaving Hackney, it had got properly dark, so I cut the trip short.

One week later I was off on the bike again, this time taking the “official” road-cycling route to Brighton. I completed the 100km route in just over 5 hours, + a couple of hours of stops – slightly disappointingly seven minutes longer than last year’s.

I also made a start on mapping the western extension to the City of London orienteering map, with a wander around the old alleys off Fleet Street.

The month finished with a weekend in Wales, on the various MTB singletrack trails in Coed y Brenin in North Wales. Great fun, a lot of trails were done, including the Tawr and most of the Dragon’s Back.

n779785520_6111535_5282780

April

The fourth trip in four months to Scotland – on Saturday I ran in the Scottish Sprint Orienteering Champs at Stirling University. Afterwards I went for a walk up to the Wallace Monument – I’d been meaning to have a look around this for years. The following day I ran the Edinburgh Half-Marathon – the sprints having been a less-than-ideal preparation. The second half of my race was a lot slower than the first. I’m doing the full-marathon version this year, and will be preparing better!

A couple of days later, and I had not recovered, but I ran anyway in the final SLOW street-O of the year, in Pimlico. I got around with two seconds to spare, and got my second best result of the series. Tim & CJ’s feast was excellent. Then it was back up to Scotland for Easter, but doing the JK Sprint in Newcastle on the way.

Back in London, I cycled 75km to Cuckfield with Anna, the first of our joint training trips for John O’Groats-London in the summer. It was a busy weekend – on the 19th I ran in the Newham Classic 10K – it was a very local race for me, and cheap to enter, and the route past the Olympic Stadium looked interesting. Then in the afternoon more City of London map surveying, around Lincoln’s Inn – and I had my bike nicked! It had lasted only 18 months, although as it happened I was going to be getting a road bike for the long summer cycles anyway.

Finally, there was the Varsity Match, which was just north of London and later in the year than normal – this year’s is in early March in Cornwall. The individual was in Epping Forest – always an enjoyable area to run on. The course was tough but pleasant, and my race was livened up when I spotted a snake slivering away from one of the controls near the end. It was warm enough to lie around at the finish and eat ice cream – summer was on its way!

Dalkeith to Peniculk Railway Walk (5967)

Categories
OpenStreetMap Orienteering

Minor Tweaks

Some small updates to OpenOrienteeringMap:

  • Where trams run on or very near roads, they are now shown as being underneath the road. For the Street-O map, this means they are partially or completely obscured. On the Pseud-O map, a set of square dots shows where the tram goes. This stops the tram line from obscuring the (passable) road.
    oomtrams
  • Hedges are now drawn underneath the road layer, so they no longer obscure passable roads.
    oomhedges
  • Paths and tracks in tunnels (e.g. in shopping centres) are now shown on the Street-O map – previously they only appeared on Pseud-O.
Categories
Orienteering

OpenOrienteeringMap Covers the World

oomamsterdam
OpenOrienteeringMap now covers the whole world – previously just Great Britain was included. You can now jump to a location by entering the latitude and longitude, and the country-level name clouds are now replaced with the regular OpenStreetMap maps. The mapping data is from 6 January.

Above: Amsterdam. Below: The Forbidden City.
oomforbiddencity

Categories
London

A Year at UCL

Here’s some iPhone photos from my office window at UCL, over the last 12 months.