obs-portal/tile-generator
2021-11-22 09:51:18 +01:00
..
layers tile-generator: also emit oneway roads 2021-11-22 09:50:33 +01:00
.gitignore Start working on PostGIS supported tile generation 2021-11-22 09:50:33 +01:00
LICENSE.md Start working on PostGIS supported tile generation 2021-11-22 09:50:33 +01:00
Makefile Move API to python. 2021-11-22 09:50:33 +01:00
openmaptiles.yaml Start working on PostGIS supported tile generation 2021-11-22 09:50:33 +01:00
README.md feat: publish tiles from API directly 2021-11-22 09:51:18 +01:00

Tile Generation

To display the collected data we generate vector tiles which can be rendered by different map renderers, such as maplibre-gl-js or QGIS.

The whole process requires a dockerized setup. Of course you can try to install and run the tools without docker, but that is probably going to be very complicated, and we're not documenting it here.

Data sources

There are two main sources of data. Both feed into a PostgreSQL database into separate tables, such that they can be joined for processing.

Application data

The API imports tracks separately and stores the imported data into the overtaking_event table. This is already part of the application and does not need configuration, apart from specifying the correct postgres.url in the API config.

Importing OpenStreetMap data

This is the road information imported from OpenStreetMap itself. Download the area(s) you would like to import from GeoFabrik. Then import the files like this:

osm2pgsql --create --hstore --style api/roads_import.lua -O flex \
  -H localhost -d obs -U obs -W \
  path/to/downloaded/myarea-latest.osm.pbf 

You might need to adjust the host, database and username (-H, -d, -U) to your setup, and also provide the correct password when queried. This process should take a few seconds to minutes, depending on the area size. You can run the process multiple times, with the same or different area files, to import or update the data. You can also truncate the road table before importing if you want to remove outdated road information.

Configure

Edit the file tile-generator/.env and adjust the following variables:

  • PGDATABASE, PGUSER, ... if you have different PostgreSQL credentials
  • BBOX, a bounding box for the area you want to generate (keep it small). Use this tool to draw an area on a map.

Generate SQL functions

The OpenMapTiles project is used to generate the vector tiles. For this, a lot of logic is generated and imported into the PostgreSQL database in the form of user functions. To generate and import these, run::

cd tile-generator/
make clean
make
make import-sql

Generate .mbtiles file

This file contains all the vector tiles for the selected area and zoom levels, and different layers of information (according to the layer descriptions in tile-generator/layers/ and tile-generator/openmaptiles.yaml). It is generated like this:

make generate-tiles-pg

Publish vector tiles

The API is capable of serving the generated mbtiles file in XYZ scheme with PBF format. Set the config variable TILES_FILE to point to your generated file.

The API might be inefficient at publishing the tiles. You might want to try a proper tileserver with caching and all if you run into trouble with its capabilities.

The URL for the tiles is:

http://api.example.com/tiles/{z}/{x}/{y}.pbf

The API generates this URL into the /config.json as obsMapSource if it is configured to serve tiles and the frontend.