Do I Need An Umbrella Today?

A few years ago I came across Umbrella Today. The site had a simple function, providing a weather forecast with only one variable: is it going to rain today? Enter your zip code and you get a Yes-No answer to the question. The simplicity of this appealed to me. Although it was featured on LifeHacker in 2008 the site has since gone offline. Anyway, I don’t live in the USA and therefore didn’t have a zip code.
Read more

Splitting large polygons for faster intersections

Large polygons are a problem for geoprocessing operations. Intersections involving large polygons are slow because the entire geometry needs to be evaluated. In addition to this, spatial indexing doesn’t help (much) because the bounding box of the polygon is itself large. This is a common problem with flood extent data, which is exported from hydraulic models without much thought as to how it will be used. An example of this is the Risk of Flooding from Rivers and Sea (RoFRS) layer available from the Environment Agency (released under the OGL on EA Geostore).
Read more

Accessing CEH Gridded Estimates of Areal Rainfall (GEAR) with Python

The Centre for Ecology & Hydrology (CEH) produce a dataset which provides an estimate of daily rainfall on a 1km grid for Great Britain and Northern Ireland from all the way back to 1890 onward to 2014. The data is hosted in NetCDF format hosted on an OPeNDAP server. At the time of writing only data to 2012 is available via OPenDAP. The script below demonstrates how to access this dataset from Python using the netCDF4 module.
Read more

Speedup Fiona with LRU caching

At some point you’re going to care about how long it takes your geoprocessing algorithm to run. While the Fiona and Shapely libraries make efforts to be as efficient as possible, a lot will depend on the algorithms you use them in. I’ve written before about how spatial indexing can speed up intersection and nearest neighbour queries. At the end of the previous article I mentioned a trade-off between speed and memory usage when the same features are requested more than once.
Read more

Homebrew Oxontime RTI display with Raspberry Pi

Update: As of 2016-03-31 the Oxontime service has changed provider and the API is no longer functional. Presumably a new API will be made available at some point. This post remains for posterity. The Oxontime Real Time Information (RTI) system provides real time predictions for bus departures in Oxfordshire, which are displayed on screens at many bus stops. The data is also available via an API. I thought it would be fun to use an Adafruit 16x2 LCD display and a Raspberry Pi to make my own personal display (photo below).
Read more

Find ArcMap document version with Python

This post shows how to find the version number of an ArcGIS map document (.mxd) programmatically using Python. It seems that arcpy does not provide a method to do this itself. ArcGIS map documents are actually Microsoft OLE2 files (also called Structured Storage, Compound File Binary Format or Compound Document File Format). There is a Python module called oletools which can read this format, which is available on PyPI. To install oletools using pip (from a command prompt):
Read more

Masking Rasterio Layers with Vector Features

This post shows how to extract data from a raster only where it intersects a vector feature using Rasterio. Fiona is used to read the vector data, and Shapely is used only as a convenience to calculate the feature’s bounding box. GDAL provides a function to “burn” vector shapes into rasters (i.e., to rasterize the geometries). This functionality is accessed from Rasterio using the rasterize function. This tool can be used to create a raster mask for another raster layer.
Read more

Embedding a Leaflet map in a Qt application

Embedding a map in a Qt application using Leaflet is surprisingly easy. The QtWebKit.QWebView object can be used to create a browser window within a Qt dialog. Within this browser window you can create an interactive map using Leaflet just as you would for any other browser. Communication between Qt and the Leaflet map is also possible, allowing you to control the map from the main application, or extract information from Leaflet.
Read more

Converting British National Grid and Irish Grid References: A Practical Example

The Environment Agency recently released their database of River Habitat Surveys (RHS) as open data, available from the GeoStore under the Open Government Licence. RHS is described as the ‘standard for collecting data on the physical character and quality of river habitats across the UK’. The data comes in the from of an Open Office XML spreadsheet, and includes survey data collected in England, Wales, Scotland and Northern Ireland from 1994 - present.
Read more

Reduce the file size of PDFs with Ghostscript

Portable Document Format (PDF) is a common format used for publishing maps. PDFs can contain both raster and vector data and can be read by a large number of freely available viewer applications, such as Adobe Reader and Okular. Adobe Reader Pro can be used to optimize the size of PDF files, by selecting File > Save As... > Optimized PDF. However, Adobe Reader Pro isn’t free, and isn’t easily automated.
Read more