From 171a4e2ce8540ff2c77959e1e5aa56152d5508e5 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sun, 11 Aug 2024 01:32:59 +0200 Subject: [PATCH] first draft at a simple indoor import --- docker-compose.local.yml | 85 ++++------------------------------------ docker-compose.yml | 12 ++---- map/osm2pgsql/style.lua | 85 ++++++++++++---------------------------- 3 files changed, 36 insertions(+), 146 deletions(-) diff --git a/docker-compose.local.yml b/docker-compose.local.yml index c70cf9e60..e7c89dc17 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -1,72 +1,4 @@ services: - webclient: - restart: unless-stopped - build: ./webclient - ports: - - "3000:3000" - environment: - TZ: Europe/Berlin - NUXT_PUBLIC_MAPS_URL: https://nav.tum.de/maps - NUXT_PUBLIC_CDN_URL: http://data:3002 - NUXT_PUBLIC_API_URL: http://api:3003 - depends_on: - data: - condition: service_healthy - api: - condition: service_healthy - # cdn - data: - restart: unless-stopped - build: ./data - environment: - TZ: Europe/Berlin - ports: - - "3002:3002" - api: - restart: unless-stopped - build: - args: - PROFILE: debug - context: server - dockerfile: Dockerfile - command: /bin/navigatum-server - ports: - - "3003:3003" - user: 1000:3000 - environment: - TZ: Europe/Berlin - LOG_LEVEL: ${LOG_LEVEL-debug} - MIELI_URL: http://meilisearch:7700 - MEILI_MASTER_KEY: ${MEILI_MASTER_KEY} - TILESERVER_URL: https://nav.tum.de/maps - CDN_URL: http://data:3002/cdn - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_DB: ${POSTGRES_DB} - POSTGRES_URL: db:5432 - CONNECTUM_OAUTH_CLIENT_ID: ${CONNECTUM_OAUTH_CLIENT_ID} - CONNECTUM_OAUTH_CLIENT_SECRET: ${CONNECTUM_OAUTH_CLIENT_SECRET} - GITHUB_TOKEN: ${GITHUB_TOKEN} - JWT_KEY: ${JWT_KEY} - depends_on: - meilisearch: - condition: service_started - db: - condition: service_healthy - meilisearch: - image: getmeili/meilisearch:v1.9.0 - restart: unless-stopped - ports: - - "7700:7700" - environment: - TZ: Europe/Berlin - MEILI_MASTER_KEY: ${MEILI_MASTER_KEY} - MEILI_ENV: development - healthcheck: - test: curl --fail http://localhost:7700/health || exit 1 - retries: 2 - interval: 600s - start_period: 10s db: image: postgis/postgis:16-3.4 restart: unless-stopped @@ -84,17 +16,14 @@ services: test: [ "CMD", "pg_isready", "-U", "${POSTGRES_USER}" ] retries: 5 interval: 10s - start_period: 10s + start_interval: 20s + start_period: 20s osm-download-data: image: alpine:latest - command: - - wget - - -O - - data.pbf - - https://download.geofabrik.de/europe/germany/bayern/oberbayern-latest.osm.pbf - working_dir: /data + command: sh -c "apk add wget && wget --continue --timestamping https://download.geofabrik.de/europe/germany/bayern/oberbayern-latest.osm.pbf" + working_dir: /map/data volumes: - - ./map/data/:/data/:rw + - ./map/data/:/map/data/:rw osm2pgsql-init: image: iboates/osm2pgsql:latest environment: @@ -105,7 +34,7 @@ services: - --create - --slim - --cache - - "200" + - "7000" - --database - ${POSTGRES_DB} - --user @@ -114,7 +43,7 @@ services: - db - --port - "5432" - - /map/data/data.pbf + - /map/data/oberbayern-latest.osm.pbf - --output=flex - --style - /map/osm2pgsql/style.lua diff --git a/docker-compose.yml b/docker-compose.yml index dc22f53d1..737dcc0bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -191,14 +191,10 @@ services: start_period: 10s osm-download-data: image: alpine:latest - command: - - wget - - -O - - data.pbf - - https://download.geofabrik.de/europe/germany-latest.osm.pbf - working_dir: /data + command: apk --update add wget && wget --continue --timestamping https://download.geofabrik.de/europe/germany-latest.osm.pbf + working_dir: /map/data volumes: - - ./map/data/:/data/:rw + - ./map/data/:/map/data/:rw osm2pgsql-init: image: iboates/osm2pgsql:latest networks: @@ -220,7 +216,7 @@ services: - db - --port - "5432" - - /map/data/data.pbf + - /map/data/germany-latest.osm.pbf - --output=flex - --style - /map/osm2pgsql/style.lua diff --git a/map/osm2pgsql/style.lua b/map/osm2pgsql/style.lua index 4654b6399..5b36e3795 100644 --- a/map/osm2pgsql/style.lua +++ b/map/osm2pgsql/style.lua @@ -1,60 +1,26 @@ --- This config exmple file is released into the Public Domain. - --- This is a very simple Lua config for the Flex output not intended for --- real-world use. Use it do understand the basic principles of the --- configuration. After reading and understanding this, have a look at --- "geometries.lua". +-- See https://github.com/osm2pgsql-dev/osm2pgsql/tree/master/flex-config +-- for configuration examples -- For debugging -- inspect = require('inspect') +-- print(inspect(object)) --- The global variable "osm2pgsql" is used to talk to the main osm2pgsql code. --- You can, for instance, get the version of osm2pgsql: print('osm2pgsql version: ' .. osm2pgsql.version) --- A place to store the SQL tables we will define shortly. local tables = {} --- Create a new table called "pois" with the given columns. When running in --- "create" mode, this will do the `CREATE TABLE`, when running in "append" --- mode, this will only declare the table for use. --- --- This is a "node table", it can only contain data derived from nodes and will --- contain a "node_id" column (SQL type INT8) as first column. When running in --- "append" mode, osm2pgsql will automatically update this table using the node --- ids. -tables.pois = osm2pgsql.define_node_table('pois', { - { column = 'tags', type = 'jsonb' }, - { column = 'geom', type = 'point', not_null = true }, -- will be something like `GEOMETRY(Point, 4326)` in SQL -}) --- A special table for restaurants to demonstrate that we can have any tables --- with any columns we want. -tables.restaurants = osm2pgsql.define_node_table('restaurants', { - { column = 'name', type = 'text' }, - { column = 'cuisine', type = 'text' }, - -- We declare all geometry columns as "NOT NULL". If osm2pgsql encounters - -- an invalid geometry (for whatever reason) it will generate a null - -- geometry which will not be written to the database if "not_null" is - -- set. The result is that broken geometries will just be silently - -- ignored. +tables.indoor_nodes = osm2pgsql.define_node_table('indoor_nodes', { + { column = 'tags', type = 'jsonb' }, { column = 'geom', type = 'point', not_null = true }, }) --- This is a "way table", it can only contain data derived from ways and will --- contain a "way_id" column. When running in "append" mode, osm2pgsql will --- automatically update this table using the way ids. -tables.ways = osm2pgsql.define_way_table('ways', { +tables.indoor_ways = osm2pgsql.define_way_table('indoor_ways', { { column = 'tags', type = 'jsonb' }, { column = 'geom', type = 'linestring', not_null = true }, }) --- This is an "area table", it can contain data derived from ways or relations --- and will contain an "area_id" column. Way ids will be stored "as is" in the --- "area_id" column, for relations the negative id will be stored. When --- running in "append" mode, osm2pgsql will automatically update this table --- using the way/relation ids. -tables.polygons = osm2pgsql.define_area_table('polygons', { +tables.indoor_polygons = osm2pgsql.define_area_table('indoor_polygons', { { column = 'type', type = 'text' }, { column = 'tags', type = 'jsonb' }, -- The type of the `geom` column is `geometry`, because we need to store @@ -91,23 +57,14 @@ function osm2pgsql.process_node(object) return end - if object.tags.amenity == 'restaurant' then - -- Add a row to the SQL table. The keys in the parameter table - -- correspond to the table columns, if one is missing the column will - -- be NULL. Id and geometry columns will be filled automatically. - tables.restaurants:insert({ - name = object.tags.name, - cuisine = object.tags.cuisine, - geom = object:as_point() - }) - else - tables.pois:insert({ - -- We know `tags` is of type `jsonb` so this will do the - -- right thing. - tags = object.tags, - geom = object:as_point() - }) + if object.tags.indoor == nil and object.tags.level == nil then + return end + + tables.indoor_nodes:insert({ + tags = object.tags, + geom = object:as_point() + }) end -- Called for every way in the input. The `object` argument contains the same @@ -121,16 +78,20 @@ function osm2pgsql.process_way(object) return end + if object.tags.indoor == nil and object.tags.level == nil then + return + end + -- Very simple check to decide whether a way is a polygon or not, in a -- real stylesheet we'd have to also look at the tags... if object.is_closed then - tables.polygons:insert({ + tables.indoor_polygons:insert({ type = object.type, tags = object.tags, geom = object:as_polygon() }) else - tables.ways:insert({ + tables.indoor_ways:insert({ tags = object.tags, geom = object:as_linestring() }) @@ -148,10 +109,14 @@ function osm2pgsql.process_relation(object) return end + if object.tags.indoor == nil and object.tags.level == nil then + return + end + -- Store multipolygons and boundaries as polygons if object.tags.type == 'multipolygon' or object.tags.type == 'boundary' then - tables.polygons:insert({ + tables.indoor_polygons:insert({ type = object.type, tags = object.tags, geom = object:as_multipolygon()