diff --git a/DESCRIPTION b/DESCRIPTION index 42995b1..d500b0b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,8 +7,8 @@ LazyLoad: yes Author: Jonathan Asher Greenberg and Matteo Mattiuzzi Description: Wrappers for the Geospatial Data Abstraction Library (GDAL) Utilities. -Version: 2.0.3.2 -Date: 2020-01-15 +Version: 2.0.3.3 +Date: 2020-05-24 Depends: R (>= 2.14.0) Imports: @@ -20,4 +20,4 @@ Imports: SystemRequirements: GDAL binaries BugReports: https://github.com/gearslaboratory/gdalUtils/issues Encoding: UTF-8 -RoxygenNote: 7.0.2 +RoxygenNote: 7.1.0 diff --git a/R/gdal_cmd_builder.R b/R/gdal_cmd_builder.R index 6df6edb..5c4bea2 100644 --- a/R/gdal_cmd_builder.R +++ b/R/gdal_cmd_builder.R @@ -8,7 +8,8 @@ #' @param parameter_order Character. The order of the parameters for the GDAL command. #' @param parameter_noflags Character. Parameters which do not have a flag. #' @param parameter_doubledash Character. Parameters which should have a double dash "--". -#' @param parameter_noquotes Character. Parameters which should not be wrapped in quotes (vector parameters only, at present). +#' @param parameter_named Named character. Parameters which have a double dash flag and are in key value format (e.g. '--config GDAL_CACHEMAX "30\%"') +#' @param parameter_noquotes Character. Parameters which should not be wrapped in quotes (vector parameters only, at present). This option supersedes `parameter_named`. #' @param gdal_installation_id Numeric. The ID of the GDAL installation to use. Defaults to 1. #' @param python_util Logical. Is the utility a python utility? Default = FALSE. #' @param verbose Logical. Enable verbose execution? Default is FALSE. @@ -59,6 +60,10 @@ #' "ot","of","mask","expand","a_srs", #' "b","mo","co", #' "src_dataset","dst_dataset") +#' +#' parameter_named <- c( +#' "config" +#' ) #' #' parameter_noflags <- c("src_dataset","dst_dataset") #' @@ -67,7 +72,8 @@ #' src_dataset = "input.tif", #' dst_dataset = "output.envi", #' of = "ENVI", -#' strict = TRUE +#' strict = TRUE, +#' config = c(GDAL_CACHEMAX = "30%") #' ) #' #' cmd <- gdal_cmd_builder( @@ -75,22 +81,24 @@ #' parameter_variables=parameter_variables, #' parameter_values=parameter_values, #' parameter_order=parameter_order, -#' parameter_noflags=parameter_noflags) +#' parameter_noflags=parameter_noflags, +#' parameter_named = parameter_named) #' #' cmd #' system(cmd,intern=TRUE) #' } #' @export -#TODO: additional commands +#TODO: additional commands #TODO: work without parameters (executable only) #TODO: command aliases (e.g. for commands with a hyphen, -# since R doesn't allow that in variable naming). +# since R doesn't allow that in variable naming). gdal_cmd_builder <- function(executable,parameter_variables=c(), parameter_values=c(),parameter_order=c(),parameter_noflags=c(), parameter_doubledash=c(), parameter_noquotes=c(), + parameter_named = c(), gdal_installation_id=1, python_util=FALSE, verbose=FALSE) @@ -300,7 +308,7 @@ gdal_cmd_builder <- function(executable,parameter_variables=c(), if(length(parameter_variables_repeatable_defined)>0) { parameter_variables_repeatable_strings <- sapply(parameter_variables_repeatable_defined, - function(X,parameter_values,parameter_doubledash) + function(X,parameter_values,parameter_doubledash, parameter_named) { # if(X == "gcp") browser() @@ -314,7 +322,16 @@ gdal_cmd_builder <- function(executable,parameter_variables=c(), flag=paste("--",X," ",sep="") } else { - flag=paste("-",X," ",sep="") + if (X %in% parameter_named) { + # this was introduced for options like + # '--config GDAL_CACHEMAX "30%"'. It is possible that there + # are also single-dashed named options. Then this must be + # adapted. + flag = paste0("--", X, " ") + } else + { + flag=paste("-",X," ",sep="") + } } } @@ -327,14 +344,23 @@ gdal_cmd_builder <- function(executable,parameter_variables=c(), collapse=" ") } else { - parameter_variables_repeatable_string <- paste( - paste(flag, - qm(parameter_values[[which(names(parameter_values)==X)]]), - sep=""), - collapse=" ") + if (X %in% parameter_named) + { + parameter_variables_repeatable_string <- paste( + paste(flag, + (names(parameter_values[[which(names(parameter_values)==X)]])), + qm(parameter_values[[which(names(parameter_values)==X)]])), + collapse = " ") + } else { + parameter_variables_repeatable_string <- paste( + paste(flag, + qm(parameter_values[[which(names(parameter_values)==X)]]), + sep=""), + collapse=" ") + } } return(parameter_variables_repeatable_string) - },parameter_values=parameter_values,parameter_doubledash=parameter_doubledash) + },parameter_values=parameter_values,parameter_doubledash=parameter_doubledash, parameter_named=parameter_named) } else { parameter_variables_repeatable_strings <- NULL @@ -403,4 +429,4 @@ gdal_cmd_builder <- function(executable,parameter_variables=c(), return(cmd) -} \ No newline at end of file +} diff --git a/R/gdal_contour.R b/R/gdal_contour.R index e826ae3..234acd7 100644 --- a/R/gdal_contour.R +++ b/R/gdal_contour.R @@ -17,7 +17,7 @@ #' @param fl Character. Name one or more "fixed levels" to extract. #' @param nln Character. Provide a name for the output vector layer. Defaults to "contour". #' @param output_Vector Logical. Return output dst_filename as a Spatial* object. Currently only works with f="ESRI Shapefile". -#' @param config Character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information. +#' @param config Named character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information. #' @param ignore.full_scan Logical. If FALSE, perform a brute-force scan if other installs are not found. Default is TRUE. #' @param verbose Logical. Enable verbose execution? Default is FALSE. @@ -119,7 +119,9 @@ gdal_contour <- function( parameter_noquotes <- unlist(parameter_variables$vector) - parameter_doubledash <- c("config") + parameter_doubledash <- c() + + parameter_named <- c("config") executable <- "gdal_contour" @@ -131,6 +133,7 @@ gdal_contour <- function( parameter_noflags=parameter_noflags, parameter_noquotes=parameter_noquotes, parameter_doubledash=parameter_doubledash, + parameter_named = parameter_named, # gdal_installation_id=gdal_chooseInstallation(hasDrivers=of)) gdal_installation_id=gdal_chooseInstallation()) diff --git a/R/gdal_grid.R b/R/gdal_grid.R index 2c3deca..c05cdee 100644 --- a/R/gdal_grid.R +++ b/R/gdal_grid.R @@ -24,7 +24,7 @@ #' @param sql Character. "select_statement". An SQL statement to be evaluated against the datasource to produce a virtual layer of features to be processed. #' @param co Character. "NAME=VALUE". Passes a creation option to the output format driver. Multiple -co options may be listed. See format specific documentation for legal creation options for each format. #' @param q Logical. Suppress progress monitor and other non-error output. -#' @param config Character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information. +#' @param config Named character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information. #' @param output_Raster Logical. Return output dst_filename as a RasterBrick? #' @param ignore.full_scan Logical. If FALSE, perform a brute-force scan if other installs are not found. Default is TRUE. #' @param verbose Logical. Enable verbose execution? Default is FALSE. @@ -333,7 +333,9 @@ gdal_grid <- function( parameter_noquotes <- unlist(parameter_variables$vector) - parameter_doubledash <- c("config") + parameter_doubledash <- c() + + parameter_named <- c("config") executable <- "gdal_grid" @@ -345,6 +347,7 @@ gdal_grid <- function( parameter_noflags=parameter_noflags, parameter_noquotes=parameter_noquotes, parameter_doubledash=parameter_doubledash, + parameter_named = parameter_named, # gdal_installation_id=gdal_chooseInstallation(hasDrivers=of)) gdal_installation_id=gdal_chooseInstallation()) diff --git a/R/gdal_translate.R b/R/gdal_translate.R index 1751c13..c7ad955 100644 --- a/R/gdal_translate.R +++ b/R/gdal_translate.R @@ -33,7 +33,7 @@ #' @param norat Logical. (GDAL >= 1.11) Do not copy source RAT into destination dataset. #' @param oo Character. NAME=VALUE. (starting with GDAL 2.0) Dataset open option (format specific) #' @param sd_index Numeric. If the file is an HDF4 or HDF5 file, which subdataset should be returned (1 to the number of subdatasets)? If this flag is used, src_dataset should be the filename of the multipart file. This parameter only works if the subdataset names follow the SUBDATASET_n_NAME convention. -#' @param config Character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information. +#' @param config Named character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information. #' @param output_Raster Logical. Return output dst_dataset as a RasterBrick? #' @param ignore.full_scan Logical. If FALSE, perform a brute-force scan if other installs are not found. Default is TRUE. #' @param verbose Logical. Enable verbose execution? Default is FALSE. @@ -182,7 +182,9 @@ gdal_translate <- function(src_dataset,dst_dataset,ot,strict,of="GTiff", parameter_noquotes <- c(unlist(parameter_variables$vector),"gcp","scale") - parameter_doubledash <- c("config") + parameter_doubledash <- c() + + parameter_named <- c("config") executable <- "gdal_translate" # browser() @@ -194,6 +196,7 @@ gdal_translate <- function(src_dataset,dst_dataset,ot,strict,of="GTiff", parameter_noflags=parameter_noflags, parameter_noquotes=parameter_noquotes, parameter_doubledash=parameter_doubledash, + parameter_named = parameter_named, gdal_installation_id=gdal_chooseInstallation(hasDrivers=of)) if(verbose) message(paste("GDAL command being used:",cmd)) diff --git a/R/gdalinfo.R b/R/gdalinfo.R index 3389656..9a8f3ae 100644 --- a/R/gdalinfo.R +++ b/R/gdalinfo.R @@ -22,7 +22,7 @@ #' @param formats Logical. List all raster formats supported by this GDAL build (read-only and read-write) and exit. The format support is indicated as follows: 'ro' is read-only driver; 'rw' is read or write (ie. supports CreateCopy); 'rw+' is read, write and update (ie. supports Create). A 'v' is appended for formats supporting virtual IO (/vsimem, /vsigzip, /vsizip, etc). A 's' is appended for formats supporting subdatasets. Note: The valid formats for the output of gdalwarp are formats that support the Create() method (marked as rw+), not just the CreateCopy() method. #' @param format Character. List detailed information about a single format driver. The format should be the short name reported in the --formats list, such as GTiff. #' @param optfile Character. Read the named file and substitute the contents into the commandline options list. Lines beginning with # will be ignored. Multi-word arguments may be kept together with double quotes. -#' @param config Character. Sets the named configuration keyword to the given value, as opposed to setting them as environment variables. Some common configuration keywords are GDAL_CACHEMAX (memory used internally for caching in megabytes) and GDAL_DATA (path of the GDAL "data" directory). Individual drivers may be influenced by other configuration options. +#' @param config Named character. Sets the named configuration keyword to the given value, as opposed to setting them as environment variables. Some common configuration keywords are GDAL_CACHEMAX (memory used internally for caching in megabytes) and GDAL_DATA (path of the GDAL "data" directory). Individual drivers may be influenced by other configuration options. #' @param debug Character. Control what debugging messages are emitted. A value of ON will enable all debug messages. A value of OFF will disable all debug messages. Another value will select only debug messages containing that string in the debug prefix code. ## @param additional_commands Character. Additional commands to pass directly to gdalinfo. #' @param raw_output Logical. Dump the raw output of the gdalinfo (default=TRUE). If not, attempt to return a clean list (not all parameters will be retained, at present). @@ -92,9 +92,9 @@ gdalinfo <- function(datasetname,json,mm,stats, varnames <- c("sd")), character = list( varnames <- c("mdd","datasetname", - "format","optfile","config","debug","oo")), + "format","optfile","debug","oo")), repeatable = list( - varnames <- NULL) + varnames <- c("config")) ) parameter_order <- c( @@ -105,7 +105,9 @@ gdalinfo <- function(datasetname,json,mm,stats, parameter_noflags <- c("datasetname") - parameter_doubledash <- c("version","formats","format","optfile","config","debug") + parameter_doubledash <- c("version","formats","format","optfile","debug") + + parameter_named <- c("config") executable <- "gdalinfo" # End gdalinfo setup @@ -116,7 +118,8 @@ gdalinfo <- function(datasetname,json,mm,stats, parameter_values=parameter_values, parameter_order=parameter_order, parameter_noflags=parameter_noflags, - parameter_doubledash=parameter_doubledash) + parameter_doubledash=parameter_doubledash, + parameter_named = parameter_named) if(verbose) message(paste("GDAL command being used:",cmd)) diff --git a/man/gdal_cmd_builder.Rd b/man/gdal_cmd_builder.Rd index 3b764ca..9ef58b3 100644 --- a/man/gdal_cmd_builder.Rd +++ b/man/gdal_cmd_builder.Rd @@ -12,6 +12,7 @@ gdal_cmd_builder( parameter_noflags = c(), parameter_doubledash = c(), parameter_noquotes = c(), + parameter_named = c(), gdal_installation_id = 1, python_util = FALSE, verbose = FALSE @@ -32,6 +33,8 @@ gdal_cmd_builder( \item{parameter_noquotes}{Character. Parameters which should not be wrapped in quotes (vector parameters only, at present).} +\item{parameter_named}{Named character. Paramters which have a double dash flag and are in key value format (e.g. '--config GDAL_CACHEMAX "30\%"')} + \item{gdal_installation_id}{Numeric. The ID of the GDAL installation to use. Defaults to 1.} \item{python_util}{Logical. Is the utility a python utility? Default = FALSE.} @@ -89,6 +92,10 @@ parameter_order <- c( "ot","of","mask","expand","a_srs", "b","mo","co", "src_dataset","dst_dataset") + +parameter_named <- c( + "config" +) parameter_noflags <- c("src_dataset","dst_dataset") @@ -97,7 +104,8 @@ parameter_values = list( src_dataset = "input.tif", dst_dataset = "output.envi", of = "ENVI", - strict = TRUE + strict = TRUE, + config = c(GDAL_CACHEMAX = "30\%") ) cmd <- gdal_cmd_builder( @@ -105,7 +113,8 @@ cmd <- gdal_cmd_builder( parameter_variables=parameter_variables, parameter_values=parameter_values, parameter_order=parameter_order, - parameter_noflags=parameter_noflags) + parameter_noflags=parameter_noflags, + parameter_named = parameter_named) cmd system(cmd,intern=TRUE) diff --git a/man/gdal_contour.Rd b/man/gdal_contour.Rd index cb46a7b..f00b21f 100644 --- a/man/gdal_contour.Rd +++ b/man/gdal_contour.Rd @@ -56,7 +56,7 @@ gdal_contour( \item{output_Vector}{Logical. Return output dst_filename as a Spatial* object. Currently only works with f="ESRI Shapefile".} -\item{config}{Character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information.} +\item{config}{Named character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information.} \item{ignore.full_scan}{Logical. If FALSE, perform a brute-force scan if other installs are not found. Default is TRUE.} diff --git a/man/gdal_grid.Rd b/man/gdal_grid.Rd index 9aa2b35..64ec70a 100644 --- a/man/gdal_grid.Rd +++ b/man/gdal_grid.Rd @@ -78,7 +78,7 @@ gdal_grid( \item{q}{Logical. Suppress progress monitor and other non-error output.} -\item{config}{Character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information.} +\item{config}{Named character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information.} \item{output_Raster}{Logical. Return output dst_filename as a RasterBrick?} diff --git a/man/gdal_translate.Rd b/man/gdal_translate.Rd index 6cd1e59..fcbd265 100644 --- a/man/gdal_translate.Rd +++ b/man/gdal_translate.Rd @@ -106,7 +106,7 @@ gdal_translate( \item{sd_index}{Numeric. If the file is an HDF4 or HDF5 file, which subdataset should be returned (1 to the number of subdatasets)? If this flag is used, src_dataset should be the filename of the multipart file. This parameter only works if the subdataset names follow the SUBDATASET_n_NAME convention.} -\item{config}{Character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information.} +\item{config}{Named character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information.} \item{output_Raster}{Logical. Return output dst_dataset as a RasterBrick?} diff --git a/man/gdalinfo.Rd b/man/gdalinfo.Rd index 7db8e71..4f498f2 100644 --- a/man/gdalinfo.Rd +++ b/man/gdalinfo.Rd @@ -73,7 +73,7 @@ gdalinfo( \item{optfile}{Character. Read the named file and substitute the contents into the commandline options list. Lines beginning with # will be ignored. Multi-word arguments may be kept together with double quotes.} -\item{config}{Character. Sets the named configuration keyword to the given value, as opposed to setting them as environment variables. Some common configuration keywords are GDAL_CACHEMAX (memory used internally for caching in megabytes) and GDAL_DATA (path of the GDAL "data" directory). Individual drivers may be influenced by other configuration options.} +\item{config}{Named character. Sets the named configuration keyword to the given value, as opposed to setting them as environment variables. Some common configuration keywords are GDAL_CACHEMAX (memory used internally for caching in megabytes) and GDAL_DATA (path of the GDAL "data" directory). Individual drivers may be influenced by other configuration options.} \item{debug}{Character. Control what debugging messages are emitted. A value of ON will enable all debug messages. A value of OFF will disable all debug messages. Another value will select only debug messages containing that string in the debug prefix code.}