Skip to content

Instantly share code, notes, and snippets.

@philandstuff
Last active August 29, 2015 14:23
Show Gist options
  • Save philandstuff/467ca5f39ddcec8cd635 to your computer and use it in GitHub Desktop.
Save philandstuff/467ca5f39ddcec8cd635 to your computer and use it in GitHub Desktop.
standalone mapit experience

mapit

standing up a mapit instance

Setting up a standalone mapit instance is documented at http://mapit.poplus.org/docs/self-hosted/install/ but there are some issues. This summarizes what I needed to do:

# install postgis
brew install postgis

# set up db
createuser mapit
createdb mapit
psql -d mapit -c 'CREATE EXTENSION postgis;'

# clone the mapit repo
git clone git://github.com/mysociety/mapit.git
cd mapit

# set up standalone django project
cp conf/general.yml-example conf/general.yml
# edit according to documentation above.  in particular, you want these settings:
# MAPIT_DB_HOST: localhost
# MAPIT_DB_PORT: 5432
# AREA_SRID: 4326
# -- leave everything else alone

# install deps into a virtualenv:
virtualenv .venv
source .venv/bin/activate
pip install -e .

# compile sass (may require installing the rubygem)
bin/mapit_make_css

# initialize db for django app
./manage.py migrate

# start the django server:
./manage.py runserver

parking lot: documentation issues to report upstream

  • ./manage.py migrate mapit doesn’t work if you haven’t already run ./manage.py migrate

importing postcodes from the postcode register

The docs for importing data are quite good. To import data from the postcode register, you only need two commands:

curl -O http://postcode.openregister.org/all.csv
./manage.py mapit_import_postal_codes --coord-field-lat 3 --code-field 2 --strip --header-row all.csv

Explanation:

  • --coord-field-lat says which column the latitude will be in. (You can specify a seprate column number for longitude, but it will assume it’s the next column after latitude if you don’t)
  • --code-field says which column the postcode will be in.
  • --strip says that the postcode field contains spaces that mapit will want to strip (ie “SW1A 0AA” -> “SW1A0AA”)
  • --header-row says that the csv has a header row which needs to be skipped

Caveat: the all.csv only returns 1000 records at the moment.

To check it worked, visit http://localhost:8000/ and search for “AB15 9NT” which should be the first postcode in all.csv. It should show you that postcode’s location (north deeside road) on openstreetmap.

To investigate: streaming updates after initial import.

importing boundaries

We don’t have an equivalent register for this at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment