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.
- clone the repo
virtualenv --no-site-packages env
You'll need to install the GDAL and related libraries for your platform, see the GeoDjango documentation.
pip install -r requirements.txt
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.
Get the SHP files with the new dataset
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.
Create a new generation (without activating it)
python manage.py mapit_generation_create --desc "2016 electoral boundaries" --commit
Take note of the ID of the generation you just created, you'll need it later.
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 manage.py 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``
That WON'T make any changes since you haven't specified
--commitbut it lets you sanity check what's going on. Run it again with
Ensure that mapit-za/management/za_metadata.py is up to date with the latest mappings between different levels.
Update the MDB-level codes:
python manage.py mapit_za_codes --generation=2
Only activate the new generation once all the data has been imported:
python manage.py mapit_generation_activate
This app runs on Dokku (or Heroku).
Be sure to set these environment variables: