colouring-montreal/etl
2022-03-31 16:27:36 +01:00
..
join_building_data Add debug, no overwrite flags 2020-06-16 16:16:46 +01:00
screenshot add screenshot image 2022-03-18 11:27:05 +00:00
__init__.py add test for filtering mastermap (not working) 2022-03-18 14:34:06 +00:00
create_building_records.sh Update etl to load UPRNs to table 2018-10-02 21:12:46 +01:00
drop_outside_limit.sh Skip altering foreign key restrictions 2018-10-04 19:00:56 +01:00
extract_mastermap.sh add echos to extraction step 2022-03-29 14:46:18 +01:00
filter_mastermap.py remove print statement 2022-03-29 14:37:42 +01:00
filter_transform_mastermap_for_loading.sh fix filtering script 2022-03-29 15:41:00 +01:00
get_test_polygons.py flake8 2022-03-18 16:18:44 +00:00
load_geometries.sh add echos to load geometries 2022-03-29 14:48:27 +01:00
load_new_geometries.sh create script to load new geometries 2022-03-31 16:27:36 +01:00
load_postcodes.sh Set postcode zoom and class 2019-02-11 09:07:26 +00:00
README.md remove bad comments 2022-03-31 15:42:06 +01:00
requirements.txt bump shapely version 2022-02-03 14:51:48 +00:00
run_all.sh remove addressbase from all steps and reorder readme 2022-03-18 11:07:15 +00:00
run_clean.sh remove addressbase from all steps and reorder readme 2022-03-18 11:07:15 +00:00

Creating a Colouring London database from scratch

Data downloading

The scripts in this directory are used to extract, transform and load (ETL) the core datasets for Colouring London:

Building geometries, sourced from Ordnance Survey (OS) MasterMap (Topography Layer)

To get the required datasets, you'll need to complete the following steps:

  1. Sign up for the Ordnance Survey Data Exploration License. You should receive an e-mail with a link to log in to the platform (this could take up to a week).
  2. Navigate to https://orders.ordnancesurvey.co.uk/orders and click the button for: ✏️ Order. From here you should be able to click another button to add a product.
  3. Drop a rectangle or Polygon over London and make the following selections, clicking the "Add to basket" button for each:

  1. You should be then able to check out your basket and download the files. Note: there may be multiple .zip files to download for MasterMap due to the size of the dataset.
  2. Unzip the MasterMap .zip files and move all the .gz files from each to a single folder in a convenient location. We will use this folder in later steps.

Prerequisites

You should already have set up PostgreSQL and created a database. Make sure to create environment variables to use psql if you haven't already:

export PGPASSWORD=<pgpassword>
export PGUSER=<username>
export PGHOST=localhost
export PGDATABASE=<colouringlondondb>

Create the core database tables:

cd ~/colouring-london
psql < migrations/001.core.up.sql

There is some performance benefit to creating indexes after bulk loading data. Otherwise, it's fine to run all the migrations at this point and skip the index creation steps below.

Install GNU parallel, this is used to speed up loading bulk data.

Make data available to Ubuntu

If you didn't download the OS files to the Ubuntu machine where you are setting up your Colouring London application, you will need to make them available there. If you are using Virtualbox, you could host share a the folder containing the MasteerMap files with the VM via a shared folder (e.g. see these instructions for Mac).

Process and load Ordnance Survey data

Move into the etl directory and set execute permission on all scripts.

cd ~/colouring-london/etl
chmod +x *.sh

Extract the MasterMap data (this step could take a while).

sudo ./extract_mastermap.sh /path/to/mastermap_dir

Filter MasterMap 'building' polygons.

sudo ./filter_transform_mastermap_for_loading.sh /path/to/mastermap_dir

Load all building outlines. Note: you should ensure that mastermap_dir has permissions that will allow the linux find command to work without using sudo.

./load_geometries.sh /path/to/mastermap_dir

Index geometries.

psql < ../migrations/002.index-geometries.up.sql

Create a building record per outline.

./create_building_records.sh

Run the remaining migrations in ../migrations to create the rest of the database structure.

ls ~/colouring-london/migrations/*.up.sql 2>/dev/null | while read -r migration; do psql < $migration; done;

[WIP] Updating the Colouring London database with new OS data

TODO: this section should instruct how to update and existing db