Open Infrastructure Map, a view of infrastructure data in OpenStreetMap
Tweak power_line_angle
Russ Garrett5a9fa30a8aa1
diff --git a/schema/functions.sql b/schema/functions.sqlindex 2d77e7f..7b4fa4f 100644--- a/schema/functions.sql+++ b/schema/functions.sql@@ -277,13 +277,16 @@ CREATE OR REPLACE FUNCTION power_line_angle(point GEOMETRY)DECLAREangle DOUBLE PRECISION;BEGIN+ -- Interpolate two points onto the line at 20% and 80% of the length, and calculate the angle between them.SELECT ST_Azimuth(ST_LineInterpolatePoints(line.geometry, 0.2, false),ST_LineInterpolatePoints(line.geometry, 0.8, false)) / (2 * PI()) * 360 INTO angleFROM (+ -- Fetch all lines within a 1m radius of the point. Clip them to a 5m buffer.SELECT ST_Intersection(l.geometry, ST_Buffer(point, 5)) AS geometryFROM osm_power_line lWHERE ST_Intersects(ST_Buffer(point, 1), l.geometry)+ ORDER BY line = 'busbar' ASC -- Prefer non-busbar lines) AS lineWHERE ST_GeometryType(line.geometry) = 'ST_LineString' LIMIT 1;RETURN angle;