Created
July 14, 2020 08:34
-
-
Save bruceh48/52f1f2a33e4ca068569bd5183ebde3b1 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 a line using 2 points | |
-- Place 100 evenly spaced points along line | |
-- intersect each point with a single band raster called elevation | |
-- return results as X, Y, Z, index_of_point, distance_from_start_point (in metres) | |
with | |
makeline(geom) as ( | |
select ST_SetSRID( | |
ST_MakeLine(ST_MakePoint(115.750,-32.051), | |
ST_MakePoint(116.170,-31.958)), 4326) as geom | |
), | |
linelen(l) as (select ST_Length(geom::geography)::float / 100.0 from makeline), | |
points(geom) as (SELECT | |
ST_Line_Interpolate_Point( | |
ml.geom,generate_series(0, 100):: double precision / 100.0 | |
) as geom from makeline ml | |
) | |
SELECT ST_X(geom) as x, ST_Y(geom) as y, | |
ROUND(ST_Value(r.rast, 1, p.geom)::NUMERIC, 3) AS val, | |
row_number() OVER () as i, | |
(row_number() OVER ()) * l as dist | |
FROM elevation r, points p, linelen | |
WHERE ST_Intersects(r.rast, p.geom) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment