Instantly share code, notes, and snippets.

Embed
What would you like to do?
--PostgreSQL
BEGIN;
ALTER TABLE osm_network_graph
ADD COLUMN geom geometry(LINESTRING,4326),
ADD COLUMN length_m double precision;
CREATE TEMP TABLE split_geom AS
SELECT osm.split_way_id,
ST_MakeLine(ln.geom,rn.geom) AS geom,
st_length(st_transform(ST_MakeLine(ln.geom,rn.geom),32618)) AS length_m
FROM osm_network_graph osm
JOIN nodes ln ON osm.start_node = ln.id
JOIN nodes rn ON osm.end_node = rn.id;
UPDATE osm_network_graph osm
SET geom = s.geom,
length_m = s.length_m
FROM split_geom s
WHERE osm.split_way_id = s.split_way_id;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment