Giter Club home page Giter Club logo

postcodes-mapit's Introduction

Voronoi Postcodes MapIt

This repository is for a version of MapIt which contains postcode boundaries calculated from the Voronoi diagram of UPRNs with postcodes in NSUL.

For more information see the blog post here:

If you're looking to create a MapIt in your country, work on any of the underlying code, or re-use it as an app in another Django project, you probably want https://github.com/mysociety/mapit instead.

How to generate the data

If you just want the data yourself, there's no need to follow these instructions - you can download it. instead. If for some reason you really want to regenerate i yourself, read on.

Create a virtualenv for this project, change into the cloned repository directory and run pip install -r requirements.txt to install the Python package dependencies.

Download NSUL

You can get NSUL from the ONS's Open Geography Portal. e.g. here is the July 2021 version

Unpack the archive somewhere convenient.

Create the database and schema

Create a PostgreSQL database and install the PostGIS extensions with CREATE EXTENSION postgis and CREATE EXTENSION postgis_topology.

Create a ~/.mapit file with your database credentials, something like:

{
    "DJANGO_SECRET_KEY": "some long random string",
    "MAPIT_DB_NAME": "mapit-postcodes",
    "MAPIT_DB_USER": "",
    "MAPIT_DB_PASS": "",
    "MAPIT_DB_HOST": null,
    "MAPIT_DB_PORT": "5432",
    "COUNTRY": "GB"
}

Then run ./manage.py migrate to create the database tables.

Load the NSUL data into the database

You can do this with:

./manage.py mapit_postcodes_populate_nsul_table -r data/regions/gb_regions_multipolygons.shp ../NSUL/Data/*.csv

... adjusting the wildcarded parameter for where you've actually extracted NSUL.

Calculate the Voronoi diagram

This command will calculate the Voronoi diagram of all those points, and store the results in the database:

./manage.py mapit_postcodes_populate_voronoi_table

Generate postcode GeoJSON files

This command will create unions of the Voronoi regions to create polygons representing all postcode areas, districts, sectors and units and output them to GeoJSON. (Warning: even with a fast machine with many cores, this can take several days to run, so you definitely want to run it under tmux or similar.)

./manage.py mapit_postcodes_union_postcode_regions --skip-vertical-streets \
    -r data/regions/gb_regions_multipolygons.shp \
    -o data/gb-postcodes

That will generate those GeoJSON files under data/gb-postcodes

Package up the data

To build a bzip2-compressed tar archive of these GeoJSON files, you can run:

bin/make-data-archive.sh data/gb-postcodes

... which will create the archive as data/gb-postocdes.tar.bz2.

Import the data into MapIt

If you want to import this data into a MapIt instance, then you can do that with:

./manage.py mapit_postcodes_import_postcode_areas data/gb-postcodes 1

... where 1 is the ID of the MapIt Generation you want to import the areas into. (It won't try to reimport any areas that already exist in that generation.)

If you want postcode lookups to work from the front page of the MapIt instance you will also need to import postcodes from ONSPD or Code-Point: see http://code.mapit.mysociety.org/import/uk/ for more details.

Contact

Contact: [email protected]

postcodes-mapit's People

Contributors

mhl avatar tombarton avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.