[GRASS-user] r.stream.basins vector outlets help (Jens Hegg)

Blumentrath, Stefan Stefan.Blumentrath at nina.no
Tue Feb 10 23:55:26 PST 2015


The advantage with python is that it is (more or less) platform independent.
What I send you first was a UNIX shell script for bash.
That obviously does not work on all UNIX like systems (like Mac in your case).
It might work if you change your terminal / shell to "bash" (http://osxdaily.com/2012/03/21/change-shell-mac-os-x/).
But python is more future oriented, anyway. So if you manage to make run in Python, that would be a better start into the world of scripting than starting with shell scripts (and then moving to Python at some point later (what I will have to - or more precisely like to- do sooner or later)...

For more info see e.g.: 
http://grasswiki.osgeo.org/wiki/GRASS_and_Python
http://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library

Cheers
Stefan
 

-----Original Message-----
From: Jens Hegg [mailto:jensenhegg at gmail.com] 
Sent: 11. februar 2015 00:13
To: Blumentrath, Stefan
Cc: grass-user at lists.osgeo.org
Subject: Re: [GRASS-user] r.stream.basins vector outlets help (Jens Hegg)

I'm on a Mac, if that makes any difference. I will try this and see how it goes. 



Sent from my iPhone

> On Feb 10, 2015, at 3:06 PM, "Blumentrath, Stefan" <Stefan.Blumentrath at nina.no> wrote:
> 
> Hi Jens,
> 
> Sorry, my fault. I should have asked you about your platform first.
> Assuming you are on Windows I guess python would be most suitable language for scripting. Unfortunately I am not that good at python, but I am sure others will fill in.
> You might need something like:
> points = grass.read_command("v.to.db", map='YOUR_VECTOR_POINTS", 
> columns='', option='coor', separator=',', flags='p') for p in points.splitlines():
>    x=p.split(',')[2]
>    y= p.split(',')[3]
>    grass.run_comand('r.stream.basin', dirs=..., coors="%d,%d" % (x, 
> y), ...)
> 
> Good luck!
> Stefan
> 
> -----Original Message-----
> From: Jens Hegg [mailto:jensenhegg at gmail.com]
> Sent: 10. februar 2015 21:22
> To: Blumentrath, Stefan
> Cc: grass-user at lists.osgeo.org
> Subject: Re: [GRASS-user] r.stream.basins vector outlets help (Jens 
> Hegg)
> 
> Sefan,
> 
> Thanks for the help. I'm still not getting it to run, but I am not at all familiar with anything beyond running basic commands on the command console, I've mostly just used the GUI. Should these be input into the command console or the Python shell? I've tried both, the console seems to not recognize most of it, the Python shell gives me lots of syntax errors (which seems like a good start, I just don't know Python at all). 
> Here is what I have:
> 
> points=$(v.db.select -c map=Fish_and_Water_PointsEPSG4140 column=cat)) for p in $points do
>    v.extract --overwrite input=Fish_and_Water_PointsEPSG4140 output=temp_point_map cat=(p) type=point
>    r.stream.basins direction=HenrysDrainage at HenrysFork 
> points=temp_point_map basins=Basin_(p) done
> 
> The first error is a syntax error at the dollar sign in points=$(v.db.select... 
> 
> Am I getting close? The idea is that temp_point_map gets overwritten at each loop so all that remains is the last one. I'm wanting to name each new basin by the category so I can go back and figure out it's attribute data. 
> 
> Jens
> 
> 
>> On Feb 9, 2015, at 11:04 PM, Blumentrath, Stefan wrote:
>> 
>> Hei Jens,
>> 
>> If you want to have watersheds which overlap, you have to have them in different maps as neither raster nor vector data with topology (as in GRASS GIS) allow for overlapping areas.
>> That again means you would have to run r.stream.basins for your vector points individually, e.g. in a loop like this:
>> 
>> points=$(v.db.select -c map=mypoints column=cat) for p in $points do
>>    v.extract ...
>>    r.stream.basisns ... 
>> done
>> 
>> Cheers
>> Stefan
>> 
>> -----Original Message-----
>> From: grass-user-bounces at lists.osgeo.org
>> [mailto:grass-user-bounces at lists.osgeo.org] On Behalf Of Jens Hegg
>> Sent: 10. februar 2015 05:32
>> To: grass-user at lists.osgeo.org
>> Subject: Re: [GRASS-user] r.stream.basins vector outlets help (Jens
>> Hegg)
>> 
>> Ok,  I figured out how to make it work for the vector file. I was including both the flow direction and the stream network along with the vector file. It turns out that only the direction and vector outlets files are needed and then it runs perfectly. The manual examples really should be updated to include a vector points example.
>> 
>> I do still have one problem that someone might be able to help with. Many of the points I use for outlets are just downstream of one another so it creates watersheds that are just small slivers between points. Is it possible for it to create overlapping watersheds as you move down the stream, or do I need to go back and do this manually?
>> 
>> Jens
>> 
>> 
>> 
>>> On Feb 9, 2015, at 6:08 PM, grass-user-request at lists.osgeo.org wrote:
>>> 
>>> Send grass-user mailing list submissions to
>>>    grass-user at lists.osgeo.org
>>> 
>>> To subscribe or unsubscribe via the World Wide Web, visit
>>>    http://lists.osgeo.org/mailman/listinfo/grass-user
>>> or, via email, send a message with subject or body 'help' to
>>>    grass-user-request at lists.osgeo.org
>>> 
>>> You can reach the person managing the list at
>>>    grass-user-owner at lists.osgeo.org
>>> 
>>> When replying, please edit your Subject line so it is more specific 
>>> than "Re: Contents of grass-user digest..."
>>> 
>>> 
>>> Today's Topics:
>>> 
>>> 1. Import/Export of ESRI Arc ascii grids (Thomas Adams)  2. GRASS 
>>> GIS 7.0.0 RC2 released (Markus Neteler)  3. Re: Import/Export of 
>>> ESRI Arc ascii grids (Markus Neteler)  4. Re: Import/Export of ESRI 
>>> Arc ascii grids
>>>    (C?sar Augusto Ram?rez Franco)
>>> 5. Re: v.generalize: does it take forever? (F?bio Dias)  6. 
>>> r.stream.basins vector outlets help (Jens Hegg)
> 


More information about the grass-user mailing list