[GRASS-user] Python-Loop over points

Johannes Radinger JRadinger at gmx.at
Tue Feb 22 02:35:03 EST 2011


Am 22.02.2011 um 02:07 schrieb Daniel Victoria:

> I'm not sure but from what I read in the r.stream.basins description,
> you can have more than one point in your vector file in roder to
> delineate your basins. Now, in case you have one basin inside another,
> what I did once was:
> 1) get x,y coordinates of each point using v.out.ascii
> 2) for each point run r.watershed...
Yes, thats what I want as well, but I want to automatize it and not to run for each
point manually. I also want to run
for each point a grass-function (not necessarily r.stream etc.)
I just want to know how it basically works to loop over points.

to things I thought:
1) loop over the ascii if that is possible
2) use the for loop in combination with v.db.select, but I don't know how that
will work in python

/johannes


> 
> Cheers
> daniel
> 
> On Fri, Feb 18, 2011 at 11:49 AM, Johannes Radinger <JRadinger at gmx.at> wrote:
>> Hello,
>> 
>> 
>> -------- Original-Nachricht --------
>>> Datum: Mon, 7 Feb 2011 22:25:31 -0200
>>> Von: Daniel Victoria <daniel.victoria at gmail.com>
>>> An: Johannes Radinger <JRadinger at gmx.at>
>>> CC: grass-user at lists.osgeo.org
>>> Betreff: Re: [GRASS-user] Python-Loop over points
>> 
>>> Hi Johannes,
>>> 
>>> You will need to use for loop. Something like this (UNTESTED!)
>>> 
>>> for p in range(5):
>>>     points_map = "point"+str(p)
>>>     out_map = "output"+str(p)
>>>     grass.run_command("r.streams.basins", dir = "flow_direction,
>>> points=points_map, basins = out_map)
>>> 
>>> That should work, or at least something similar
>>> 
>>> Daniel
>> 
>> Thank you for your suggestions Daniel, I also thought about
>> a for loop. But in your case the loop is using for each iteration
>> a input-pointmap called "point"+str(p).
>> 
>>  The difference in my
>> case is that I've got only one vector map but with several points
>> in it and I want to iterate over the single points.
>> How is it possible to iterate over the single points? The points are
>> stored in a kind of list format, so it should somehow be possible to
>> loop over this file, but how?
>> 
>> any suggestions?
>> 
>>  /johannes
>> 
>>> 
>>> On Wed, Feb 2, 2011 at 9:39 AM, Johannes Radinger <JRadinger at gmx.at>
>>> wrote:
>>>> Hello,
>>>> 
>>>> I am performing e.g. the r.stream.basins calcutlation in python:
>>>> 
>>>>    grass.run_command("r.stream.basins",
>>>>                      dir = "flow_direction",
>>>>                      points = "point1",
>>>>                      basins = "output")
>>>> 
>>>> that's working perfectly in the case of one single point in "point1".
>>>> How can I do that multiple times when the point layer consist of e.g. 5
>>>> points and I want to create an output for each point (create 5 output
>>> rasters).
>>>> 
>>>> How can that be done in a python script?
>>>> 
>>>> 
>>>> thank you
>>>> 
>>>> Johannes
>>>> 
>>>> --
>>>> NEU: FreePhone - kostenlos mobil telefonieren und surfen!
>>>> Jetzt informieren: http://www.gmx.net/de/go/freephone
>>>> _______________________________________________
>>>> grass-user mailing list
>>>> grass-user at lists.osgeo.org
>>>> http://lists.osgeo.org/mailman/listinfo/grass-user
>>>> 
>> 
>> --
>> NEU: FreePhone - kostenlos mobil telefonieren und surfen!
>> Jetzt informieren: http://www.gmx.net/de/go/freephone
>> 



More information about the grass-user mailing list