Represent Boundaries loads geospatial data in the shapefile format. Other formats like KML and GeoJSON can be converted to shapefile using tools like ogr2ogr. Before using Represent Boundaries, collect the geospatial data that you need. For example, collect Canada's federal electoral districts:

curl -O

You've got your shapefiles? Next, write definition files that describe how to load shapefiles into the API. When a shapefile is loaded, a boundary set is created for the shapefile and a boundary is created for each polygon feature in the shapefile. See the sample definition file to learn how to control how shapefiles are loaded. Most parameters in a definition file are optional. Here's a minimal definition file for Canada's federal electoral districts:

from datetime import date

import boundaries

boundaries.register('Federal electoral districts',
    last_updated=date(2011, 11, 28),

The loadshapefiles command looks for definition files, ending in or, in my_project/data/shapefiles. You can change this path by setting BOUNDARIES_SHAPEFILES_DIR in my_project/ Represent Boundaries will walk the directory tree looking for definition files, so you may organize your shapefiles any way you like. puts the shapefiles in subdirectories with a single top-level definition file, while Represent creates a tree with a definition file in each directory containing a shapefile.

If you've been following the example, move the shapefile and definition file for Canada's federal electoral districts into data/shapefiles. You may need to create the directory before moving the files:

mkdir -p data/shapefiles

You can now run:

python loadshapefiles

The data should now be available via the API. Let's explore the API.