Re: [GRASS-user] Get values from raster map following a direction map for n steps

2018-11-23 Thread Moritz Lennert

On 23/11/18 14:28, Markus Metz wrote:



On Tue, Nov 20, 2018 at 9:16 AM Stefan Blumentrath 
mailto:stefan.blumentr...@nina.no>> wrote:

 >
 > Dear all,
 >
 >
 >
 > In an r.mapcalc expression, I would like to trace values along a 
direction map for 1 to n steps (e.g. looking 4 steps ahead along a path 
or stream or along a given direction (degrees or 45degrees).

 >
 >
 >
 > I tried using the neighborhood modifier within an eval function in 
r.mapcalc. Unfortunately, using this command:

 >
 > r.mapcalc --o << EOF
 >
 > eval(elev_200 = elevation[1,1] - 200, elev_5 = 5 * elev_200[1,1], 
elev_p = pow(elev_5, 2))

 >
 > gradient_1 = (0.5 * elev_200) + 0.8 * elev_p
 >
 > EOF

elev_200 is an internal variable of the elev function with a single 
value, and not a (temporary) map. Therefore elev_200[1,1] can't work.


You would need several calls to r.mapcalc, with the first one creating 
the map elev_200, e.g.


r.mapcalc "elev_200 = elevation[1,1] - 200"
r.mapcalc "elev_p = pow(5 * elev_200[1,1], 2)"
r.mapcalc "gradient_1 = (0.5 * elev_200) + 0.8 * elev_p"


Cf the man page (Notes section):

"Any maps generated by a r.mapcalc command only exist after the entire 
command has completed. All maps are generated concurrently, row-by-row 
(i.e. there is an implicit "for row in rows {...}" around the entire 
expression). Thus the #, @, and [ ] operators cannot be used on a map 
generated within same r.mapcalc command run. "


Moritz
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] Get values from raster map following a direction map for n steps

2018-11-23 Thread Markus Metz
On Tue, Nov 20, 2018 at 9:16 AM Stefan Blumentrath <
stefan.blumentr...@nina.no> wrote:
>
> Dear all,
>
>
>
> In an r.mapcalc expression, I would like to trace values along a
direction map for 1 to n steps (e.g. looking 4 steps ahead along a path or
stream or along a given direction (degrees or 45degrees).
>
>
>
> I tried using the neighborhood modifier within an eval function in
r.mapcalc. Unfortunately, using this command:
>
> r.mapcalc --o << EOF
>
> eval(elev_200 = elevation[1,1] - 200, elev_5 = 5 * elev_200[1,1], elev_p
= pow(elev_5, 2))
>
> gradient_1 = (0.5 * elev_200) + 0.8 * elev_p
>
> EOF

elev_200 is an internal variable of the elev function with a single value,
and not a (temporary) map. Therefore elev_200[1,1] can't work.

You would need several calls to r.mapcalc, with the first one creating the
map elev_200, e.g.

r.mapcalc "elev_200 = elevation[1,1] - 200"
r.mapcalc "elev_p = pow(5 * elev_200[1,1], 2)"
r.mapcalc "gradient_1 = (0.5 * elev_200) + 0.8 * elev_p"

Markus M
>
>
>
> I get the following error message:
>
> syntax error, unexpected '[', expecting ')'
>
>
>
> However, this command works fine:
>
> r.mapcalc --o << EOF
>
> eval(elev_200 = elevation[1,1] - 200, elev_5 = 5 * elevation[1,1], elev_p
= pow(elev_5, 2))
>
> gradient_1 = (0.5 * elev_200) + 0.8 * elev_p
>
> EOF
>
>
>
> My questions now are:
>
> a) is it generally not supported to use the neighbourhood modifier on a
temporary map defined in an eval() function in r.mapcalc?
>
> b) are there other (efficient) approaches for those of us who do not know
C (e.g. pygrass)?
>
>
>
> I am grateful for any hint.
>
>
>
> Kind regards,
>
> Stefan
>
> ___
> grass-user mailing list
> grass-user@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

[GRASS-user] Get values from raster map following a direction map for n steps

2018-11-20 Thread Stefan Blumentrath
Dear all,

In an r.mapcalc expression, I would like to trace values along a direction map 
for 1 to n steps (e.g. looking 4 steps ahead along a path or stream or along a 
given direction (degrees or 45degrees).

I tried using the neighborhood modifier within an eval function in r.mapcalc. 
Unfortunately, using this command:
r.mapcalc --o << EOF
eval(elev_200 = elevation[1,1] - 200, elev_5 = 5 * elev_200[1,1], elev_p = 
pow(elev_5, 2))
gradient_1 = (0.5 * elev_200) + 0.8 * elev_p
EOF

I get the following error message:
syntax error, unexpected '[', expecting ')'

However, this command works fine:
r.mapcalc --o << EOF
eval(elev_200 = elevation[1,1] - 200, elev_5 = 5 * elevation[1,1], elev_p = 
pow(elev_5, 2))
gradient_1 = (0.5 * elev_200) + 0.8 * elev_p
EOF

My questions now are:
a) is it generally not supported to use the neighbourhood modifier on a 
temporary map defined in an eval() function in r.mapcalc?
b) are there other (efficient) approaches for those of us who do not know C 
(e.g. pygrass)?

I am grateful for any hint.

Kind regards,
Stefan
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user