[GRASS-user] how to change all cats in a vector line
Michael Barton
Michael.Barton at asu.edu
Mon Dec 1 11:05:09 PST 2014
This is exactly what I’m doing. The problems come when I want to sample the vector stream at regular intervals. r.to.vect splits the resulting vector line into multiple segments with different cats for some reason.
Michael
____________________
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
On Dec 1, 2014, at 11:51 AM, Johannes Radinger <johannesradinger at gmail.com<mailto:johannesradinger at gmail.com>> wrote:
Hi Michael,
I have not read the entire thread, but maybe follwowing might work
if you want to extract this upstream-downstream watercourse in raster format:
1) Use r.cost with your outlet as starting point and your cell resolution as
cost surface. So the output is a pseudo-elevation
map with increasing values in upstream direction
2) use r.drain to extract the main course in downstream direction based on a
defined upstream end and the pseudo-elevation map created by r.cost.
3) Than you can use r.to.vect to convert your raster cells to vectors and
extract your distance per point (cummulative cost) and your elevation.
Maybe this might help in on or the other way.
best,
Johannes
On Mon, Dec 1, 2014 at 7:21 PM, Michael Barton <Michael.Barton at asu.edu<mailto:Michael.Barton at asu.edu>> wrote:
v.build.polylines is indeed part of what is needed. But it is not enough to be able to use v.to.points in the data I have—and this is not a weirdly meandering stream, just a Mediterranean barranco.
A major part of the problem is in the raster to vector conversion. I’ve been using r.to.vect. But it breaks the resulting line into multiple segments and assigns different cat numbers to the segments. If the segments all connect cleanly, v.build.polylines may combine the segments. But I’ve tried using cat=first and it continues to assign multiple cats to the segments. To get a single line, what I have to do currently is:
v.clean
v.build.polylines with cats=no
v.category with option=del ## may not be necessary but I’ve had enough inconsistent results to want to make sure on this
v.category with option=add cat=1 step=0 ## this gets me a vector with cat=1 for all parts.
repeat the above a 2nd time
This gives a sufficiently clean single-object line with a single cat number that I can run v.to.points on.
Maybe r.stream.order does a cleaner job in raster to vector conversion. It’s worth a try. Unfortunately, I can’t use the stream order info to extract a stream since I want the stream from its headwaters (stream order = 1) to its outlet (stream order > 1).
Ideally, there would be a module where I could enter the coordinates of the upstream end of a stream, it would extract the entire watercourse as a single object to its downstream end, edge of map, or a defined outlet stop point. Then I could run v.to.points and v.what.rast to get profile data. OR in a a stream profile module, it would run these for me. I could do it in Python if I could extract a clean vector (one object, one cat, no loops or self-crossing) of a single stream from a stream network created with r.watershed or r.stream.extract. AFAICT, there is nothing available in GRASS that can do this. Kind of surprising.
Michael
____________________
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<http://csdc.asu.edu/>
On Dec 1, 2014, at 9:31 AM, Moritz Lennert <mlennert at club.worldonline.be<mailto:mlennert at club.worldonline.be>> wrote:
> 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<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
_______________________________________________
grass-user mailing list
grass-user at lists.osgeo.org<mailto:grass-user at lists.osgeo.org>
http://lists.osgeo.org/mailman/listinfo/grass-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20141201/da501eb8/attachment-0001.html>
More information about the grass-user
mailing list