Skip to content

Commit

Permalink
readRAST can return filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Feb 4, 2022
1 parent 5f2e991 commit 96f9d58
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions R/bin_link.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
readRAST <- function(vname, cat=NULL, ignore.stderr=get.ignore.stderrOption(),
NODATA=NULL, plugin=get.pluginOption(), mapset=NULL,
useGDAL=get.useGDALOption(), close_OK=TRUE, drivername="GTiff",
driverFileExt=NULL, return_SGDF=TRUE) {
driverFileExt=NULL, return_SGDF=TRUE, return_filenames=FALSE) {

R_in_sp <- isTRUE(.get_R_interface() == "sp")

Expand Down Expand Up @@ -41,7 +41,7 @@ readRAST <- function(vname, cat=NULL, ignore.stderr=get.ignore.stderrOption(),
resa <- .read_rast_non_plugin(vname=vname, NODATA=NODATA,
driverFileExt=driverFileExt,
ignore.stderr=ignore.stderr, return_SGDF=return_SGDF,
cat=cat, R_in_sp=R_in_sp)
cat=cat, R_in_sp=R_in_sp, return_file=return_filenames)
}
},
finally = {
Expand All @@ -60,7 +60,7 @@ readRAST <- function(vname, cat=NULL, ignore.stderr=get.ignore.stderrOption(),
}


.read_rast_non_plugin <- function(vname, NODATA, driverFileExt, ignore.stderr, return_SGDF, cat, R_in_sp){
.read_rast_non_plugin <- function(vname, NODATA, driverFileExt, ignore.stderr, return_SGDF, cat, R_in_sp, return_filenames=FALSE){
{
pid <- as.integer(round(runif(1, 1, 1000)))

Expand Down Expand Up @@ -144,6 +144,13 @@ readRAST <- function(vname, cat=NULL, ignore.stderr=get.ignore.stderrOption(),
null=as.integer(NODATA),
ignore.stderr=ignore.stderr)

if (return_filenames) {
ff <- list.files(rtmpfl1, pattern=paste0(vname[i], ".*\\.hdr"), full.names=TRUE)
ff <- gsub(".hdr", "", ff)
return (ff)
}


gdal_info <- bin_gdal_info(rtmpfl11, to_int)

what <- ifelse(to_int, "integer", "double")
Expand All @@ -155,8 +162,10 @@ readRAST <- function(vname, cat=NULL, ignore.stderr=get.ignore.stderrOption(),
nodata=attr(gdal_info, "nodata"))
},
finally = {
unlink(paste(rtmpfl1, list.files(rtmpfl1,
if (!return_filenames) {
unlink(paste(rtmpfl1, list.files(rtmpfl1,
pattern=vname[i]), sep=.Platform$file.sep))
}
}
)

Expand Down

0 comments on commit 96f9d58

Please sign in to comment.