Skip to content

Commit

Permalink
remove old warper code
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Jun 6, 2024
1 parent ae90aad commit 50db739
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 295 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# vapour 0.10.0

* Old warper code is removed, now uses 'gdal_raster_'.

* Fixed putting bad options in (empty strings).

* Fixed type problem in internal get projection strings.
Expand Down
4 changes: 2 additions & 2 deletions R/00_warpgeneral.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ gdal_raster_data <- function(dsn, target_crs = NULL, target_dim = NULL, target_e

if (anyNA(target_ext)) stop("NA values in 'target_ext'")
dif <- diff(target_ext)[c(1L, 3L)]
if (any(!dif > 0)) stop("all 'target_ext' values must xmin < xmax, ymin < ymax")
if (any(!dif > 0)) stop("all 'target_ext' values must be xmin < xmax, ymin < ymax")

}
if (is.null(target_dim)) {
Expand Down Expand Up @@ -110,7 +110,7 @@ gdal_raster_dsn <- function(dsn, target_crs = NULL, target_dim = NULL, target_ex

if (anyNA(target_ext)) stop("NA values in 'target_ext'")
dif <- diff(target_ext)[c(1L, 3L)]
if (any(!dif > 0)) stop("all 'target_ext' values must xmin < xmax, ymin < ymax")
if (any(!dif > 0)) stop("all 'target_ext' values must be xmin < xmax, ymin < ymax")

}
if (is.null(target_dim)) {
Expand Down
4 changes: 0 additions & 4 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ sds_list_list_gdal_cpp <- function(dsn) {
.Call('_vapour_sds_list_list_gdal_cpp', PACKAGE = 'vapour', dsn)
}

warp_in_memory_gdal_cpp <- function(dsn, source_WKT, target_WKT, target_extent, target_dim, bands, source_extent, resample, silent, band_output_type, options, nomd, overview, nara) {
.Call('_vapour_warp_in_memory_gdal_cpp', PACKAGE = 'vapour', dsn, source_WKT, target_WKT, target_extent, target_dim, bands, source_extent, resample, silent, band_output_type, options, nomd, overview, nara)
}

vapour_read_raster_block_cpp <- function(dsource, offset, dimension, band, band_output_type, unscale, nara) {
.Call('_vapour_vapour_read_raster_block_cpp', PACKAGE = 'vapour', dsource, offset, dimension, band, band_output_type, unscale, nara)
}
Expand Down
63 changes: 41 additions & 22 deletions R/raster-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,12 @@ vapour_warp_raster <- function(x, bands = NULL,

## bands
if (is.numeric(bands) && any(bands < 1)) stop("all 'bands' index must be >= 1")
if (is.null(bands)) bands <- 0
if(length(bands) < 1 || anyNA(bands) || !is.numeric(bands)) stop("'bands' must be numeric (integer), start at 1")
bands <- as.integer(bands)
#if (is.null(bands)) bands <- 0

if (!is.null(bands)) {
if (length(bands) < 1 || anyNA(bands)) stop("'bands' must be numeric (integer), start at 1")
bands <- as.integer(bands)
}
##if ("projection" %in% names(list(...))) message("argument 'projection' input is ignored, warper functions use 'wkt = ' to specify target projection (any format is ok)")
# dud_extent <- FALSE
# if (is.null(extent)) {
Expand Down Expand Up @@ -413,9 +416,9 @@ vapour_warp_raster <- function(x, bands = NULL,

## if (dud_extent) extent <- 0.0
## hmm, we can't rely on gdalwarp to give a sensibleish dimension if not specified, it goes for the native-res
dud_dimension <- FALSE
#dud_dimension <- FALSE
## we dud it if no target projection is set, so you get native from the extent
if (is.null(dimension) && nchar(projection) < 1) {
if (!is.null(dimension)) {
## NO. We can't heuristic dimension or extent because we don't have a format to return those values with
## we make a simple raster, the image() thing and go with that

Expand All @@ -429,27 +432,30 @@ vapour_warp_raster <- function(x, bands = NULL,
## ## that has to be set in the C++, but we need to send down a message that the default is used (so do it all in C is the summ))
## set it to native with a max
## set it to native with a warn/override
dud_dimension <- TRUE
dimension <- c(2, 2)
#dud_dimension <- TRUE
#dimension <- c(2, 2)
if(!is.numeric(dimension)) stop("'dimension' must be numeric")
if(!length(dimension) == 2L) stop("'dimension must be of length 2'")
if(!all(dimension > 0)) stop("'dimension' values must be greater than 0")
if(!all(is.finite(dimension))) stop("'dimension' values must be finite and non-missing")

}
if(!is.numeric(dimension)) stop("'dimension' must be numeric")
if(!length(dimension) == 2L) stop("'dimension must be of length 2'")
if(!all(dimension > 0)) stop("'dimension' values must be greater than 0")
if(!all(is.finite(dimension))) stop("'dimension' values must be finite and non-missing")
if (dud_dimension) dimension <- 0
#if (dud_dimension) dimension <- 0


if (length(source_extent) > 1) {
if (!is.numeric(source_extent)) {
stop("'source_extent' must be numeric, of length 4 c(xmin, xmax, ymin, ymax)")
}
if (!all(is.finite(source_extent))) stop("'source_extent' values must be finite and non missing")
x <- vapour_vrt(x, source_extent = source_extent)
}
if(!is.null(source_projection)) {
if (!is.character(source_projection)) stop("source_projection must be character")
if(!silent) {
if(!nchar(source_projection) > 10) message("short 'source_projection', possibly invalid?")
}
x <- vapour_vrt(x, projection = source_projection)
}

if (!silent) {
Expand Down Expand Up @@ -510,16 +516,29 @@ vapour_warp_raster <- function(x, bands = NULL,
}
if (any(grepl("-te_srs", options))) stop("setting '-te_srs' projection of target extent is not supported")

vals <- warp_in_memory_gdal_cpp(x, source_WKT = source_projection,
target_WKT = projection,
target_extent = as.numeric(extent),
target_dim = as.integer(dimension),
bands = as.integer(bands),
source_extent = as.numeric(source_extent),
resample = resample,
silent = silent,
band_output_type = band_output_type,
options = options, nomd = nomd, overview, nara = nara)
# vals <- warp_in_memory_gdal_cpp(x, source_WKT = source_projection,
# target_WKT = projection,
# target_extent = as.numeric(extent),
# target_dim = as.integer(dimension),
# bands = as.integer(bands),
# source_extent = as.numeric(source_extent),
# resample = resample,
# silent = silent,
# band_output_type = band_output_type,
# options = options, nomd = nomd, overview, nara = nara)
#

if (nara) {
vals <- gdal_raster_nara(x, target_crs = projection, target_ext = extent, target_dim = dimension,
bands = bands, resample = resample, band_output_type = band_output_type,
options = options, include_meta = !nomd)
} else {
## FIXME deal with nara and source projection source extent
if (is.null(bands)) bands <- 1L
vals <- gdal_raster_data(x, target_crs = projection, target_ext = extent, target_dim = dimension,
bands = bands, resample = resample, band_output_type = band_output_type,
options = options, include_meta = !nomd)
}
# ##// if we Dataset->RasterIO we don't have separated bands'
# nbands <- length(vals[[1L]]) / prod(as.integer(dimension))
# if (nbands > 1) vals <- split(vals[[1L]], rep(seq_len(nbands), each = prod(as.integer(dimension))))
Expand Down
Loading

0 comments on commit 50db739

Please sign in to comment.