This is an API for the Link react app. Most of the calls use SQLAlchemy models and schemas to access a Postgres DB, but the /analyze endpoint uses the LTS Connectivity tool (linked below).
It uses:
- FastAPI
- Postgres (with PostGIS and PGrouting)
- DVRPC's LTS/sidewalk connectivity tool.
- ogr2ogr
sudo apt install postgresql-16-pgroutingwhich will install PostgreSQL, PostGIS, and PGrouting. If you have postgres already, you need to install the other two individually. Setup any roles you want.
You also need ogr2ogr. For Linux:
sudo apt install gdal-binpython -m venv veThen activate the environment.
. ve/bin/activatepip install wheel && pip install -r requirements_base.txtCreate a .env file at the root of the project. An example is below, which contains a URI to a database.
DB_URI=postgresql://user:pw@host:port/db
You may also alter the path by including a URL_ROOT variable (that starts with a /). If not included, it will not be used.
DB_URI=postgresql://user:pw@host:port/db
URL_ROOT=/api
You'll need to add a configuration file for pg-data-etl at the root of this project. It must be named 'database_connections.cfg', and should be formatted like this:
[localhost]
host = host
un = postgres
pw = password
port = port
db_name = db_name
Don't edit the localhost in brackets, as the script searches for it (see analyze endpoint) but change all the other variables.
If you're putting this onto a remote server, you need to pipe a copy of the database from a machine that's behind the DVRPC firewall, as all of the data import and setup scripts can only be run behind the firewall, pulling from DVRPC's GIS postgres server. The most recent backup can be found in 'G:\Shared drives\Bike LTS and Connectivity Analysis Webmap\Rethinking Connectivity\DB_Backups'.
Pipe a copy in with:
psql -U your_username -h your_host -p your_port -d target_database < backup.sql Start the development server with
cd app
uvicorn main:app --reloadSee what API calls are supported by visiting localhost:8000/docs. (Note that if you set URL_ROOT, this would be different, e.g. a URL_ROOT of /api would result in localhost:8000/api/docs).
The project uses the GPL 3.0 license.