GeoDjango, PostGIS, Heroku and Circle Continuous Integration

At Gramercy Studios, we’ve been using PostGIS (the GIS extension to PostgreSQL) to store locations as spatial fields in the database. This allows for intelligent database querying – e.g. to find points within 1km of a selected latitude/longitude, determine what city/country (POLYGON) points are contained within, to find the bounding box surrounding a number of geometry features, or simply find the distance between two points.

GeoDjango adds support for PostGIS (django.contrib.gis.db.backends.postgis) and GIS fields (PointField, PolygonField, etc) to Django, which lets us build location-enabled web APIs from a high level. Some configuration is required to get all this running smoothly locally (OSX), on Heroku and with Circle CI, a continuous integration/deployment service we’re using.

We’ve found that the Heroku multi buildpack (BUILDPACK_URL: https://github.com/ddollar/heroku-buildpack-multi.git) with the following buildpacks (Python and GEO) works well:

With Postgres.app (and Django/geos/etc) installed locally on our macs, the following settings file allows us to have full GIS support when developing our Django apps locally, and when deployed to Heroku. (You’ll need to run psql and create the postgis extension locally – see the top of the settings file)

On Circle CI, we found that the postgis extension wasn’t getting created, so we added a command to run on post-database creation in our circle.yml configuration file:

Hopefully this will help someone out in the future – enjoy!

Serialising Shapely objects to JSON

Lately I’ve been using Shapely to perform geometry operations, and I’ve come across the need to serialise a number of objects in a Python data structure to JSON. I’ve chosen to use a custom JSONEncoder and JSONDecoder class.

image_processing_edge

OpenCV – Mown grass detection

Over lunch today, a few friends and I were discussing the possibility of an autonomous grass mowing robot. We decided that the major problem was navigation – following the edge of the lawn that has been previously mown. I present a (relatively) simple method using Python and OpenCV to estimate the border between areas of cut and uncut grass. Continue reading