Can be used to write prepared inputs on disk.

This is a convenience function around assessDataType(ras, type = "GDAL")

assessDataType(ras, type = "writeRaster")

# S3 method for Raster
assessDataType(ras, type = "writeRaster")

# S3 method for RasterStack
assessDataType(ras, type = "writeRaster")

# S3 method for default
assessDataType(ras, type = "writeRaster")

assessDataTypeGDAL(ras)

Arguments

ras

The RasterLayer or RasterStack for which data type will be assessed.

type

Character. "writeRaster" (default) or "GDAL" to return the recommended data type for writing from the raster and gdalUtils packages, respectively, or "projectRaster" to return recommended resampling type.

Value

The appropriate data type for the range of values in ras. See dataType for details.

The appropriate data type for the range of values in ras for using GDAL. See dataType for details.

Examples

## LOG1S library(raster)
#> Loading required package: sp
ras <- raster(ncol = 10, nrow = 10) ras[] <- rep(c(0,1),50) assessDataType(ras)
#> [1] "LOG1S"
ras[] <- rep(c(TRUE,FALSE),50) assessDataType(ras)
#> [1] "LOG1S"
ras[] <- c(NA, NA, rep(c(0,1),49)) assessDataType(ras)
#> [1] "LOG1S"
ras <- raster(ncol = 10, nrow = 10) ras[] <- c(0, NaN, rep(c(0,1),49)) assessDataType(ras)
#> [1] "LOG1S"
## INT1S ras[] <- -1:98 assessDataType(ras)
#> [1] "INT1S"
ras[] <- c(NA, -1:97) assessDataType(ras)
#> [1] "INT1S"
## INT1U ras <- raster(ncol = 10, nrow = 10) ras[] <- 1:100 assessDataType(ras)
#> [1] "INT1U"
ras[] <- c(NA, 2:100) assessDataType(ras)
#> [1] "INT1U"
## INT2U ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = 64000, max = 65000)) assessDataType(ras)
#> [1] "INT2U"
## INT2S ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -32767, max = 32767)) assessDataType(ras)
#> [1] "INT2S"
ras[54] <- NA assessDataType(ras)
#> [1] "INT2S"
## INT4U ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = 0, max = 500000000)) assessDataType(ras)
#> [1] "INT4U"
ras[14] <- NA assessDataType(ras)
#> [1] "INT4U"
## INT4S ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -200000000, max = 200000000)) assessDataType(ras)
#> [1] "INT4S"
ras[14] <- NA assessDataType(ras)
#> [1] "INT4S"
## FLT4S ras <- raster(ncol = 10, nrow = 10) ras[] <- runif(100, min = -10, max = 87) assessDataType(ras)
#> [1] "FLT4S"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -3.4e+26, max = 3.4e+28)) assessDataType(ras)
#> [1] "FLT4S"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = 3.4e+26, max = 3.4e+28)) assessDataType(ras)
#> [1] "FLT4S"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -3.4e+26, max = -1)) assessDataType(ras)
#> [1] "FLT4S"
## FLT8S ras <- raster(ncol = 10, nrow = 10) ras[] <- c(-Inf, 1, rep(c(0,1),49)) assessDataType(ras)
#> [1] "FLT8S"
ras <- raster(ncol = 10, nrow = 10) ras[] <- c(Inf, 1, rep(c(0,1),49)) assessDataType(ras)
#> [1] "FLT8S"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -1.7e+30, max = 1.7e+308)) assessDataType(ras)
#> [1] "FLT8S"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = 1.7e+30, max = 1.7e+308)) assessDataType(ras)
#> [1] "FLT8S"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -1.7e+308, max = -1)) assessDataType(ras)
#> [1] "FLT8S"
# stack ras <- raster(ncol = 10, nrow = 10) ras[] <- rep(c(0,1),50) ras1 <- raster(ncol = 10, nrow = 10) ras1[] <- round(runif(100, min = -1.7e+308, max = -1)) sta <- stack(ras, ras1) assessDataType(sta)
#> [1] "LOG1S" "FLT8S"
library(raster) ## Byte ras <- raster(ncol = 10, nrow = 10) ras[] <- 1:100 assessDataTypeGDAL(ras)
#> [1] "Byte"
ras[] <- c(NA, 2:100) assessDataTypeGDAL(ras)
#> [1] "Byte"
##Int16 ras <- raster(ncol = 10, nrow = 10) ras <- setValues(ras, -1:98) assessDataTypeGDAL(ras)
#> [1] "Int16"
ras[] <- c(NA, -1:97) assessDataTypeGDAL(ras)
#> [1] "Int16"
ras[] <- round(runif(100, min = -32767, max = 32767)) assessDataTypeGDAL(ras)
#> [1] "Int16"
## UInt16 ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = 64000, max = 65000)) assessDataTypeGDAL(ras)
#> [1] "UInt16"
## UInt32 ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = 0, max = 500000000)) assessDataTypeGDAL(ras)
#> [1] "UInt32"
ras[14] <- NA assessDataTypeGDAL(ras)
#> [1] "UInt32"
## Int32 ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -200000000, max = 200000000)) assessDataTypeGDAL(ras)
#> [1] "Int32"
ras[14] <- NA assessDataTypeGDAL(ras)
#> [1] "Int32"
## Float32 ras <- raster(ncol = 10, nrow = 10) ras[] <- runif(100, min = -10, max = 87) assessDataTypeGDAL(ras)
#> [1] "Float32"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -3.4e+26, max = 3.4e+28)) assessDataTypeGDAL(ras)
#> [1] "Float32"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = 3.4e+26, max = 3.4e+28)) assessDataTypeGDAL(ras)
#> [1] "Float32"
ras <- raster(ncol = 10, nrow = 10) ras[] <- round(runif(100, min = -3.4e+26, max = -1)) assessDataTypeGDAL(ras)
#> [1] "Float32"