[GRASS-user] Profile from a random path

Dylan Beaudette dylan.beaudette at gmail.com
Wed Dec 20 18:31:14 EST 2006


Thanks for the tips Michael. I hadn't tried this out yet (i usually stick with 
the d.mon interface to GRASS... :) ).

PS: posted a cleaner version of this here:
http://casoilresource.lawr.ucdavis.edu/drupal/node/375

Cheers,

Dylan

On Wednesday 20 December 2006 14:50, Michael Barton wrote:
> If you look at profile.tcl (in $GISBASE/etc/gm/) you can see how I used
> r.profile to create the TclTk profiler. It draws continuous profiles of
> multisegment transects.
>
> BTW, the profiler is broken at the moment because r.univar has been renamed
> to r.univar2 when it was enhanced.
>
> If you rename r.univar2 back to r.univar it will be OK.
>
> Michael
>
> On 12/20/06 4:14 PM, "Dylan Beaudette" <dylan.beaudette at gmail.com> wrote:
> > On Wednesday 20 December 2006 05:55, Hamish wrote:
> >> Luca Casagrande wrote:
> >>> I have got a path described by a vector line; i'd like to create the
> >>> elevation profile for that line without using GUI.
> >>
> >> maybe something with v.drape?
> >>
> >>> 3) Use r.profile as described in the example 3 to create the profile
> >>> for the ascii file.
> >>>
> >>> I focused on the 3rd problem:
> >>>
> >>> In the r.profile man page, in the example 3 section, it says this:
> >>> [..]
> >>> Example 3
> >>> Extract a profile with coordinates provided from standard input or an
> >>> external file: First create a points file with d.where
> >>> d.where > saved.points
> >>> Then pipe the points file into r.profile
> >>> cat saved.points | r.profile input=elev.rast output=profile.pts
> >>> [..]
> >>>
> >>> The matter is that if i run the command line shown in the example, it
> >>> doesn't work, cause it need -i flag or to set the profile= one with
> >>> the coordinates of points.
> >>>
> >>> Any idea?
> >>
> >> The error message is wrong. That's been broken for ~6 years..
> >> thanks for pointing it out. fixed in CVS + 6.2 branch.
> >>
> >>
> >> Added this example to the help page:
> >>
> >> #spearfish
> >> r.profile elevation.dem res=1000 << EOF
> >>   591243,4926344
> >>   592509,4922156
> >>   594100,4920793
> >>   599910,4919365
> >>   602929,4919235
> >>   604844,4918391
> >>   606468,4917190
> >>   607766,4915664
> >> EOF
> >>
> >>
> >> this now works too:
> >>  d.where | r.profile elevation.dem
> >>
> >>
> >> Hamish
> >
> > Luca:
> >
> > did this solve your problem? I recall doing something like this a while
> > back using v.drape.
> >
> > If you like R here is the code I usually use for plotting distance along
> > line (3d) vs elevation: (grass and R code):
> >
> > # make new line
> > v.digit -n map=t bgcmd="d.rast elev_meters"
> > # convert to points
> > v.to.points in=t out=tp type=line dmax=50 -i -v -t
> > # set resolution
> > g.region -pa res=4
> > # make 3d
> > v.drape in=tp out=tpz type=point rast=elev_4m method=cubic
> > # export
> > v.out.ascii tpz > tpz.txt
> >
> > # start R
> > R
> >
> > # read in the data, note that there is no header, and the columns are
> > pipe delimited
> > x <- read.table('tpz.txt', header=F, sep="|",
> > col.names=c('easting','northing','elev','f'))
> >
> > # use attach for simple access to columns
> > attach(x)
> >
> > # compute the length minus 1 ; i.e. the number of points - 1
> > # use for the lagged distance calculation
> > s <- length(easting) - 1
> >
> > # calculate the lagged distance along each component of the 3D vector
> > dx <- easting[2:(s+1)] - easting[1:s]
> > dy <- northing[2:(s+1)] - northing[1:s]
> > dz <- elev[2:(s+1)] - elev[1:s]
> >
> > # combine the vector components
> > # 3D distance formula
> > c <- sqrt( dx^2 + dy^2 + dz^2)
> >
> > # create the cumulative distance along line:
> > dist <- cumsum(c[1:s])
> >
> > # plot the results
> > plot(dist, elev[1:s], type='l', xlab='Distance from start (m)',
> > ylab='Elevation (m)', main='Profile')
> >
> > # cleanup
> > detach(x)
> >
> >
> > see attached figure for output
> >
> > I can put this up on the R-wiki for later use. it might be fun to code
> > this into something, so that there are fewer steps involved...
> >
> > Cheers,
> >
> > Dylan
>
> __________________________________________
> Michael Barton, Professor of Anthropology
> School of Human Evolution & Social Change
> Center for Social Dynamics and Complexity
> Arizona State University
>
> phone: 480-965-6213
> fax: 480-965-7671
> www: http://www.public.asu.edu/~cmbarton

-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341




More information about the grass-user mailing list