Skip to content

Commit

Permalink
Flex indoor style (#1435)
Browse files Browse the repository at this point in the history
* migrated osm2pgsql to the flex export format

* first draft at a simple indoor import

* made martin expose the relevant tables in the catalog

* apk usage

* removed odd `sh -c`
  • Loading branch information
CommanderStorm authored Aug 12, 2024
1 parent 542afd0 commit bad2001
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 34 deletions.
30 changes: 15 additions & 15 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,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: apk --update --quiet 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:
Expand All @@ -114,14 +111,13 @@ services:
- db
- --port
- "5432"
- data.pbf
- --hstore
- --hstore-add-index
- --hstore-column
- raw
working_dir: /data
- /map/data/oberbayern-latest.osm.pbf
- --output=flex
- --style
- /map/osm2pgsql/style.lua
volumes:
- ./map/data/:/data/:ro
- ./map/data/:/map/data/:ro
- ./map/osm2pgsql/:/map/osm2pgsql/:ro
depends_on:
osm-download-data:
condition: service_completed_successfully
Expand All @@ -148,6 +144,8 @@ services:
condition: service_completed_successfully
db:
condition: service_healthy
volumes:
- ./map/osm2pgsql/:/map/osm2pgsql/:ro
osm2pgsql-replication:
image: iboates/osm2pgsql:latest
environment:
Expand All @@ -167,6 +165,8 @@ services:
depends_on:
osm2pgsql-replication-init:
condition: service_completed_successfully
volumes:
- ./map/osm2pgsql/:/map/osm2pgsql/:ro
martin-init-config:
image: alpine:latest
command:
Expand Down
32 changes: 16 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,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-latest.osm.pbf
working_dir: /data
command: apk --update --quiet 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:
Expand All @@ -211,7 +208,7 @@ services:
- --create
- --slim
- --cache
- "4096" # cache size in MB, maybe underspeced
- "4096" # cache size in MB, maybe too low for optimum
- --database
- ${POSTGRES_DB}
- --user
Expand All @@ -220,14 +217,13 @@ services:
- db
- --port
- "5432"
- data.pbf
- --hstore
- --hstore-add-index
- --hstore-column
- raw
working_dir: /data
- /map/data/germany-latest.osm.pbf
- --output=flex
- --style
- /map/osm2pgsql/style.lua
volumes:
- ./map/data/:/data/:ro
- ./map/data/:/map/data/:ro
- ./map/osm2pgsql/:/map/osm2pgsql/:ro
depends_on:
osm-download-data:
condition: service_completed_successfully
Expand Down Expand Up @@ -256,6 +252,8 @@ services:
condition: service_completed_successfully
db:
condition: service_healthy
volumes:
- ./map/osm2pgsql/:/map/osm2pgsql/:ro
osm2pgsql-replication:
image: iboates/osm2pgsql:latest
networks:
Expand All @@ -277,6 +275,8 @@ services:
depends_on:
osm2pgsql-replication-init:
condition: service_completed_successfully
volumes:
- ./map/osm2pgsql/:/map/osm2pgsql/:ro
martin-init-config:
image: alpine:latest
command:
Expand Down
30 changes: 29 additions & 1 deletion map/martin/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fonts:
postgres:
connection_string: $DATABASE_URL
auto_publish: false
tables: {}
tables:
# addrfeat:
# schema: tiger
# table: addrfeat
Expand Down Expand Up @@ -231,6 +231,34 @@ postgres:
# vtdst00: varchar
# zcta5ce: varchar
# zcta5ce00: varchar
indoor_nodes:
schema: public
table: indoor_nodes
srid: 3857
geometry_column: geom
geometry_type: POINT
properties:
node_id: int8
tags: jsonb
indoor_polygons:
schema: public
table: indoor_polygons
srid: 3857
geometry_column: geom
geometry_type: GEOMETRY
properties:
area_id: int8
tags: jsonb
type: text
indoor_ways:
schema: public
table: indoor_ways
srid: 3857
geometry_column: geom
geometry_type: LINESTRING
properties:
tags: jsonb
way_id: int8
# place:
# schema: tiger
# table: place
Expand Down
125 changes: 125 additions & 0 deletions map/osm2pgsql/style.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
-- See https://github.com/osm2pgsql-dev/osm2pgsql/tree/master/flex-config
-- for configuration examples

-- For debugging
-- inspect = require('inspect')
-- print(inspect(object))

print('osm2pgsql version: ' .. osm2pgsql.version)

local tables = {}


tables.indoor_nodes = osm2pgsql.define_node_table('indoor_nodes', {
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'point', not_null = true },
})

tables.indoor_ways = osm2pgsql.define_way_table('indoor_ways', {
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'linestring', not_null = true },
})

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
-- polygons AND multipolygons
{ column = 'geom', type = 'geometry', not_null = true },
})

-- Debug output: Show definition of tables
for name, dtable in pairs(tables) do
print("\ntable '" .. name .. "':")
print(" name='" .. dtable:name() .. "'")
-- print(" columns=" .. inspect(dtable:columns()))
end

-- Helper function to remove some of the tags we usually are not interested in.
-- Returns true if there are no tags left.
local function clean_tags(tags)
tags.odbl = nil
tags.created_by = nil
tags.source = nil
tags['source:ref'] = nil

return next(tags) == nil
end

-- Called for every node in the input. The `object` argument contains all the
-- attributes of the node like `id`, `version`, etc. as well as all tags as a
-- Lua table (`object.tags`).
function osm2pgsql.process_node(object)
-- Uncomment next line to look at the object data:
-- print(inspect(object))

if clean_tags(object.tags) then
return
end

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
-- information as with nodes and additionally a boolean `is_closed` flag and
-- the list of node IDs referenced by the way (`object.nodes`).
function osm2pgsql.process_way(object)
-- Uncomment next line to look at the object data:
-- print(inspect(object))

if clean_tags(object.tags) then
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.indoor_polygons:insert({
type = object.type,
tags = object.tags,
geom = object:as_polygon()
})
else
tables.indoor_ways:insert({
tags = object.tags,
geom = object:as_linestring()
})
end
end

-- Called for every relation in the input. The `object` argument contains the
-- same information as with nodes and additionally an array of members
-- (`object.members`).
function osm2pgsql.process_relation(object)
-- Uncomment next line to look at the object data:
-- print(inspect(object))

if clean_tags(object.tags) then
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.indoor_polygons:insert({
type = object.type,
tags = object.tags,
geom = object:as_multipolygon()
})
end
end
2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FROM rust:1.80-alpine AS compiler
# - musl-dev is needed for musl to compile the binary
# - mold is used to link faster
# - I somehow could not get openssl to cooperate => we are contibuing with libpq-dev
RUN apk add -q --update-cache --no-cache musl-dev libpq-dev mold
RUN apk --update add -q --update-cache --no-cache musl-dev libpq-dev mold

WORKDIR /compiler
ENV USER=root
Expand Down
3 changes: 2 additions & 1 deletion webclient/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ RUN pnpm run build


FROM node:21-alpine3.19 AS production-stage
RUN apk update --no-progress --quiet && apk add curl --no-progress --quiet
RUN apk update --no-progress --quiet && \
apk add --no-cache --no-progress --quiet curl

COPY --from=build-stage /app/.output /app/.output
COPY --from=build-stage /app/node_modules /app/node_modules
Expand Down

0 comments on commit bad2001

Please sign in to comment.