Compiling Python extensions for old glibc versions

I'm a big fan of the Anaconda Python distribution. It makes managing multiple Python environments on different operating systems easy (at least in theory).

I recently came across an issue trying to import a Cython extension I'd built for Linux on a different machine. We'd be testing ...

Continue reading »

Masking NetCDF datasets using Rasterio

This post brings a couple of ideas from previous posts together, namely downloading data using NetCDF and masking raster layers with vector data.

The end result is the ability to query raster datasets using irregular shapes and only download the data you actually need.

Continue reading »

Pickling Cython classes

Automatic pickle support in Cython is still a pending feature. In order to support pickling of cdef classes you must implement the pickle protocol. This is done by implementing the __getstate__ and __setstate__ methods. Although the official documentation is quite clear, it lacks a simple example and also instruction on ...

Continue reading »

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 ...

Continue reading »

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 ...

Continue reading »

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 ...

Continue reading »

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 ...

Continue reading »

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 ...

Continue reading »

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 ...

Continue reading »

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 ...

Continue reading »