[postgis-users] plpgsql function question, equivalent sql statement?
Nathaniel Hunter Clay
clay.nathaniel at gmail.com
Sun Dec 9 07:19:20 PST 2012
Hi all,
I am wondering if there is a better way do accomplish the following. To
create an array of values between two points from a raster. This is what
I have come up with.
{{{
CREATE or REPLACE Function sampledArray(rast raster, bandnum integer,
p1 geometry,p2 geometry, sampledistance double precision) RETURNS double
precision[] AS
$$
DECLARE
line geometry;
distance double precision;
samples integer;
sample double precision;
valuesarray double precision[];
BEGIN
line := ST_MakeLine($3,$4);
distance := ST_Distance($3,$4);
samples := floor(distance/sampledistance);
sample := sampledistance/distance;
for i in 0..samples by 1
LOOP
valuesarray[i] :=
ST_Value($1,$2,ST_Line_Interpolate_Point(line,sample*i));
END LOOP;
return valuesarray;
END;
$$
LANGUAGE plpgsql;
}}}
More information about the postgis-users
mailing list