Created
January 14, 2013 18:22
-
-
Save ajashton/4532112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function way_to_wkt(way_id int) | |
returns text | |
language plpgsql as | |
$$ | |
declare | |
nodes bigint[] := (select nodes from planet_osm_ways where id = way_id); | |
i smallint := 0; | |
coords text[]; | |
begin | |
if array_length(nodes, 1) = 0 then | |
return null; | |
end if; | |
while i < array_length(nodes, 1) loop | |
coords := array_append(coords, (select lat || ' ' || lon from planet_osm_nodes where id = nodes[i])); | |
i = i + 1; | |
end loop; | |
return 'MULTILINESTRING((' || array_to_string(coords, ', ') || '))'; | |
end; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment