2018-09-25 15:46:16 -04:00
# Data loading
The scripts in this directory are used to extract, transform and load (ETL) the core datasets
for Colouring London:
1. Building geometries, sourced from Ordnance Survey MasterMap (Topography Layer)
1. Unique Property Reference Numbers (UPRNs), sourced from Ordnance Survey AddressBase
## Prerequisites
2020-06-18 05:32:35 -04:00
Install PostgreSQL and create a database for colouringlondon, with a database
user that can connect to it. The [PostgreSQL
documentation](https://www.postgresql.org/docs/12/tutorial-start.html) covers
installation and getting started.
Install the [PostGIS extension ](https://postgis.net/ ).
Connect to the colouringlondon database and add the PostGIS, pgcrypto and
pg_trgm extensions:
```sql
create extension postgis;
create extension pgcrypto;
create extension pg_trgm;
```
Create the core database tables:
```bash
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.
## Process and load Ordance Survey data
2018-09-25 15:46:16 -04:00
Before running any of these scripts, you will need the OS data for your area of
interest. AddressBase and MasterMap are available directly from [Ordnance
2020-06-18 05:32:35 -04:00
Survey](https://www.ordnancesurvey.co.uk/). The alternative setup below uses
OpenStreetMap.
2018-09-25 15:46:16 -04:00
The scripts should be run in the following order:
2018-09-29 13:29:57 -04:00
```bash
# extract both datasets
extract_addressbase.sh ./addressbase_dir
extract_mastermap.sh ./mastermap_dir
# filter mastermap ('building' polygons and any others referenced by addressbase)
filter_transform_mastermap_for_loading.sh ./addressbase_dir ./mastermap_dir
# load all building outlines
load_geometries.sh ./mastermap_dir
# index geometries (should be faster after loading)
psql < .. / migrations / 002 . index-geometries . sql
# create a building record per outline
create_building_records.sh
# add UPRNs where they match
load_uprns.py ./addressbase_dir
# index building records
2018-10-02 16:12:46 -04:00
psql < .. / migrations / 003 . index-buildings . sql
2018-09-29 13:29:57 -04:00
```
2020-06-18 05:32:35 -04:00
## Alternative, using OpenStreetMap
This uses the [osmnx ](https://github.com/gboeing/osmnx ) python package to get OpenStreetMap data. You will need python and osmnx to run `get_test_polygons.py` .
2018-09-29 13:29:57 -04:00
To help test the Colouring London application, `get_test_polygons.py` will attempt to save a
small (1.5km²) extract from OpenStreetMap to a format suitable for loading to the database.
In this case, run:
```bash
# download test data
2020-06-18 05:32:35 -04:00
python get_test_polygons.py
2018-09-29 13:29:57 -04:00
# load all building outlines
2020-06-18 05:32:35 -04:00
./load_geometries.sh ./
2018-09-29 13:29:57 -04:00
# index geometries (should be faster after loading)
2020-06-18 05:32:35 -04:00
psql < .. / migrations / 002 . index-geometries . up . sql
2018-09-29 13:29:57 -04:00
# create a building record per outline
2020-06-18 05:32:35 -04:00
./create_building_records.sh
2018-09-29 13:29:57 -04:00
# index building records
2020-06-18 05:32:35 -04:00
psql < .. / migrations / 003 . index-buildings . up . sql
2018-09-29 13:29:57 -04:00
```
2020-06-18 05:32:35 -04:00
## Finally
Run the remaining migrations in `../migrations` to create the rest of the database structure.