r.mapcalc and us of max value

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

r.mapcalc and us of max value

simogeo
Hi,

I'm able to get the max value of a raster map using the following command :

r.info map=myrast

which return max = 45784578
and I use this value to create another raster like so :

r.mapcalc "newrast = myrast * 100 / 45784578"

Returns :
 Range of data:    min = 76.2637440646149  max = 446.00018579574 

which appears to be correct

My question is : Is there a way to do it dynamically? I want to automatise that into a bash script.

I've tried : r.mapcalc "newrast = myrast * 100 / max(myrast)" expecting max(myrast) returns here 45784578 (max value) with no success.

returns :
Range of data:    min = 446  max = 446   

which appears to be incorrect.

Any help would be appreciated.

Thanks,
simon
Reply | Threaded
Open this post in threaded view
|

Re: r.mapcalc and us of max value

Micha Silver
It looks like something in your formatting has cut our part of the message.
In any case, in a bash script I would do:

MAX=`r.univar -g map=<your raster> | grep max | cut -d '=' -f 2`
r.mapcalc "newrast = myrast*100/$MAX"

On 04/25/2013 05:22 PM, simogeo wrote:
Hi,

I'm able to get the max value of a raster map using the following command :



which return max = 45784578
and I use this value to create another raster like so :



Returns :

which appears to be correct

My question is : Is there a way to do it dynamically? I want to automatise
that into a bash script.

I've tried : /r.mapcalc "newrast = myrast * 100 / max(myrast)"/ expecting
max(myrast) returns here 45784578 (max value) with no success.

returns : 

which appears to be incorrect.

Any help would be appreciated.

Thanks,
simon



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/r-mapcalc-and-us-of-max-value-tp5049643.html
Sent from the Grass - Users mailing list archive at Nabble.com.
_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user

This mail was received via Mail-SeCure System.




-- 
Micha Silver
GIS Consultant, Arava Development Co.
http://www.surfaces.co.il

_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: r.mapcalc and us of max value

simogeo
Hi Micha,

Thanks for your reply. It works perfectly but I would prefer to use :
MAX=`r.info -rst map=<your raster> | grep max | cut -d '=' -f 2`

since it's much faster!

thanks again.

Bye
Reply | Threaded
Open this post in threaded view
|

Re: r.mapcalc and us of max value

Markus Metz-3
On Thu, Apr 25, 2013 at 10:08 PM, simogeo <[hidden email]> wrote:
> Hi Micha,
>
> Thanks for your reply. It works perfectly but I would prefer to use :

MAX=`r.info -rst map=<your raster> | grep max | cut -d '=' -f 2`

r.info reports max of the raster map as it is, r.univar reports max
for the current region settings. Since r.mapcalc uses the current
region settings, you should really use r.univar instead of r.info.

Markus M

>
>
> since it's much faster!
>
> thanks again.
>
> Bye
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/r-mapcalc-and-us-of-max-value-tp5049643p5049720.html
> Sent from the Grass - Users mailing list archive at Nabble.com.
> _______________________________________________
> grass-user mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/grass-user
_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: r.mapcalc and us of max value

hamish-2
In reply to this post by simogeo
simogeo wrote:

> I'm able to get the max value of a raster map using the
> following command :
>
>
>
> which return max = 45784578
> and I use this value to create another raster like so :
>
>
>
> Returns :
>
> which appears to be correct

Hi,

please post in plain text, as often the HTML gets lost along
the way, many people don't get to see what you wrote, and the
archives don't either:
http://lists.osgeo.org/pipermail/grass-user/2013-April/067939.html
http://thread.gmane.org/gmane.comp.gis.grass.user/47096


thanks,
Hamish
_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: r.mapcalc and us of max value

Markus Neteler
In reply to this post by Micha Silver
On Thu, Apr 25, 2013 at 6:27 PM, Micha Silver <[hidden email]> wrote:
> MAX=`r.univar -g map=<your raster> | grep max | cut -d '=' -f 2`
> r.mapcalc "newrast = myrast*100/$MAX"

Even easier:

GRASS 6.4.3svn (nc_spm_08):~ > eval `r.univar -g elevation`
GRASS 6.4.3svn (nc_spm_08):~ > echo $max
156.329864501953
GRASS 6.4.3svn (nc_spm_08):~ > r.mapcalc "newrast = myrast * 100.0 / $max"

Note that I wrote 100.0 for floating point arithmetics.

If you really want r.info, then likewise with:

GRASS 6.4.3svn (nc_spm_08):~ > eval `r.info -gr elevation`

markusN
_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: r.mapcalc and us of max value

simogeo
On Thu, Apr 25, 2013 at 10:26 PM, Markus Metz <[hidden email]> wrote:

> r.info reports max of the raster map as it is, r.univar reports max
> for the current region settings. Since r.mapcalc uses the current
> region settings, you should really use r.univar instead of r.info.


Thanks for the precision. My current region is set using the raster map.


On Fri, Apr 26, 2013 at 10:29 AM, Markus Neteler <[hidden email]> wrote:


GRASS 6.4.3svn (nc_spm_08):~ > eval `r.univar -g elevation`
GRASS 6.4.3svn (nc_spm_08):~ > echo $max
156.329864501953
GRASS 6.4.3svn (nc_spm_08):~ > r.mapcalc "newrast = myrast * 100.0 / $max"

Note that I wrote 100.0 for floating point arithmetics.

If you really want r.info, then likewise with:

GRASS 6.4.3svn (nc_spm_08):~ > eval `r.info -gr elevation`

markusN

Nice alternative, indeed.

Thanks to all of you


_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user