Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Code4SA's MapIt API

MapIt is a service that maps geographical points to administrative areas. It’s useful for anyone who has the co-ordinates of a particular point, and needs to find out what regions it lies within. It’s also great for looking up the shapes of all those boundaries.

Local development

  1. clone the repo
  2. cd mapit-za
  3. virtualenv --no-site-packages env
  4. source env/bin/activate

You'll need to install the GDAL and related libraries for your platform, see the GeoDjango documentation.

  1. pip install -r requirements.txt
  2. ./ runserver

Importing new boundaries

Every now and then you need to import new boundaries into Mapit. Generally this is after the Demarcation Board adjusts boundaries. For more information on importing data into Mapit, read the import documentation.

  1. Get the SHP files with the new dataset

  2. Important: If you're importing districts, you MUST remove the metro municipalities from the district shapefile first. Otherwise, because the MDB includes metros in both district and municipality shapefiles, the same district will be imported twice with the same codes but different municipality types.

  3. Create a new generation (without activating it)

     python mapit_generation_create --desc "2016 electoral boundaries" --commit
  4. Take note of the ID of the generation you just created, you'll need it later.

  5. Import the shapes for each area type (ward, province, etc) separately, specifying the new generation ID. For each shapefile you need to tell Mapit which fields from the shapefile to use for the name and code fields in the database.

     python mapit_import --generation_id=XXX --country_code=ZA --name_type_code=common --code_type=MDB --area_type_code=WD --name_field=WardID --cade_field=WardID -v 2 --preserve shapefile.shp``
  6. That WON'T make any changes since you haven't specified --commit but it lets you sanity check what's going on. Run it again with --commit.

  7. Ensure that mapit-za/management/ is up to date with the latest mappings between different levels.

  8. Update the MDB-level codes:

     python mapit_za_codes --generation=2
  9. Only activate the new generation once all the data has been imported:

     python mapit_generation_activate

Production deployment

This app runs on Dokku (or Heroku).

Be sure to set these environment variables:

  • DJANGO_DEBUG=false
  • DJANGO_SECRET_KEY=some-secret-key
  • NEW_RELIC_LICENSE_KEY=some-license-key


Django container for South African installation of mapit







No releases published


No packages published