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


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 and v.fixed.segmentpoints. v.profile might do the job but it is not available for GRASS 7.

Michael

On Nov 29, 2014, at 10:02 PM, grass-user-request@lists.osgeo.org wrote:

From: César Augusto Ramírez Franco <caesarivs@gmail.com>

To: GRASS User List <grass-user@lists.osgeo.org>

Date: November 29, 2014 at 9:13:43 PM MST

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

Hello Michael
You could use r.stream.order after r.stream.extract to get your stream network ordered, and then, after running r.thin on the ordered stream network, convert it to vector using r.to.vect with the -v flag, that way, each order is a cat, you can them use v.to.points or the add-on suggested below to get topologically-correct points along the stream network, you could also use r.stream.distance and upload distance and elevation to each point using v.what.rast
I usually run R from within GRASS and use the spgrass6 library to read the vector map and analyze the data there
Regards
César.

El sáb, 29 de noviembre de 2014 06:29 p.m., Helmut Kudrnovsky <hellik@web.de> escribió:

Michael Barton wrote

Hi Markus,

What I’m trying to do is start with a raster stream map from r.drain and
convert it to a sequence of vector points, where each point has
information as to its position along the stream. I then use the points for
sampling a stream profile and related information. Oddly enough, with all
of the very useful stream analysis modules, there is nothing I could find
to generate the data for a stream profile (distance from outlet or from
headwaters vs. elevation).

v.to.points does a nice job of creating a sequence of evenly spaced points
with information about their location along a line (the “along” field).
BUT, if the line is composed of multiple segments or even if it has an
irregularity in it, the “along” values start over again from 0. The only
way I can use it is if I have a very clean and continuous vector line with
only a single cat.

This has proven surprisingly difficult to obtain reliably from my raster
stream map. So far, the only way has been to do a two sequences of v.clean
(with thresholds 1.5 X the raster resolution) and v.build.polylines. If
you have any better suggestion, I’d love to hear it.

Thanks again for the polylines idea. That was a big help.

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

Michael Barton wrote:

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.

You could use v.net + v.net.path to extract a single line from a given
headwaters to a given outlet. r.stream.distance should then use the
entire course of the selected stream. With a little loop this can be
done for all streams of interest.

Markus M

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 and v.fixed.segmentpoints. v.profile might do the
job but it is not available for GRASS 7.

Michael

On Nov 29, 2014, at 10:02 PM, grass-user-request@lists.osgeo.org wrote:

From: César Augusto Ramírez Franco <caesarivs@gmail.com>
To: GRASS User List <grass-user@lists.osgeo.org>
Date: November 29, 2014 at 9:13:43 PM MST
Subject: Re: [GRASS-user] how to change all cats in a vector line

Hello Michael
You could use r.stream.order after r.stream.extract to get your stream
network ordered, and then, after running r.thin on the ordered stream
network, convert it to vector using r.to.vect with the -v flag, that way,
each order is a cat, you can them use v.to.points or the add-on suggested
below to get topologically-correct points along the stream network, you
could also use r.stream.distance and upload distance and elevation to each
point using v.what.rast
I usually run R from within GRASS and use the spgrass6 library to read the
vector map and analyze the data there
Regards
César.

El sáb, 29 de noviembre de 2014 06:29 p.m., Helmut Kudrnovsky
<hellik@web.de> escribió:

Michael Barton wrote
> Hi Markus,
>
> What I'm trying to do is start with a raster stream map from r.drain and
> convert it to a sequence of vector points, where each point has
> information as to its position along the stream. I then use the points
> for
> sampling a stream profile and related information. Oddly enough, with
> all
> of the very useful stream analysis modules, there is nothing I could
> find
> to generate the data for a stream profile (distance from outlet or from
> headwaters vs. elevation).
>
> v.to.points does a nice job of creating a sequence of evenly spaced
> points
> with information about their location along a line (the "along" field).
> BUT, if the line is composed of multiple segments or even if it has an
> irregularity in it, the "along" values start over again from 0. The only
> way I can use it is if I have a very clean and continuous vector line
> with
> only a single cat.
>
> This has proven surprisingly difficult to obtain reliably from my raster
> stream map. So far, the only way has been to do a two sequences of
> v.clean
> (with thresholds 1.5 X the raster resolution) and v.build.polylines. If
> you have any better suggestion, I'd love to hear it.
>
> Thanks again for the polylines idea. That was a big help.
>
> 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
>

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

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@PERMANENT threshold=10000 accumulation=accum drainage=direction stream=streams
r.stream.order --overwrite stream_rast=streams@user1 direction=direction@user1 elevation=elevation@PERMANENT accumulation=accum@user1 stream_vect=streams horton=horton
v.extract --overwrite input=streams@user1 where=horton=3 output=main_stream
v.build.polylines --overwrite input=main_stream@user1 output=main_stream_poly cats=first

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

