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?
Best regards
Pietro