raster.transformation: Statistical transformation for rasters

View source: R/raster.transformations.R

raster.transformationR Documentation

Statistical transformation for rasters

Description

Transforms raster to a specified statistical transformation

Usage

raster.transformation(x, trans = "norm", smin = 0, smax = 255)

Arguments

x

A terra SpatRaster class object

trans

Transformation method: "norm", "rstd", "std", "stretch", "nl", "slog", "sr" (please see notes)

smin

Minimum value for stretch

smax

Maximum value for stretch

Details

Transformation option details:

  • norm - (Normalization_ (0-1): if min(x) < 0 ( x - min(x) ) / ( max(x) - min(x) )

  • rstd - (Row standardize) (0-1): if min(x) >= 0 x / max(x) This normalizes data

  •    with negative distributions
    
  • std - (Standardize) (x - mean(x)) / sdv(x)

  • stretch - (Stretch) ((x - min(x)) * max.stretch / (max(x) - min(x)) + min.stretch) This will stretch values to the specified minimum and maximum values (eg., 0-255 for 8-bit)

  • nl - (Natural logarithms) if min(x) > 0 log(x)

  • slog - (Signed log 10) (for skewed data): if min(x) >= 0 ifelse(abs(x) <= 1, 0, sign(x)*log10(abs(x)))

  • sr - (Square-root) if min(x) >= 0 sqrt(x)

Value

A terra SpatRaster class object of specified transformation

Author(s)

Jeffrey S. Evans jeffrey_evans@tnc.org

Examples


library(terra)
r <- rast(nrows=500, ncols=500, xmin=571823, xmax=616763, 
            ymin=4423540, ymax=4453690)
  crs(r) <- "epsg:9001"
r[] <- runif(ncell(r), 1000, 2500)

 # Positive values so, can apply any transformation    
 for( i in c("norm", "rstd", "std", "stretch", "nl", "slog", "sr")) {
   print( raster.transformation(r, trans = i) ) 
 }

 # Negative values so, can't transform using "nl", "slog" or "sr"
 r[] <- runif(ncell(r), -1, 1)
   for( i in c("norm", "rstd", "std", "stretch", "nl", "slog", "sr")) {
  try( print( raster.transformation(r, trans = i) ) ) 
   }



spatialEco documentation built on Nov. 18, 2023, 1:13 a.m.