« Older Entries Subscribe to Latest Posts

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.

4 Nov 2009

Google Maps – Nearly Alright

Posted by Oliver. 1 Comment

There’s been some discussion about the large number of small-scale mistakes present in Google Maps – there were always a few, but that number has increased dramatically recently as Google has included new sets of POIs.

What I find is that the map looks pretty good if you just need to drive around an area, but once you zoom and study it in detail, the bugs appear. Of course, if you don’t know the area, you probably aren’t going to notice the problems unless you really go looking for them, so perhaps it’s still “fit for purpose”.

My local area (pretty close to central London, not somewhere random in the countryside) has some real howlers – but then, people driving through aren’t going to notice:

googlemaps1

Never mind, OpenStreetMap to the rescue:
osm1

For me, it’s particularly pleasing that OpenStreetMap is now becoming more accurate than Google Maps in these respects, rather than just catching up – as long as there’s a keen local contributor in each area. Adding simple (POI) data to OSM still isn’t quite as easy as it could be, although it’s much improved with recent Potlatch updates, and Mapzen looks like it could make the process easier still.

9 Oct 2009

High Resolution Historical OS Maps now in OSM

Posted by Oliver. 5 Comments

campbeltown

[Updated] – Steve Chilton (designer-in-chief of the “standard” OpenStreetMap map) has announced the first Ordnance Survey 7th Series 1:50000 map scans are now available for tracing on to OpenStreetMap. The first ones available are in the south-west of Scotland. Further details of the project area are here.

On the right is what Girvan, a town in Ayrshire and Galloway, looks like in OpenStreetMap currently. Below that is what the 7th series imagery offers – and, bottom, the modern-day Google mapping data. This shows that, for even some sizeable towns, a 50-year-old map still has a lot to offer to enrich OpenStreetMap.

The scans have been reprojected into the “Spherical Mercator” format so they can be used in Potlatch – OpenStreetMap’s main online editor. They build on the New Popular Edition maps, which have been reprojected in England and Wales, but not Scotland so far, allowing OSM contributors to add features from the maps into the project.

Because the maps are (just) over 50 years old, their Crown Copyright has expired, which is why they can now be included in the project. Unfortunately many of the 7th series maps were printed in the early 1960s, so we’ll have to wait a few more years for these to come out of copyright and Scotland be fully covered. It would be lovely of course if the OS were to waive the copyright on these…

The maps can be seen directly here – the quality of the imagery is excellent, as can be seen in the screenshot above. Incidentally, the tilt of the grid squares is very noticeable here – the angle between grid and “true” north is quite pronounced in west Scotland.

[Update - The NPE, OS 7th Edition mentioned here, and a small number of 1:25000 OS 1st Edition maps can be directly compared on the new OOC map.]