CRESHMap is a web application written in python using the flask framework. It uses a postgis database for storing the data. The data map layer is generated using mapserver and displayed using OpenLayers. Static pages are produced from markdown input files kept in the CRESHMap/pages/ directory.
Install all the requirements into a python virtual environment.
Install postgis, create a database (let's call it cresh
) with support for spatial data and create a read-write (cresh
) and a read-only user (creshro
). The actual user names and database names can be different.
The application uses an environment variable to figure out how to connect to the database:
export DATABASE_URL='postgresql://cresh:PASSWORD@pow/cresh
There are multiple programs involved loading data:
creshmap-load-geographies
creates all tables (after dropping them if they already exist). Geographies are loaded following the plan in data.yaml. Compound geographies are aggregated from the smallest ones.creshmap-define-variables
reads the variable definition file variables.yaml and updates the database with any changes. Variable IDs should not change.creshmap-load-variables
reads in data from either and excel or csv file. The mapping of column names to data base names is defined in the config file.
The mapserver is controlled via a mapfile. This file is generated using the genmap.py script together with a configuration file. The script also configures the database connection for mapserver. Use the read-only user.
export DATABASE_URL='postgresql://creshro:PASSWORD@pow/cresh?options=-c%20search_path=cresh,public,topology'
creshmap-genmap creshmap.cfg -o /path/to/webdir
Note, that the read-ony user needs access to all database schemas to work correctly. The script will put the mapfile and template into the /path/to/webdir
directory. Attributes that can be displayed by the map are configured in the configuration file.
The following environment variables are needed for the app to run correctly:
Variable name | Value |
---|---|
DATABASE_URL |
See Database Setup |
MAPSERVER_URL |
URL to mapserver. Must end in a ? |
SECRET_KEY |
Long string of random characters |
EMAIL_FROM_ADDR |
The From field in the email that sends the download link |
EMAIL_SMTP_SERV |
Email SMPT server (set to localhost ) |
PUBLIC_DOMAIN |
Public facing domain name used in the download email |
- This application follows the flask application factory pattern.
- The web app uses postcodes.io for geolocating postcodes.
- local authority areas - Scotland
- UK Parliamentary Constituencies - Scotland