Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

New mapping config

Russ Garrett6201c309c57e
diff --git a/.github/workflows/imposm.yml b/.github/workflows/imposm.yml
index a36ed96..c4a8869 100644
--- a/.github/workflows/imposm.yml
+++ b/.github/workflows/imposm.yml
@@ -5,7 +5,7 @@ on:
branches:
- main
paths:
- - 'mapping/**'
+ - 'imposm/**'
- '.github/workflows/imposm.yml'
jobs:
@@ -34,8 +34,8 @@ jobs:
id: docker_build
uses: docker/build-push-action@v4
with:
- context: ./mapping
- file: ./mapping/Dockerfile
+ context: ./imposm
+ file: ./imposm/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
diff --git a/README.md b/README.md
index fecd6e9..4d9efda 100644
--- a/README.md
+++ b/README.md
@@ -12,9 +12,11 @@ The [web backend](web-backend) serves the [stats pages](https://openinframap.org
## OSM Import & Mapping
The mapping file controls how the OSM subset is imported with
-[imposm3](https://imposm.org/docs/imposm3/latest/). It's generated from the files in [mapping](mapping)
+[imposm3](https://imposm.org/docs/imposm3/latest/). It's generated from the files in [imposm](imposm)
by calling `python3 ./mapping/main.py > ./mapping.json`.
+The production server uses the docker container built in this directory.
+
Changes to the mapping require a re-import of the OpenStreetMap database, which takes
a while and is currently done very irregularly.
@@ -35,7 +37,7 @@ Imposm runs as a service with the `-expiretiles-dir` option:
The low-zoom layers are seeded daily with:
- /usr/local/bin/tegola cache seed --bounds="-180,-85.0511,180,85.0511" --min-zoom 2 --max-zoom 6 --overwrite --config /home/osm/styles/tegola/config.toml
+ /usr/local/bin/tegola cache seed --bounds="-180,-85.0511,180,85.0511" --max-zoom 6 --overwrite --config /home/osm/styles/tegola/config.toml
Invalidated tiles are removed every minute:
diff --git a/mapping/Dockerfile b/imposm/Dockerfile
similarity index 62%
rename from mapping/Dockerfile
rename to imposm/Dockerfile
index 32a77ac..a809834 100644
--- a/mapping/Dockerfile
+++ b/imposm/Dockerfile
@@ -1,7 +1,7 @@
-FROM python:3.11-slim AS build
+FROM python:3.12-slim AS build
# First, build the mapping.json file
COPY . .
RUN python main.py > ./mapping.json
FROM ghcr.io/openinframap/imposm3:latest
-COPY --from=build mapping.json /mapping.json
+COPY --from=build mapping.json /mapping.json
\ No newline at end of file
diff --git a/mapping/__init__.py b/imposm/__init__.py
similarity index 100%
rename from mapping/__init__.py
rename to imposm/__init__.py
diff --git a/mapping/funcs.py b/imposm/funcs.py
similarity index 66%
rename from mapping/funcs.py
rename to imposm/funcs.py
index 58bc1c1..b936e23 100644
--- a/mapping/funcs.py
+++ b/imposm/funcs.py
@@ -1,3 +1,9 @@
+from typing import Any, Optional
+
+
+Mapping = dict[str, list[str]]
+
+
def col_generator(typ):
def col_inner(column, name=None):
if name is None:
@@ -17,8 +23,15 @@ tables = {}
generalized_tables = {}
-def table(name, mappings, geom_type, columns=None, tags_from_member=False, **kwargs):
- assert type(mappings) == dict
+def table(
+ name,
+ mappings: Mapping,
+ geom_type,
+ columns: Optional[list] = None,
+ tags_from_member: bool = False,
+ **kwargs,
+) -> None:
+ assert isinstance(mappings, dict)
fields = [{"name": "osm_id", "type": "id"}]
if geom_type != "relation":
@@ -26,15 +39,15 @@ def table(name, mappings, geom_type, columns=None, tags_from_member=False, **kwa
fields += columns or []
- tags_field = {"name": "tags", "type": "hstore_tags"}
+ tags_field: dict[str, Any] = {"name": "tags", "type": "hstore_tags"}
if tags_from_member:
tags_field["from_member"] = True
fields.append(tags_field)
- data = {"fields": fields}
+ data: dict[str, Any] = {"fields": fields}
- if type(geom_type) == list:
+ if isinstance(geom_type, list):
data["type_mappings"] = {}
for typ in geom_type:
data["type_mappings"][typ] = mappings
@@ -47,7 +60,9 @@ def table(name, mappings, geom_type, columns=None, tags_from_member=False, **kwa
tables[name] = data
-def relation_tables(name, mappings, relation_types, relation_columns=None):
+def relation_tables(
+ name: str, mappings: Mapping, relation_types, relation_columns=None
+) -> None:
table(name, mappings, "relation", relation_columns, relation_types=relation_types)
table(
f"{name}_member",
@@ -62,11 +77,8 @@ def relation_tables(name, mappings, relation_types, relation_columns=None):
)
-def generalized_table(name, source, tolerance, sql_filter=None):
- gt = {
- "source": source,
- "tolerance": tolerance
- }
+def generalized_table(name: str, source: str, tolerance, sql_filter=None) -> None:
+ gt = {"source": source, "tolerance": tolerance}
if sql_filter:
- gt['sql_filter'] = sql_filter
+ gt["sql_filter"] = sql_filter
generalized_tables[name] = gt
diff --git a/mapping/main.py b/imposm/main.py
similarity index 92%
rename from mapping/main.py
rename to imposm/main.py
index 5db4157..b0d8f38 100644
--- a/mapping/main.py
+++ b/imposm/main.py
@@ -4,6 +4,7 @@ from funcs import tables, generalized_tables
import power # noqa
import telecoms # noqa
import petroleum # noqa
+import water # noqa
data = {
@@ -24,7 +25,6 @@ data = {
"addr:*",
"natural",
"surface",
- "waterway",
"oneway",
"service",
"wall",
@@ -44,12 +44,10 @@ data = {
"shop",
"lit",
"import",
- "note",
"leaf_type",
"crossing",
"lacounty:*",
"osak:*",
- "water",
"yh:*",
"tourism",
"entrance",
@@ -63,7 +61,7 @@ data = {
],
},
"tables": tables,
- "generalized_tables": generalized_tables
+ "generalized_tables": generalized_tables,
}
print(json.dumps(data, indent=3))
diff --git a/mapping/petroleum.py b/imposm/petroleum.py
similarity index 75%
rename from mapping/petroleum.py
rename to imposm/petroleum.py
index 93cd748..a1c4b9b 100644
--- a/mapping/petroleum.py
+++ b/imposm/petroleum.py
@@ -25,22 +25,26 @@ table(
"oil",
"fracking",
"oil_storage",
+ "petroleum_terminal",
"hydrocarbons",
"oil sands",
"oil_sands",
"gas",
+ "gas_storage",
"natural_gas",
"wellsite",
"well_cluster",
- ]
+ "refinery",
+ ],
+ "pipeline": ["substation"],
},
"polygon",
- columns=[type_col],
+ columns=[type_col, str_col("name")],
)
table(
"pipeline_feature",
- {"pipeline": ["valve", "substation", "flare"]},
+ {"pipeline": ["valve", "flare"]},
"point",
columns=[type_col],
)
@@ -51,3 +55,9 @@ table(
"point",
columns=[type_col],
)
+
+table(
+ "offshore_platform",
+ {"man_made": ["offshore_platform"]},
+ ["points", "polygons"],
+)
diff --git a/mapping/power.py b/imposm/power.py
similarity index 75%
rename from mapping/power.py
rename to imposm/power.py
index 40f0f7c..1db38e1 100644
--- a/mapping/power.py
+++ b/imposm/power.py
@@ -14,6 +14,7 @@ table(
{
"power": ["line", "minor_line", "cable", "minor_cable"],
"construction:power": ["line", "minor_line", "cable", "minor_cable"],
+ "disused:power": ["line", "minor_line", "cable", "minor_cable"],
},
"linestring",
columns=[
@@ -24,10 +25,27 @@ table(
str_col("frequency"),
int_col("circuits"),
str_col("construction:power", "construction"),
+ str_col("disused:power", "disused"),
bool_col("tunnel"),
],
)
+relation_tables(
+ "power_circuit_relation",
+ {
+ "route": ["power"],
+ "power": ["circuit"],
+ "construction:power": ["circuit"],
+ },
+ relation_types=["route", "power"],
+ relation_columns=[
+ str_col("name"),
+ str_col("voltage"),
+ str_col("frequency"),
+ str_col("construction:power", "construction"),
+ ],
+)
+
generalized_table(
"power_line_gen_100",
"power_line",
@@ -49,20 +67,22 @@ table(
{
"power": ["tower", "pole", "portal"],
"construction:power": ["tower", "pole", "portal"],
+ "disused:power": ["tower", "pole", "portal"],
},
["points", "linestrings"],
columns=[
type_col,
bool_col("location:transition", "transition"),
str_col("construction:power", "construction"),
+ str_col("disused:power", "disused"),
],
)
table(
"power_substation",
{
- "power": ["substation", "sub_station"],
- "construction:power": ["substation", "sub_station"],
+ "power": ["substation"],
+ "construction:power": ["substation"],
},
["points", "polygons"],
columns=[
@@ -78,8 +98,8 @@ table(
relation_tables(
"power_substation_relation",
{
- "power": ["substation", "sub_station"],
- "construction:power": ["substation", "sub_station"],
+ "power": ["substation"],
+ "construction:power": ["substation"],
},
relation_types=["site"],
relation_columns=[
@@ -116,7 +136,7 @@ table(
columns=[
str_col("plant:output:electricity", "output"),
str_col("plant:source", "source"),
- str_col("construction_power", "construction"),
+ str_col("construction:power", "construction"),
],
)
@@ -127,7 +147,7 @@ relation_tables(
relation_columns=[
str_col("plant:output:electricity", "output"),
str_col("plant:source", "source"),
- str_col("construction_power", "construction"),
+ str_col("construction:power", "construction"),
],
)
@@ -139,7 +159,7 @@ table(
str_col("generator:source", "source"),
str_col("generator:method", "method"),
str_col("generator:type", "type"),
- str_col("generator:output", "output"), # TODO: should be generator:output:electricity
- str_col("construction_power", "construction"), # TODO: should be construction:power
+ str_col("generator:output:electricity", "output"),
+ str_col("construction:power", "construction"),
],
)
diff --git a/mapping/telecoms.py b/imposm/telecoms.py
similarity index 56%
rename from mapping/telecoms.py
rename to imposm/telecoms.py
index f2ef298..ccc6fe1 100644
--- a/mapping/telecoms.py
+++ b/imposm/telecoms.py
@@ -1,4 +1,4 @@
-from funcs import table, type_col
+from funcs import table, type_col, str_col
table(
@@ -31,7 +31,33 @@ table(
table(
"mast",
- {"man_made": ["mast", "tower", "communications_tower"]},
- "point",
+ {
+ "man_made": ["mast", "tower", "communications_tower"],
+ "tower:type": ["communication"],
+ },
+ ["points", "polygons"],
columns=[type_col],
)
+
+table(
+ "telecom_antenna",
+ {
+ "man_made": ["antenna"],
+ },
+ ["points", "polygons"],
+ columns=[type_col],
+)
+
+table(
+ "utility_pole",
+ {"man_made": ["utility_pole"]},
+ "point",
+ columns=[str_col("utility")],
+)
+
+table(
+ "street_cabinet",
+ {"man_made": ["street_cabinet"]},
+ ["points", "polygons"],
+ columns=[str_col("utility")],
+)
diff --git a/imposm/water.py b/imposm/water.py
new file mode 100644
index 0000000..af5c098
--- /dev/null
+++ b/imposm/water.py
@@ -0,0 +1,40 @@
+from funcs import table, type_col, str_col
+
+table(
+ "water_treatment_plant",
+ {"man_made": ["water_works", "desalination_plant"]},
+ "polygon",
+ columns=[type_col, str_col("name")],
+)
+
+table(
+ "wastewater_plant",
+ {"man_made": ["wastewater_plant"]},
+ "polygon",
+ columns=[type_col, str_col("name")],
+)
+
+table(
+ "pumping_station",
+ {"man_made": ["pumping_station"]},
+ "polygon",
+ columns=[str_col("name"), str_col("pumping_station"), str_col("substance")],
+)
+
+table("water_tower", {"man_made": ["water_tower"]}, ["points", "polygons"])
+
+table("water_well", {"man_made": ["water_well"]}, ["points", "polygons"])
+
+table(
+ "pressurised_waterway",
+ {"waterway": ["pressurised"]},
+ "linestring",
+ columns=[str_col("name")],
+)
+
+table(
+ "water_reservoir",
+ {"man_made": ["reservoir_covered"], "water": ["reservoir"]},
+ "polygon",
+ columns=[type_col, str_col("name")],
+)