[postgis-users] Elevation Profiles

ANDREW WOOLEY awooley at mountainland.org
Wed Dec 1 14:47:47 PST 2004


Thanks for that.  It sounds like it will work very well, but I keep
getting an error: 

WARNING: plpgsql: ERROR during compile of linestring_samples near line
ERROR:  syntax error at or near "[".

I don't know where the error occurs, but the query won't run. Any

Here is my modified query (sorry about the formatting):

select s.linestring_samples[1] as position, z.gridcode 
(select * from linestring_samples((select the_geom from rt1101751073
where gid=1),0)) as s, mtntrails_elevation as z where
geometry(s.linestring_samples[2]) && z.the_geom 
and intersects(geometry(s.linestring_samples[2]),z.the_geom) 
order by linestring_samples[1] asc;

Thanks again for sending this.


>>> carl.anderson at vadose.org 11/29/2004 11:13:32 PM >>>
On 11/24/2004 01:46:31 PM, ANDREW WOOLEY wrote:
> Folks,
> I have been working on this idea for some time and have been trying 

> to
> implement elevation profiles and have yet to get it working like I
> want.
>  I am hoping that someone has some good ideas for me.
> Here is my problem. I have a series of lines in a table.  I also
> a
> table with elevations as polygons. I overlay them using this query:
> select e.gridcode as elevation from mtntrails_elevation as e, route 

> as
> r where e.the_geom && r.the_geom;
> (route has one trail with 3 or 4 segments.)(mtntrails_elevation has 

> ~7
> million rows.)

When working with path profiles I usually plot them up on a cartesian 

grid as a path distance vs an elevation.  The problem becomes how to  
degenerate a path into a set of evenly spaced samples.

the two attached plpgsql functions can help.  an example of a SQL  
statement calling the scripts is included.  Use them as you will.

the outer function linestring_samples "walks" a specific path using the
inner function to compute the position of each sample.  In the  
path_profile script only one path can be sampled at a time or you'll  
get an error.  you may also need to wrap a setsrid around.  ie setsrid


the result is an array, but you could script the samples into a  
destination table as well.  the sampling function needs to return a  
setof two values. one for sampling one for ordering.

Re: speed of relational operators on polygons.  The speed of  
computation of the relation is related to the number of vertices in the
polygon.  Consider breaking the polygons into smaller "gridded"  


More information about the postgis-users mailing list