Open Infrastructure Map, a view of infrastructure data in OpenStreetMap
Calculate angles for switchgear
Russ Garrettbc2aeec10481
diff --git a/schema/functions.sql b/schema/functions.sqlindex d4cf6dd..2d77e7f 100644--- a/schema/functions.sql+++ b/schema/functions.sql@@ -264,3 +264,27 @@ EXCEPTIONRETURN st_buffer(g1, 10);end$$;++-- Given a point on a power line (say the location of a switch),+-- return the angle of the line at that point.+-- Returns null if a line cannot be found.+CREATE OR REPLACE FUNCTION power_line_angle(point GEOMETRY)+ RETURNS DOUBLE PRECISION+ LANGUAGE plpgsql+ IMMUTABLE STRICT+ PARALLEL SAFE+ AS $$+DECLARE+ angle DOUBLE PRECISION;+BEGIN+ SELECT ST_Azimuth(ST_LineInterpolatePoints(line.geometry, 0.2, false),+ ST_LineInterpolatePoints(line.geometry, 0.8, false)+ ) / (2 * PI()) * 360 INTO angle+ FROM (+ SELECT ST_Intersection(l.geometry, ST_Buffer(point, 5)) AS geometry+ FROM osm_power_line l+ WHERE ST_Intersects(ST_Buffer(point, 1), l.geometry)+ ) AS line+ WHERE ST_GeometryType(line.geometry) = 'ST_LineString' LIMIT 1;+ RETURN angle;+END $$;\ No newline at end of filediff --git a/tegola/layers.yml b/tegola/layers.ymlindex d89ba27..7da2fc9 100644--- a/tegola/layers.yml+++ b/tegola/layers.yml@@ -297,6 +297,8 @@ layers:sql: convert_voltage(tags -> 'voltage') / 1000- name: ratingsql: tags -> 'rating'+ - name: angle+ sql: round(power_line_angle(geometry))::integer % 180id_field: osm_idfrom: osm_power_switchgearwhere: type = 'compensator' AND geometry && !BBOX!@@ -315,6 +317,8 @@ layers:sql: tags -> 'gas_insulated'- name: cablessql: tags -> 'cables'+ - name: angle+ sql: round(power_line_angle(geometry))::integer % 180id_field: osm_idfrom: osm_power_switchgearwhere: type = 'switch' AND geometry && !BBOX!