[GRASS-dev] r.mapcalc bug on max and min?

Anna Petrášová kratochanna at gmail.com
Mon Oct 6 05:25:33 PDT 2014


On Mon, Oct 6, 2014 at 4:51 AM, Pietro <peter.zamb at gmail.com> wrote:

> Dear all,
>
> I would like to rescale a raster map from a -1, 1 interval to 0, 255.
>
> To make an example I've tried to normalize the elevation map:
>
> {{{
> $ r.mapcalc "el = elevation / max(elevation)" --o
>  100%
> $ r.info el
>
>  +----------------------------------------------------------------------------+
>  | Map:      el                             Date: Mon Oct  6 10:29:19
> 2014    |
>  | Mapset:   user1                          Login of Creator: pietro
>     |
>  | Location: nc_basic_spm_grass7
>     |
>  | DataBase: /home/pietro/docdat/gis
>     |
>  | Title:     ( el )
>     |
>  | Timestamp: none
>     |
>
>  |----------------------------------------------------------------------------|
>  |
>     |
>  |   Type of Map:  raster               Number of Categories: 0
>    |
>  |   Data Type:    FCELL
>     |
>  |   Rows:         1350
>    |
>  |   Columns:      1500
>    |
>  |   Total Cells:  2025000
>     |
>  |        Projection: Lambert Conformal Conic
>    |
>  |            N:     228500    S:     215000   Res:    10
>    |
>  |            E:     645000    W:     630000   Res:    10
>    |
>  |   Range of data:    min = 1  max = 1
>    |
>  |
>     |
>  |   Data Description:
>     |
>  |    generated by r.mapcalc
>     |
>  |
>     |
>  |   Comments:
>     |
>  |    elevation / max(elevation)
>     |
>  |
>     |
>
>  +----------------------------------------------------------------------------+
>
> }}}
>
> As you can see the result is a map with all the values that are 1.
>
> Instead If I execute:
>
> {{{
> $ r.mapcalc "el = elevation / 156.3299" --o
>  100%
>
> $ r.info el
>
>  +----------------------------------------------------------------------------+
>  | Map:      el                             Date: Mon Oct  6 10:31:17
> 2014    |
>  | Mapset:   user1                          Login of Creator: pietro
>     |
>  | Location: nc_basic_spm_grass7
>     |
>  | DataBase: /home/pietro/docdat/gis
>     |
>  | Title:     ( el )
>     |
>  | Timestamp: none
>     |
>
>  |----------------------------------------------------------------------------|
>  |
>     |
>  |   Type of Map:  raster               Number of Categories: 0
>    |
>  |   Data Type:    DCELL
>     |
>  |   Rows:         1350
>    |
>  |   Columns:      1500
>    |
>  |   Total Cells:  2025000
>     |
>  |        Projection: Lambert Conformal Conic
>    |
>  |            N:     228500    S:     215000   Res:    10
>    |
>  |            E:     645000    W:     630000   Res:    10
>    |
>  |   Range of data:    min = 0.355522472489405  max = 0.999999772928615
>    |
>  |
>     |
>  |   Data Description:
>     |
>  |    generated by r.mapcalc
>     |
>  |
>     |
>  |   Comments:
>     |
>  |    elevation / 156.3299
>     |
>  |
>     |
>
>  +----------------------------------------------------------------------------+
> }}}
>
> Now it si working... do you know why this r.mapcalc expression:
> "el = elevation / max(elevation)" is wrong?
>
> Now trying to normalize del "el" map:
>
> {{{
> $ RAST="el"
> $ NEW_MAX=255.
> $ NEW_MIN=0.
> $ r.mapcalc "s$RAST = int(float($RAST - min($RAST)) / float(max($RAST)
> - min($RAST)) * ($NEW_MAX - $NEW_MIN) + $NEW_MIN)" --o
>  100%
> $ r.info sel
>
>  +----------------------------------------------------------------------------+
>  | Map:      sel                            Date: Mon Oct  6 10:42:42
> 2014    |
>  | Mapset:   user1                          Login of Creator: pietro
>     |
>  | Location: nc_basic_spm_grass7
>     |
>  | DataBase: /home/pietro/docdat/gis
>     |
>  | Title:     ( sel )
>    |
>  | Timestamp: none
>     |
>
>  |----------------------------------------------------------------------------|
>  |
>     |
>  |   Type of Map:  raster               Number of Categories: 0
>    |
>  |   Data Type:    CELL
>    |
>  |   Rows:         1350
>    |
>  |   Columns:      1500
>    |
>  |   Total Cells:  2025000
>     |
>  |        Projection: Lambert Conformal Conic
>    |
>  |            N:     228500    S:     215000   Res:    10
>    |
>  |            E:     645000    W:     630000   Res:    10
>    |
>  |   Range of data:    min = NULL  max = NULL
>    |
>  |
>     |
>  |   Data Description:
>     |
>  |    generated by r.mapcalc
>     |
>  |
>     |
>  |   Comments:
>     |
>  |    int(float(el - min(el)) / float(max(el) - min(el)) * (255 - 0) + 0)
>    |
>  |
>     |
>
>  +----------------------------------------------------------------------------+
> }}}
>
> Again everything is NULL, I'm doing something wrong or it is a bug?
>

Glynn could perhaps give you some more precise comment, but basically, max
doesn't operate on the entire map but only on the current cell. So for
example, r.macalc "map_max = max(elevation1, elevation2, elevation3)"
creates a map where each cell is the largest value of the corresponding
cells in the 3 elevation maps.

Hope that helps,
Anna


> Best regards
>
> Pietro
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20141006/2309104b/attachment-0001.html>


More information about the grass-dev mailing list