Skip to content

Instantly share code, notes, and snippets.

@ajashton
Created January 14, 2013 18:22
Show Gist options
  • Save ajashton/4532112 to your computer and use it in GitHub Desktop.
Save ajashton/4532112 to your computer and use it in GitHub Desktop.
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