Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* select osm_id,highway, st_length(way) as len, max_degree(way), st_numpoints(way) from
- planet_osm_line where highway is not null and oneway <> 'no' and junction is null
- and st_isring(way) and st_length(way) < 1000 and
- highway in ('primary','secondary','tertiary','trunk','residential','unclassified');
- */
- DROP FUNCTION IF EXISTS max_degree(way geometry);
- CREATE OR REPLACE FUNCTION max_degree(way geometry)
- RETURNS numeric
- AS
- $$
- DECLARE
- i numeric;
- result float;
- curAngle float;
- angle float;
- azimuth1 float;
- azimuth2 float;
- intNumPoints numeric;
- point1 geometry;
- point2 geometry;
- point3 geometry;
- BEGIN
- IF geometrytype(way) <> 'LINESTRING' THEN
- RETURN 9999;
- END IF;
- result := 0;
- intNumPoints := ST_NumPoints(way);
- FOR i in 2..intNumPoints LOOP
- point1 := ST_PointN(way, i-1);
- point2 := ST_PointN(way, i);
- IF i + 1 <= intNumPoints THEN
- point3 := ST_PointN(way, i+1);
- ELSE
- point3 := ST_PointN(way, 1);
- END IF;
- azimuth1 := degrees(ST_Azimuth(point1, point2));
- azimuth2 := degrees(ST_Azimuth(point2, point3));
- angle := abs(round((azimuth1 - azimuth2)::decimal, 2));
- IF angle < (360 - angle) THEN
- curAngle := angle;
- ELSE
- curAngle := 360 - angle;
- END IF;
- IF curAngle > result THEN
- result := curAngle;
- END IF;
- END LOOP;
- RETURN result;
- END
- $$ LANGUAGE 'plpgsql' IMMUTABLE;
- /* RAISE NOTICE 'Index %, Angle %, A1 %, A2 %', i, curAngle, azimuth1, azimuth2; */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement