Prepare Docker
docker compose --profile '*' buildThis view is configured to be a true alternative to overpass, in the sense that there is no filtering on the elements included in the DB. They are all included in the DB with all their tags, whereas osm2pgsql is usually configured not to include tags or elements that are useless for generating tiles.
Warning : this wiew will not work on an existing osm2pgsql database (see below). It is specific for a database created with the lua script above and the -s (--slim) option.
Create you database with osm2pgsql, using the script geometries-alone.lua available in this folder.
Example command:
osm2pgsql -U user -d database -c -s --flat-nodes FILE --middle-with-nodes -x -O flex -S geometries-alone.lua extract.osm.pbf
Explanation of the command:
-c -s -x: create an updatable table including metadata--flat-nodes FILE --middle-with-nodes: use the fileFILEto store nodes (to reduce the size of the DB), but nodes with tags are also stored in the database (so that filtering by tag will be possible on nodes)-O flex -S geometries-alone.lua: use flex output mode with specific.luafile
One finished, add index for tags:
CREATE INDEX nodes_tags_idx ON planet_osm_nodes USING GIN (tags);
CREATE INDEX ways_tags_idx ON planet_osm_ways USING GIN (tags);
CREATE INDEX rels_tags_idx ON planet_osm_rels USING GIN (tags);
Use osm2pgsql-replication to update the DB.
Sizing
- 57GB for France (29GB for middle tables (metadata+tags) + 2GB for tag index + 26GB for output tables (geometries))
If your database was created "outside" docker, you will have to modify docker-compose.yaml to:
- delete services
osm2pgsqlandpostgress - in service api : delete reference
depends on: -postgresand set yourDATABASE_URL: postgres://user:pw@host:5432/database
Explanation of the .lua script and principle of the DB structure:
-soption createsmiddletables which include all raw OSM elements (planet_osm_nodes,planet_osm_ways,planet_osm_rels) with all their tags. This view uses these 3 tables to get tags (no need to duplicate them inoutputtables), but we need to manually index them at the beginning.-xoption add columns for metadata in these tables, and tableplanet_osm_usersfor usernames.- so only the geometries are missing. The
.luascript of theflex outputcreates 3 additionnaloutputtables:nodes_geom,ways_geomandrels_geomwith the id and the geometry.- I had to use tables by element type instead of geometry type (as usual for osm2pgsql) since the negative id used for relations in area type table is problematic for the join with the
planet_osm_relstable which uses normal positive id (join is slow since indexing is not working).
- I had to use tables by element type instead of geometry type (as usual for osm2pgsql) since the negative id used for relations in area type table is problematic for the join with the
- For a list of expected areas (as usual in osm2pgsql), the lua script creates polygon-like geometries (instead of line-like) and adds the area size in a 3rd column (it will be usefull to get areas).
not written yet
not written yet
Run the HTTP server
docker compose up