[GRASS-user] r.mapcalc questions

Glynn Clements glynn at gclements.plus.com
Thu Jun 9 02:58:42 EDT 2011


Frank Broniewski wrote:

> I have some questions concerning the use of r.mapcalc. I have a DEM made 
> by r.surf.contour using the approach in the wiki (multiplying by 
> 100000)[1]. Now when calculating back the original values I wonder about 
> the values given by r.info. Calculation is done like so within the 
> wxpython map calculator: r.mapcalc dtm_surf = dtm_surf.100k / 100000.0
> 
> Now r.info tells me:
> Data Type:    DCELL
> which seems OK, but
> Range of data:    min = 130  max = 555
> -> shouldn't these be float values after calculation?
> and the comments
> dtm_surf.100k / 100000
> I definitely typed 100000.0! Where're my .0s?

For DCELL, r.info uses %.15g for the range, while r.mapcalc uses %.8g
for floating-point constants in the history. The "%g" format specifier
omits trailing zeros, and omits the decimal point if nothing follows
it.

The alternatives are "%f", which uses a fixed number of decimal
places, "%e" which always uses scientific (exponential) notation, or
"%#g", which always includes the decimal point and trailing zeros. All
of these have their drawbacks.

Would would be nice would be like the existing behaviour but always
retaining the decimal point and at least one digit, but there isn't
any easy way to get that.

> A quick visual 
> verification with r.slope.aspect shows some terracing effects. That lets 
> me suspect that the conversion to a DEM float raster failed somehow - 
> but why?

Note that r.surf.contour works in floating-point and generates DCELL
output, so the multiplication and subsequent division should be
unnecessary.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list