Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

Add function to select pipeline type

Russ Garrett1cfb4a176d40
diff --git a/schema/functions.sql b/schema/functions.sql
index 750387f..87bf249 100644
--- a/schema/functions.sql
+++ b/schema/functions.sql
@@ -293,4 +293,26 @@ BEGIN
) AS line
WHERE ST_GeometryType(line.geometry) = 'ST_LineString' LIMIT 1;
RETURN angle;
-END $$;
\ No newline at end of file
+END $$;
+
+CREATE OR REPLACE FUNCTION pipeline_type(substance TEXT)
+ RETURNS TEXT
+ LANGUAGE sql
+ IMMUTABLE STRICT
+ PARALLEL SAFE
+ AS $$
+
+SELECT CASE
+ WHEN substance IN (
+ 'natural_gas', 'gas', 'oil', 'fuel', 'cng', 'lpg', 'ngl', 'lng',
+ 'y-grade', 'hydrocarbons', 'hydrogen', 'carbon_dioxide', 'carbon_monoxide',
+ 'ethylene', 'propylene', 'chemicals', 'chemical', 'ammonia',
+ 'methane', 'ethane', 'nitrogen', 'isobutane', 'butane',
+ 'propane', 'condensate', 'butadiene', 'naphtha'
+ ) THEN 'petroleum'
+ WHEN substance IN ('water', 'hot_water', 'rainwater', 'wastewater', 'sewage',
+ 'waterwaste', 'steam') THEN 'water'
+ ELSE 'other'
+END;
+
+$$;
\ No newline at end of file
diff --git a/tegola/layers.yml b/tegola/layers.yml
index 1f615bd..330536f 100644
--- a/tegola/layers.yml
+++ b/tegola/layers.yml
@@ -452,13 +452,7 @@ layers:
sql: tags -> 'material'
from: osm_pipeline
where: >
- COALESCE(substance, type) IN (
- 'natural_gas', 'gas', 'oil', 'fuel', 'cng', 'lpg', 'ngl', 'lng',
- 'y-grade', 'hydrocarbons', 'hydrogen', 'carbon_dioxide', 'carbon_monoxide',
- 'ethylene', 'propylene', 'chemicals', 'chemical', 'ammonia',
- 'methane', 'ethane', 'nitrogen', 'isobutane', 'butane',
- 'propane', 'condensate', 'butadiene', 'naphtha'
- ) AND construction = ''
+ pipeline_type(COALESCE(substance, type)) = 'petroleum' AND construction = ''
AND ((tags->'usage' IS NOT NULL AND tags->'usage' = 'transmission')
OR !ZOOM! > 7
)
@@ -485,13 +479,7 @@ layers:
sql: tags -> 'material'
from: osm_pipeline
where: >
- COALESCE(substance, type) NOT IN (
- 'natural_gas', 'gas', 'oil', 'fuel', 'cng', 'lpg', 'ngl', 'lng',
- 'y-grade', 'hydrocarbons', 'hydrogen', 'carbon_dioxide', 'carbon_monoxide',
- 'ethylene', 'propylene', 'chemicals', 'chemical', 'ammonia',
- 'methane', 'ethane', 'nitrogen', 'isobutane', 'butane',
- 'propane', 'condensate', 'butadiene', 'naphtha'
- ) AND construction = ''
+ pipeline_type(COALESCE(substance, type)) = 'other' AND construction = ''
AND ((tags->'usage' IS NOT NULL AND tags->'usage' = 'transmission')
OR !ZOOM! > 7
)
@@ -541,10 +529,9 @@ layers:
sql: tags -> 'start_date'
from: osm_pipeline
where: >
- COALESCE(substance, type) IN (
- 'water', 'hot_water', 'rainwater', 'wastewater', 'sewage',
- 'waterwaste', 'steam'
- ) AND geometry && !BBOX! AND ST_Length(geometry) > !PIXEL_WIDTH! / 4
+ pipeline_type(COALESCE(substance, type)) = 'water'
+ AND geometry && !BBOX!
+ AND ST_Length(geometry) > !PIXEL_WIDTH! / 4
- name: pressurised_waterway
map: