<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 6, 2014 at 4:51 AM, Pietro <span dir="ltr"><<a href="mailto:peter.zamb@gmail.com" target="_blank">peter.zamb@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear all,<br>
<br>
I would like to rescale a raster map from a -1, 1 interval to 0, 255.<br>
<br>
To make an example I've tried to normalize the elevation map:<br>
<br>
{{{<br>
$ r.mapcalc "el = elevation / max(elevation)" --o<br>
100%<br>
$ <a href="http://r.info" target="_blank">r.info</a> el<br>
+----------------------------------------------------------------------------+<br>
| Map: el Date: Mon Oct 6 10:29:19 2014 |<br>
| Mapset: user1 Login of Creator: pietro |<br>
| Location: nc_basic_spm_grass7 |<br>
| DataBase: /home/pietro/docdat/gis |<br>
| Title: ( el ) |<br>
| Timestamp: none |<br>
|----------------------------------------------------------------------------|<br>
| |<br>
| Type of Map: raster Number of Categories: 0 |<br>
| Data Type: FCELL |<br>
| Rows: 1350 |<br>
| Columns: 1500 |<br>
| Total Cells: 2025000 |<br>
| Projection: Lambert Conformal Conic |<br>
| N: 228500 S: 215000 Res: 10 |<br>
| E: 645000 W: 630000 Res: 10 |<br>
| Range of data: min = 1 max = 1 |<br>
| |<br>
| Data Description: |<br>
| generated by r.mapcalc |<br>
| |<br>
| Comments: |<br>
| elevation / max(elevation) |<br>
| |<br>
+----------------------------------------------------------------------------+<br>
<br>
}}}<br>
<br>
As you can see the result is a map with all the values that are 1.<br>
<br>
Instead If I execute:<br>
<br>
{{{<br>
$ r.mapcalc "el = elevation / 156.3299" --o<br>
100%<br>
<br>
$ <a href="http://r.info" target="_blank">r.info</a> el<br>
+----------------------------------------------------------------------------+<br>
| Map: el Date: Mon Oct 6 10:31:17 2014 |<br>
| Mapset: user1 Login of Creator: pietro |<br>
| Location: nc_basic_spm_grass7 |<br>
| DataBase: /home/pietro/docdat/gis |<br>
| Title: ( el ) |<br>
| Timestamp: none |<br>
|----------------------------------------------------------------------------|<br>
| |<br>
| Type of Map: raster Number of Categories: 0 |<br>
| Data Type: DCELL |<br>
| Rows: 1350 |<br>
| Columns: 1500 |<br>
| Total Cells: 2025000 |<br>
| Projection: Lambert Conformal Conic |<br>
| N: 228500 S: 215000 Res: 10 |<br>
| E: 645000 W: 630000 Res: 10 |<br>
| Range of data: min = 0.355522472489405 max = 0.999999772928615 |<br>
| |<br>
| Data Description: |<br>
| generated by r.mapcalc |<br>
| |<br>
| Comments: |<br>
| elevation / 156.3299 |<br>
| |<br>
+----------------------------------------------------------------------------+<br>
}}}<br>
<br>
Now it si working... do you know why this r.mapcalc expression:<br>
"el = elevation / max(elevation)" is wrong?<br>
<br>
Now trying to normalize del "el" map:<br>
<br>
{{{<br>
$ RAST="el"<br>
$ NEW_MAX=255.<br>
$ NEW_MIN=0.<br>
$ r.mapcalc "s$RAST = int(float($RAST - min($RAST)) / float(max($RAST)<br>
- min($RAST)) * ($NEW_MAX - $NEW_MIN) + $NEW_MIN)" --o<br>
100%<br>
$ <a href="http://r.info" target="_blank">r.info</a> sel<br>
+----------------------------------------------------------------------------+<br>
| Map: sel Date: Mon Oct 6 10:42:42 2014 |<br>
| Mapset: user1 Login of Creator: pietro |<br>
| Location: nc_basic_spm_grass7 |<br>
| DataBase: /home/pietro/docdat/gis |<br>
| Title: ( sel ) |<br>
| Timestamp: none |<br>
|----------------------------------------------------------------------------|<br>
| |<br>
| Type of Map: raster Number of Categories: 0 |<br>
| Data Type: CELL |<br>
| Rows: 1350 |<br>
| Columns: 1500 |<br>
| Total Cells: 2025000 |<br>
| Projection: Lambert Conformal Conic |<br>
| N: 228500 S: 215000 Res: 10 |<br>
| E: 645000 W: 630000 Res: 10 |<br>
| Range of data: min = NULL max = NULL |<br>
| |<br>
| Data Description: |<br>
| generated by r.mapcalc |<br>
| |<br>
| Comments: |<br>
| int(float(el - min(el)) / float(max(el) - min(el)) * (255 - 0) + 0) |<br>
| |<br>
+----------------------------------------------------------------------------+<br>
}}}<br>
<br>
Again everything is NULL, I'm doing something wrong or it is a bug?<br></blockquote><div><br></div><div>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.</div><div><br></div><div>Hope that helps,</div><div>Anna</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Best regards<br>
<span class="HOEnZb"><font color="#888888"><br>
Pietro<br>
_______________________________________________<br>
grass-dev mailing list<br>
<a href="mailto:grass-dev@lists.osgeo.org">grass-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/grass-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-dev</a><br>
</font></span></blockquote></div><br></div></div>