« Older Entries Subscribe to Latest Posts

10 Feb 2010

It’s Back

Posted by Oliver. No Comments


#uksnow is great – it allows us Brits to indulge in our national pastime of talking about very minor weather events.

9 Feb 2010

Prettier Maps with Mapnik 0.7.0

Posted by Oliver. 3 Comments

[Updated] The Mapnik 0.7.0 release last month has added a number of features, including one that makes choropleth maps, and others with numerous adjacent polygons, more pretty. The PolygonSymbolizer has a new parameter, gamma, which, when set to a value between 0 and 1, causes the polygon edges to bleed into each other slightly, removing distinctive hairlines that allow the background colour to “shine through” the joins.

Here’s a before-and-after of a choropleth of England & Wales. We don’t care much for the boundaries, as they are Middle-Level Super Output Areas (MSOAs), which are administrative boundaries that people are not familiar with, unlike say county boundaries. So, using the gamma parameter, we can hide them.


Mapnik 0.6


Mapnik 0.7

The new parameter is also useful for my OpenOrienteeringMap project, particularly to make large estuaries, which are typically made up of multiple polygons, appear contiguous. However, applying too low a value appears to affect the anti-aliasing of line features, even ones away from the affected polygons. Here, the gamma is just applied to the “water” style. Note the thin white line crossing the water, near the black dotted line that also crosses it, disappears, but the paths and roads start to distort too:


Mapnik 0.6 – thin white line running across the river.


Mapnik 0.7+patch (Gamma 0.8) – the thin white line has gone. Other features are unchanged.

The map tile, by the way, is showing the Greenwich Foot Tunnel crossing the River Thames in east London.

[Update - The crossed-out section highlights a bug that has now been fixed by the Mapnik development team. I've patched my Mapnik build and the gamma changes now only appear where expected.]

5 Feb 2010

OpenLayers 101

Posted by Oliver. No Comments

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 pulls in some custom tiles from a URL and overlays them on the “standard” OpenstreetMap map. You will need to change the URL (and attribution text) to point to the overlay you are interested in.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>NPE Scotland</title> <script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"> </script> <script type="text/javascript"> var map; var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); var EPSG900913 = new OpenLayers.Projection("EPSG:900913"); var b = 20037508.34; function init() { map = new OpenLayers.Map ("map", { controls:[ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.Attribution(), new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.MouseDefaults(), new OpenLayers.Control.KeyboardDefaults()], maxExtent: new OpenLayers.Bounds(-1*b, -1*b, b, b), maxResolution: 156543.0399, units: 'm', projection: EPSG900913, displayProjection: EPSG4326 }); layerMapnik = new OpenLayers.Layer.OSM( null, null, { numZoomLevels: 15 }); layerOverlay = new OpenLayers.Layer.OSM( "NPE Scotland", "tiles/${z}/${x}/${y}.jpg", { transitionEffect: "none", isBaseLayer: false, attribution: "Imagery CC-By-NC-SA NPEMap.org.uk" } ); map.addLayer(layerMapnik); map.addLayer(layerOverlay); var start = new OpenLayers.LonLat(-3.5, 56.5); map.setCenter(start.transform(EPSG4326, EPSG900913), 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:

1 Feb 2010

Converting OS Eastings/Northings to Grid References in Python

Posted by Oliver. No Comments

[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: ]

15 Jan 2010

Simple Choropleth Maps in Quantum GIS

Posted by Oliver. 3 Comments

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!

8 Jan 2010

A Year at UCL

Posted by Oliver. 2 Comments

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

24 Dec 2009

Season’s Greetings

Posted by Oliver. No Comments

2010 promises to be a very exciting year for GIS, neo-geography and information visualisation.

Potentially one of the most interesting events that may happen next year is a big shift on access to mapping data in the UK. Yesterday, the Communities and Local Government Department (CLG) published the consultation paper for opening up Ordnance Survey data. The consultation is open until March.

Also in March is the first Wherecamp EU, right here in London. I’ve looked on enviously as the neo-geos and proto-geos do cool things with spatial data over in the States at Wherecamp, and its associated “regular” conference Where 2.0. Now we get to do the same!

Geomob’s next evening, at my alma mater City University in January, has an interesting lineup of speakers, possibly including the author of Information is Beautiful – the UK edition of which is out shortly after in February.

This year was pretty amazing for opening up access to data – there’s a lot of it out there, now we just need to visualise it. Here are some lovely examples.

Finally, the British Library is putting on a major exhibition of historic maps from April – Magnificant Maps, which will include the largest book in the world – six feet high apparently. I saw their “London: A Life in Maps” exhibition back in 2007 and was highly impressed. They have an impressive collection and I look forward to seeing next year’s exhibition.

Season’s greetings!


Bauble from the OpenStreetMap Wiki

18 Dec 2009

On-The-Fly Mapping Preview

Posted by Oliver. 1 Comment

oom1

A public preview of the on-the-fly mapping that is being used for the CensusGIV project is available at OpenOrienteeringMap (OOM).

The same mechanism that will be used to produce the varied choropleth maps of census data is being used to produce the “Street-O” and “Pseud-O” maps on OOM. The main differences are that the map image files, or tiles, are more aggressively cached – as there’s only two maps rather than millions – and the designs are in an XML file rather than being specified on the URL, as they are much more complex than simple thematic choropleth maps.

oom4

Further details of the construction are in a posting and information page on my personal blog.

Top: “Pseud-O” map of Furzton district in Milton Keynes. Bottom: Edinburgh Old Town “Street-O” map.

9 Dec 2009

CensusGIV Prototype Presentation for CASA

Posted by Oliver. No Comments

My boss (Dr Pablo Mateos) and I gave this presentation today as part of this term’s CASA Seminar series here at UCL. My bit starts at slide 22 (of 60! – we just about managed it in the hour but only by rushing at the end.)

chorogen
CensusGIV – Geographic Information Visualisation of Census Data

View more documents from oliverobrien.

Note that the censusprofiler site mentioned a couple of times in the presentation only has a (very out of date) blog on it at the moment, and the prototype itself is not yet available for general use – with luck, an alpha version will be available to play with by the end of the year.

20 Nov 2009

Flow Map

Posted by Oliver. No Comments

While search for a way to visualise flows between schools and universities in England, I came across this excellent bit of software by Doantam Phan et al from Stanford: Flow Map (paper). It was presented at Infoviz 2005.

It’s a Java application, simple to install, and with the addition of an appropriately formatted data file, you can have a flow map up quickly. The software allows points to be moved around to declutter the visualisation – allowing a good balance between geographic accuracy and clarity.

Here’s the English universities that Southend-on-sea school pupils choose to go to – N and W England cropped out for simplicity:

sthdaa_crop

London and the other multi-university cities are “exploded” but the universities retain their geographic equivalence.