Open Infrastructure Map, a view of infrastructure data in OpenStreetMap
More updates
Russ Garrettd83062971162
diff --git a/config.toml b/config.tomlindex cfd641f..b3ca954 100644--- a/config.toml+++ b/config.toml@@ -109,9 +109,8 @@ user = "osm"[[providers.layers]]name = "power_line"-dont_simplify = truegeometry_type = "LineString"-sql = "SELECT osm_id AS gid, ST_AsBinary(ST_Simplify(geometry, ZRes(!ZOOM!) / 5, true)) AS geom, tunnel, location, first_semi(frequency) AS frequency, tags -> 'name' AS name, line, tags -> 'ref' AS ref, char_length(tags -> 'ref') AS ref_len, convert_voltage(voltage) / 1000 AS voltage, convert_voltage(nth_semi(voltage, 2)) / 1000 AS voltage_2, convert_voltage(nth_semi(voltage, 3)) / 1000 AS voltage_3, tags -> 'operator' AS operator FROM osm_power_line WHERE geometry && !BBOX! AND ST_Length(geometry) > ZRes(!ZOOM!) AND (line NOT IN ('bay', 'busbar') OR !ZOOM! > 10) ORDER BY convert_voltage(voltage) ASC NULLS FIRST"+sql = "SELECT gid, ST_AsBinary(geometry) AS geom, tunnel, location, first_semi(frequency) AS frequency, tags -> 'name' AS name, line, tags -> 'ref' AS ref, char_length(tags -> 'ref') AS ref_len, convert_voltage(voltage) / 1000 AS voltage, convert_voltage(nth_semi(voltage, 2)) / 1000 AS voltage_2, convert_voltage(nth_semi(voltage, 3)) / 1000 AS voltage_3, tags -> 'operator' AS operator FROM power_lines(!ZOOM!) WHERE geometry && !BBOX! ORDER BY convert_voltage(voltage) ASC NULLS FIRST"[[providers.layers]]name = "power_tower"diff --git a/mapping/funcs.py b/mapping/funcs.pyindex 259f337..58bc1c1 100644--- a/mapping/funcs.py+++ b/mapping/funcs.py@@ -14,6 +14,7 @@ type_col = {"name": "type", "type": "mapping_value"}tables = {}+generalized_tables = {}def table(name, mappings, geom_type, columns=None, tags_from_member=False, **kwargs):@@ -59,3 +60,13 @@ def relation_tables(name, mappings, relation_types, relation_columns=None):relation_types=relation_types,tags_from_member=True,)+++def generalized_table(name, source, tolerance, sql_filter=None):+ gt = {+ "source": source,+ "tolerance": tolerance+ }+ if sql_filter:+ gt['sql_filter'] = sql_filter+ generalized_tables[name] = gtdiff --git a/mapping/main.py b/mapping/main.pyindex 5643b74..a6da2f4 100644--- a/mapping/main.py+++ b/mapping/main.py@@ -1,5 +1,5 @@import json-from funcs import tables+from funcs import tables, generalized_tablesimport power # noqaimport telecoms # noqa@@ -63,7 +63,8 @@ data = {"wheelchair",],},- "tables": tables+ "tables": tables,+ "generalized_tables": generalized_tables}print(json.dumps(data, indent=3))diff --git a/mapping/petroleum.py b/mapping/petroleum.pyindex bb30b62..93cd748 100644--- a/mapping/petroleum.py+++ b/mapping/petroleum.py@@ -9,9 +9,13 @@ table(table("pipeline",- {"man_made": ["pipeline"]},+ {"man_made": ["pipeline"], "construction:man_made": ["pipeline"]},"linestring",- columns=[str_col("substance"), str_col("type")],+ columns=[+ str_col("substance"),+ str_col("type"),+ str_col("construction:man_made", "construction"),+ ],)table(diff --git a/mapping/power.py b/mapping/power.pyindex 325f990..9e99fd8 100644--- a/mapping/power.py+++ b/mapping/power.py@@ -1,4 +1,12 @@-from funcs import table, relation_tables, str_col, int_col, bool_col, type_col+from funcs import (+ table,+ relation_tables,+ generalized_table,+ str_col,+ int_col,+ bool_col,+ type_col,+)table(@@ -20,6 +28,22 @@ table(],)+generalized_table(+ "power_line_gen_100",+ "power_line",+ 100,+ "coalesce(convert_voltage(voltage), 0) > 100000 AND ST_length(geometry) > 200 "+ "AND line NOT IN ('bay', 'busbar')",+)++generalized_table(+ "power_line_gen_500",+ "power_line",+ 500,+ "coalesce(convert_voltage(voltage), 0) > 100000 AND ST_length(geometry) > 600 "+ "AND line NOT IN ('bay', 'busbar')",+)+table("power_tower",{diff --git a/mapping/telecoms.py b/mapping/telecoms.pyindex 77c6a35..f2ef298 100644--- a/mapping/telecoms.py+++ b/mapping/telecoms.py@@ -1,7 +1,14 @@from funcs import table, type_col-table("telecom_cable", {"communication": ["line", "cable"]}, "linestring")+table(+ "telecom_cable",+ {+ "communication": ["line", "cable"],+ "construction:communication": ["line", "cable"],+ },+ "linestring",+)table("telecom_building",@@ -23,5 +30,8 @@ table()table(- "mast", {"man_made": ["mast", "tower", "communications_tower"]}, "point", columns=[type_col]+ "mast",+ {"man_made": ["mast", "tower", "communications_tower"]},+ "point",+ columns=[type_col],)diff --git a/views.sql b/views.sqlindex bccbc7e..2d0d58a 100644--- a/views.sql+++ b/views.sql@@ -44,3 +44,49 @@ CREATE OR REPLACE VIEW power_plant ASUNIONSELECT osm_id, geometry, name, output, source, tagsFROM power_plant_relation;++++/* Dispatch power line query to the appropriate generalised table based on zoom. */+CREATE OR REPLACE FUNCTION power_lines(zoom INT) RETURNS+ TABLE (gid bigint,+ geometry geometry(LineString, 3857),+ type character varying,+ location character varying,+ line character varying,+ voltage character varying,+ frequency character varying,+ circuits integer,+ construction character varying,+ tunnel boolean,+ tags hstore)+ LANGUAGE plpgsql+AS $$+DECLARE+BEGIN+ IF zoom < 5 THEN+ RETURN QUERY SELECT osm_id, osm_power_line_gen_500.geometry,+ osm_power_line_gen_500.type, osm_power_line_gen_500.location,+ osm_power_line_gen_500.line, osm_power_line_gen_500.voltage,+ osm_power_line_gen_500.frequency, osm_power_line_gen_500.circuits,+ osm_power_line_gen_500.construction, osm_power_line_gen_500.tunnel,+ osm_power_line_gen_500.tags+ FROM osm_power_line_gen_500;+ ELSIF zoom < 8 THEN+ RETURN QUERY SELECT osm_id, osm_power_line_gen_100.geometry,+ osm_power_line_gen_100.type, osm_power_line_gen_100.location,+ osm_power_line_gen_100.line, osm_power_line_gen_100.voltage,+ osm_power_line_gen_100.frequency, osm_power_line_gen_100.circuits,+ osm_power_line_gen_100.construction, osm_power_line_gen_100.tunnel,+ osm_power_line_gen_100.tags+ FROM osm_power_line_gen_100;+ ELSE+ RETURN QUERY SELECT osm_id, osm_power_line.geometry,+ osm_power_line.type, osm_power_line.location, osm_power_line.line,+ osm_power_line.voltage, osm_power_line.frequency,+ osm_power_line.circuits, osm_power_line.construction, osm_power_line.tunnel,+ osm_power_line.tags+ FROM osm_power_line;+ END IF;+END+$$;