v.to.points input=main_stream@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

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

On Dec 1, 2014, at 9:31 AM, Moritz Lennert <mlennert@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

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@PERMANENT threshold=10000 accumulation=accum drainage=direction stream=streams
r.stream.order --overwrite stream_rast=streams@user1 direction=direction@user1 elevation=elevation@PERMANENT accumulation=accum@user1 stream_vect=streams horton=horton
v.extract --overwrite input=streams@user1 where=horton=3 output=main_stream
v.build.polylines --overwrite input=main_stream@user1 output=main_stream_poly cats=first

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

v.to.points input=main_stream@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

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@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

On Dec 1, 2014, at 9:31 AM, Moritz Lennert <mlennert@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

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@PERMANENT threshold=10000 accumulation=accum drainage=direction stream=streams
r.stream.order --overwrite stream_rast=streams@user1 direction=direction@user1 elevation=elevation@PERMANENT accumulation=accum@user1 stream_vect=streams horton=horton
v.extract --overwrite input=streams@user1 where=horton=3 output=main_stream
v.build.polylines --overwrite input=main_stream@user1 output=main_stream_poly cats=first

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

v.to.points input=main_stream@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@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

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

···

On Mon, Dec 1, 2014 at 7:21 PM, Michael Barton <Michael.Barton@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

On Dec 1, 2014, at 9:31 AM, Moritz Lennert <mlennert@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

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@PERMANENT threshold=10000 accumulation=accum drainage=direction stream=streams
r.stream.order --overwrite stream_rast=streams@user1 direction=direction@user1 elevation=elevation@PERMANENT accumulation=accum@user1 stream_vect=streams horton=horton
v.extract --overwrite input=streams@user1 where=horton=3 output=main_stream
v.build.polylines --overwrite input=main_stream@user1 output=main_stream_poly cats=first

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

v.to.points input=main_stream@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@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Thanks to all who replied to this vexing problem. My postdoc Isaac Ullah found what seems to be a good solution to part of this.

v.net.path appears to extract a single object, single cat vector line from a stream network if we can give it a starting and ending point.

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:21 AM, Michael Barton <michael.barton@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

On Dec 1, 2014, at 9:31 AM, Moritz Lennert <mlennert@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

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@PERMANENT threshold=10000 accumulation=accum drainage=direction stream=streams
r.stream.order --overwrite stream_rast=streams@user1 direction=direction@user1 elevation=elevation@PERMANENT accumulation=accum@user1 stream_vect=streams horton=horton
v.extract --overwrite input=streams@user1 where=horton=3 output=main_stream
v.build.polylines --overwrite input=main_stream@user1 output=main_stream_poly cats=first

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

v.to.points input=main_stream@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

But I’ve tried using cat=first and it continues to assign multiple cats to

the segments.

tested here on my side.

from the manual:

    cats=no - No category number is assigned to a polyline. Also attributes
tables linked to the input vector map are not copied to the output vector
map.
    cats=first - Assign to a polyline category number of the first line. All
linked attributes tables are copied to the output vector map.
    cats=multi - If the lines that make up a polyline have different
category numbers then v.build.polylines will set the multiple catetory
numbers to a polyline. Also all linked attributes tables are copied to the
output vector map.

none of this options seems to work, as always all cats are copied to the
attribute table.

bug in v.build.polylines?

-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/how-to-change-all-cats-in-a-vector-line-tp5175575p5175849.html
Sent from the Grass - Users mailing list archive at Nabble.com.