[GRASS-user] how to change all cats in a vector line

Moritz Lennert mlennert at club.worldonline.be
Mon Dec 1 08:31:51 PST 2014


On 30/11/14 06:28, Michael Barton wrote:
>
> ____________________
> C. Michael Barton
> Director, Center for Social Dynamics & Complexity
> Professor of Anthropology, School of Human Evolution & Social Change
> Head, Graduate Faculty in Complex Adaptive Systems Science
> Arizona State University
>
> voice: 480-965-6262 (SHESC), 480-965-8130/727-9746 (CSDC)
> fax: 480-965-7671 (SHESC),  480-727-0709 (CSDC)
> www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu
>
>
>
>
> Thanks César,
>
> This is pretty much what I’m doing. However, it is not that simple, it
> turns out.
>
> First, for a stream profile, you want to isolate a single watercourse.
> r.stream.extract creates a stream network. Getting stream order does not
> help with profiling, however.
>
> I looked at r.stream.distance. But this calculates distance from each
> stream junction. I want it for the entire course of the selected
> stream—from headwaters to outlet. That is the only way to graph a stream
> profile for the entire stream.
>
> Once I have a set of points with the distance from the beginning or the
> end of the line stored as an attribute for each point, the rest is easy.
> It is getting to this step that is hard.
>
> If a line is composed of multiple segments—as is the case for any line
> created with r.stream.extract or r.watershed, and also with r.drain
> surprisingly—there is nothing that will ignore all of these segments and
> just give me the distance along the line from one end to the other. This
> is the case with v.to.points

As MarkusN said: you have to use v.build.polylines with cats=first, but 
then it is easy to get total length with v.to.db or v.to.points if that 
is what you need (or many other options (get end node coordinates and 
use v.distance 'to_along' or MarkusM's suggestion: v.net.distance from 
start to end node along the stream).

Here's an example in the NC dataset, using r.stream.order to approximate 
the main stream:

g.region n=227440 s=221640 w=630220 e=637220 res=10
r.watershed --overwrite elevation=elevation at PERMANENT threshold=10000 
accumulation=accum drainage=direction stream=streams
r.stream.order --overwrite stream_rast=streams at user1 
direction=direction at user1 elevation=elevation at PERMANENT 
accumulation=accum at user1 stream_vect=streams horton=horton
v.extract --overwrite input=streams at user1 where=horton=3 output=main_stream
v.build.polylines --overwrite input=main_stream at user1 
output=main_stream_poly cats=first

then: v.to.db  (result=11312.5) or

v.to.points input=main_stream at user1 output=main_stream_points dmax=1

db.select sql="select round(max(along)) from main_stream_points_2"
round(max(along))
11312.5


Moritz


More information about the grass-user mailing list