Skip to content

Commit

Permalink
fix nara problem (nara itself not working for vapour_read_raster)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Feb 29, 2024
1 parent e26510d commit 5e67be7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", 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 :)"),
Expand Down
9 changes: 5 additions & 4 deletions R/raster-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'")
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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]]
Expand Down
4 changes: 1 addition & 3 deletions inst/include/gdalraster/gdalraster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion man/vapour_read_raster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/vapour_read_raster_raw.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e67be7

Please sign in to comment.