polipoly – A tool for dealing with district boundary polygons

by

Finding out what congressional district an address falls within can be a difficult problem. Typically you need a 9 digit zip code, and the US Postal Service does not make looking up the zip+4 easy. Even with a zip+4, existing solutions are either expensive or inaccurate and sometimes both.

It turns out that the US census bureau publishes polygon files defining the boundaries of all 435 congressional districts. Through geocoding services such as google maps we can easily convert an address to a latitude and longitude and therefore it is possible to determine what district an address lies within by simply testing what polygon it falls within.

We recently added a new API method but one of the major drawbacks is that because it uses Google as a geocoding service we are limited to 50,000 calls a day. We’re aware that some organizations may want to do batch processing of their membership lists, which may means thousands of lookups at once. In addition to using up all of our geocoding requests, calling a web service for this kind of batch processing isn’t efficient.

To attempt to meet these challenges we are proud to announce polipoly. Polipoly is a small python library that uses public domain census shapefiles to allow developers to write simple python scripts that can relate addresses to congressional districts. And because you’re running it with your own Google Maps API key, you are able to use all 50,000 geocoding requests a day.

For information on installation and usage head over to the project page. Example source for a web service that works just like places.getDistrictFromAddress has been released, as well as an example of processing a CSV file similar to the kind that could be exported from a database or spreadsheet.

This is the second project we have released on Google Code (the first being the Sunlight ADK) but much more is on the way in terms of open source.