Skip to content

Instantly share code, notes, and snippets.

@dfwarden
Created January 10, 2016 15:36
Show Gist options
  • Save dfwarden/b68df8f8722fdbf1c443 to your computer and use it in GitHub Desktop.
Save dfwarden/b68df8f8722fdbf1c443 to your computer and use it in GitHub Desktop.
PostGIS New LinestringZ from Linestring w/Raster Sample
/*
We have to build a new replacement LinestringZ rather than use
ST_SetPoint() since UPDATE can only change a single row, and
the column type in question is LinestringZ, not PointZ.
*/
select st_astext(st_makeline(
array(select st_makepoint(st_x(point), st_y(point), z) as new_point
from
(select st_pointn(wkb_geometry, point_idx) as point,
st_value(rast, st_pointn(wkb_geometry, point_idx)) as z
from vermont.roads, vermont.elevation_test,
(select ogc_fid, generate_series(1, st_numpoints(wkb_geometry)) as point_idx
from vermont.roads
where ogc_fid=92884) as point_idxs
where roads.ogc_fid = point_idxs.ogc_fid
) as points
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment