[GRASS-user] A question before I embark on a programming exercise

Moritz Lennert mlennert at club.worldonline.be
Thu Nov 13 01:00:38 PST 2014


On 13/11/14 00:25, Thomas Adams wrote:
> 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'

In the example, I was assuming (without making it explicit, sorry) a dir 
coming from r.watershed ('drainage' parameter) and as you can see in the 
man page:

"Provides the "aspect" for each cell measured CCW from East. Multiplying 
positive values by 45 will give the direction in degrees that the 
surface runoff will travel from that cell. The value 0 (zero) indicates 
that the cell is a depression area (defined by the depression input 
map). Negative values indicate that surface runoff is leaving the 
boundaries of the current geographic region. The absolute value of these 
negative cells indicates the direction of flow."

I.e. 2 = due north, 4 = east, 6 = south, 8 = east.

But obviously this has to be adapted to whatever tool you use for 
calculating your drainage direction.


>
> 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'??

 From the r.mapcalc man page:

"In r.mapcalc, maps may be followed by a neighborhood modifier that 
specifies a relative offset from the current cell being evaluated. The 
format is map[r,c], where r is the row offset and c is the column 
offset. For example, map[1,2] refers to the cell one row below and two 
columns to the right of the current cell, map[-2,-1] refers to the cell 
two rows above and one column to the left of the current cell, and 
map[0,1] refers to the cell one column to the right of the current cell."

I.e. the inverse of what you interpreted: [0,1] = same row, one to the 
east, i.e. drainage direction due east.

And I realise that I inversed it myself in the second element of the 
example. It should be:

down_id = if(dir=1, id[1,1], if(dir=2, id[1,0], if(dir=3, id[-1,1] .... etc

i.e. dir=2 implies due North and so one row up, same column.

>
> I apologize for being dense about this, I just need to be sure — sorry…

It can be a bit difficult to wrap your head around, especially when 
those trying to help you induce you into error ;-)


Moritz



More information about the grass-user mailing list