[GRASS-user] A question before I embark on a programming exercise
Thomas Adams
tea3rd at gmail.com
Wed Nov 12 15:25:08 PST 2014
Moritz,
I need to be sure I understand this line:
down_id = if(dir=1, id[1,1], if(dir=2, id[0,1], if(dir=3, id[-1,1] .... etc
dir=1 is what direction?; dir=2 is what direction?, etc. Is dir=1 directly
to the 'East', dir=3 directly 'south', dir=5 directly 'west' and
dir=7 directly 'north'
Also, does the indexing [0,1] refer to the [x,y], i.e., [column, row] so
that [0,1] refers to the same column, but one row below? Which would imply
from your line that dir=2 is directly 'south'??
I apologize for being dense about this, I just need to be sure — sorry…
I did get the first part to work using r.mapcalc to get the pixel indexing:
id = (row() - 1)*Ncolumns + col()
Regards,
Tom
On Wed, Nov 12, 2014 at 7:30 AM, Moritz Lennert <
mlennert at club.worldonline.be> wrote:
> On 12/11/14 05:10, Thomas Adams wrote:
>
>> I need to generate an ascii text file from a flow direction grid that
>> consists of (among a couple other things that don't really matter at
>> this point) for each pixel:
>>
>
> Rainer has already given you a whole program, but here's a decomposition
> in simple (untested) r.mapcalc steps:
>
>
>> (1) a unique integer identifier (1 -- N) for the pixel
>>
>
> r.mapcalc "id = row()*N + col()" # where N = nb cols * 10
>
> (you might have to watch out for integer overflow, though)
>
> (2) the integer identifier of the downstream pixel (assuming there is
>> ONLY one)
>>
>
> Calculate flow direction in SFD mode and use something like this:
>
> r.mapcalc down_id = if(dir=1, id[1,1], if(dir=2, id[0,1], if(dir=3,
> id[-1,1] .... etc
>
>
> (3) the x,y location of the pixel (presumably, the lower left corner of
>> the pixel)
>>
>
> center of pixel:
> r.mapcalc x = x()
> r.mapcalc y = y()
>
> if you want the lower left corner:
>
> r.mapcalc x = x() - ewres()/2
> r.mapcalc y = y() - nsres()/2
>
>
> Then export everything with
>
> r.stats -1 in=id,x,y,down_id
>
> Moritz
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20141112/157ec376/attachment.html>
More information about the grass-user
mailing list