diff --git a/DESCRIPTION b/DESCRIPTION index 748a580c..c58a746d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: vapour Title: Access to the 'Geospatial Data Abstraction Library' ('GDAL') -Version: 0.9.5.9009 +Version: 0.9.5.9010 Authors@R: c(person("Michael", "Sumner", email = "mdsumner@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2471-7511")), person("Simon", "Wotherspoon", role = "ctb", comment = "RasterIO configuration for resampling options"), person("Mark", "Padgham", role = "ctb", comment = "helped get started :)"), diff --git a/R/raster-input.R b/R/raster-input.R index 497d3839..8b3bedee 100644 --- a/R/raster-input.R +++ b/R/raster-input.R @@ -50,6 +50,7 @@ #' @param set_na specify whether NA values should be set for the NODATA #' @param band_output_type numeric type of band to apply (else the native type if ''), is mapped to one of 'Byte', 'Int32', or 'Float64' #' @param unscale default is `TRUE` so native values will be converted by offset and scale to floating point +#' @param nara logical whether to return a (scaled) nativeRaster #' @export #' @return list of numeric vectors (only one for 'band') #' @examples @@ -63,7 +64,7 @@ #' ## the method can be used to up-sample as well #' str(matrix(vapour_read_raster(f, window = c(0, 0, 10, 10, 15, 25)), 15)) #' -vapour_read_raster <- function(x, band = 1, window, resample = "nearestneighbour", ..., sds = NULL, native = FALSE, set_na = TRUE, band_output_type = "", unscale = TRUE) { +vapour_read_raster <- function(x, band = 1, window, resample = "nearestneighbour", ..., sds = NULL, native = FALSE, set_na = TRUE, band_output_type = "", unscale = TRUE, nara = FALSE) { x <- .check_dsn_single(x) if (!length(native) == 1L || is.na(native[1]) || !is.logical(native)) { stop("'native' must be a single 'TRUE' or 'FALSE'") @@ -105,7 +106,7 @@ vapour_read_raster <- function(x, band = 1, window, resample = "nearestneighbour ## pull a swifty here with [[ to return numeric or integer ##vals <- raster_io_gdal_cpp(dsn = datasourcename, window = window, band = band, resample = resample[1L], band_output_type = band_output_type) vals <- lapply(band, function(iband) { - raster_io_gdal_cpp(dsn = datasourcename, window = window, band = iband, resample = resample[1L], band_output_type = band_output_type, unscale = unscale)[[1L]] + raster_io_gdal_cpp(dsn = datasourcename, window = window, band = iband, resample = resample[1L], band_output_type = band_output_type, unscale = unscale, nara = nara)[[1L]] }) if (set_na && !is.raw(vals[[1L]][1L])) { for (i in seq_along(vals)) { @@ -134,9 +135,9 @@ vapour_read_raster <- function(x, band = 1, window, resample = "nearestneighbour vapour_read_raster_raw <- function(x, band = 1, window, resample = "nearestneighbour", ..., - sds = NULL, native = FALSE, set_na = TRUE) { - + sds = NULL, native = FALSE, set_na = TRUE, nara = FALSE) { + if (nara) message("nara incompatible with raw output, ignoring") if (length(band) > 1) message("_raw output implies one band, using only the first") vapour_read_raster(x, band = band, window = window, resample = resample, ..., sds = sds, native = native, set_na = set_na, band_output_type = "Byte")[[1L]] diff --git a/inst/include/gdalraster/gdalraster.h b/inst/include/gdalraster/gdalraster.h index ad2e8a38..a1646185 100644 --- a/inst/include/gdalraster/gdalraster.h +++ b/inst/include/gdalraster/gdalraster.h @@ -812,9 +812,7 @@ inline List gdal_read_band_values(GDALDataset *hRet, GDALClose(hRet); Rcpp::stop("band type not supported (is it Complex? report at hypertidy/vapour/issues)"); } - Rprintf("%s\n", (const char *)band_output_type[0]); - Rprintf("%i\n", (int)nara[0]); - + if (nara[0] && band_output_type[0] == "Byte") { return replace_nativeRaster(outlist, (R_xlen_t) outXSize, (R_xlen_t) outYSize); } diff --git a/man/vapour_read_raster.Rd b/man/vapour_read_raster.Rd index d1c587ac..32a7ffa8 100644 --- a/man/vapour_read_raster.Rd +++ b/man/vapour_read_raster.Rd @@ -14,7 +14,8 @@ vapour_read_raster( native = FALSE, set_na = TRUE, band_output_type = "", - unscale = TRUE + unscale = TRUE, + nara = FALSE ) } \arguments{ @@ -37,6 +38,8 @@ vapour_read_raster( \item{band_output_type}{numeric type of band to apply (else the native type if ''), is mapped to one of 'Byte', 'Int32', or 'Float64'} \item{unscale}{default is \code{TRUE} so native values will be converted by offset and scale to floating point} + +\item{nara}{logical whether to return a (scaled) nativeRaster} } \value{ list of numeric vectors (only one for 'band') diff --git a/man/vapour_read_raster_raw.Rd b/man/vapour_read_raster_raw.Rd index 487b1f41..d2cd1fa4 100644 --- a/man/vapour_read_raster_raw.Rd +++ b/man/vapour_read_raster_raw.Rd @@ -16,7 +16,8 @@ vapour_read_raster_raw( ..., sds = NULL, native = FALSE, - set_na = TRUE + set_na = TRUE, + nara = FALSE ) vapour_read_raster_int( @@ -79,6 +80,8 @@ vapour_read_raster_hex( \item{native}{apply the full native window for read, \code{FALSE} by default} \item{set_na}{specify whether NA values should be set for the NODATA} + +\item{nara}{logical whether to return a (scaled) nativeRaster} } \value{ atomic vector of the nominated type raw, int, dbl, or character (hex)