Tuesday 12 February 2013

Creating masked vice-county rasters in Quantum GIS

I was inspired by Teresa Frost to have a go at making a good base-map for South Yorkshire (well, the Watsonian vice-county 63 to be precise) in Quantum GIS (v. 1.8.0). I thought it would be relatively straight-forward, but, I soon came up against an irritating problem, that of successfully trimming a raster of elevations using a vector of vc63. I overview the process below, because by the look of the many mentions of this topic on many forums and mailing lists, there is a need for more examples! There are no doubt easier ways of achieving what follows, but this is what worked for me.

Firstly, I retrieved the Land-Form PANORAMA® data from the Ordnance Survey's new(ish) OpenData website, and the Watsonian vice-county boundaries from the NBN. The Land-Form download contains, amongst other things, Digital Terrain Models (DTM) in ASCII format, by 10 km grid squares.

In order to merge all of the necessary 10km DTM square into one raster, it was first necessary to get a list of all the 10 km squares overlapping vc63: this Biological Records Centre website was handy for that.

1) In Quantum GIS, the Raster --> Miscellaneous --> Merge option allows the import of multiple rasters and merges them to one raster layer in your project. I chose OSGB 1936 (EPSG:4277) (the Ordnance Survey National Grid) as the Spatial Ref. System for this work.



2) Visualising the DTM data is also a minor challenge, and can be overcome by right-clicking the raster layer, and choosing 'Properties'. Under 'Style', change the color band option to 'pseudocolor' and you should now see the DTM data, albeit in fairly lurid colours.

3) Import the vc63 shapefile via the normal route (Layer --> Import Vector Layer). (If you get it from NBN, it should already be georeferenced to the OS National Grid, but you can check that the bottom right box in the QGIS window says EPSG:4277).

4) As far as I know, it is necessary to polygonise the vice-county boundary in order to use it to "mask" (i.e. clip) the raster image. Luckily, there is a handy plugin for this (Plugins --> Fetch Python Plugins... --> search and install 'Polygonize'). Whilst you are there, it is also worth installing the plugins "Value Table", and, by adding a new repository, the "1-Band Raster Colour Table" (see this stackexchange question for advice on this).

5) Polygonize your shapefile using the new plugin. (Vector --> Polygonizer --> Polygonizer). As it says, try the "old" method if the new one doesn't seem to work.



6) The mask step was the most complex, and, despite trying numerous routes, it was this method that worked in the end: Raster Masks in QGIS/FOSSGIS. The result is below (don't let the change in colour put you off!):


7) Actually, this didn't quite work, because the clipped raster was still showing the "null data" outside the clipping boundary as coloured. Luckily I could get around this by reprojecting the clipped raster to a new file (using the same Spatial Ref. System) using a Raster --> Warp (Reproject).

8) Then I applied a b/w DTM colour scheme using the 1-Band Raster Colour Table plugin (under Raster menu) mentioned earlier. This generates a text file style, that can subsequently be imported and applied via right-clicking on the raster layer, and choosing 'Properties', then the 'Style' tab, also mentioned earlier.


Now I just need to add rivers and urban areas! Think I'll save that for another day : ) All in all, this did take a fair bit of messing around to accomplish, and occasional quirks of QGIS did slow me down (for example, layers sometimes need to be exported (right click and "Save as..." for vectors; Raster --> Warp (Reproject) for rasters) and re-imported, before they can be selected as layers for masking or other transformations). Additionally, very few of the methods suggested out on the web seemed to work, until I found the method used above. But, once you know the pitfalls, work-arounds seem to be possible. Also, more background knowledge on my part wouldn't go amiss...

No comments:

Post a Comment