Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix config parameter #33

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
54 changes: 40 additions & 14 deletions R/gdal_cmd_builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
#'
Expand All @@ -67,30 +72,33 @@
#' src_dataset = "input.tif",
#' dst_dataset = "output.envi",
#' of = "ENVI",
#' strict = TRUE
#' strict = TRUE,
#' config = c(GDAL_CACHEMAX = "30%")
#' )
#'
#' cmd <- gdal_cmd_builder(
#' executable=executable,
#' 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)
Expand Down Expand Up @@ -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()

Expand All @@ -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="")
}
}
}

Expand All @@ -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)
mwip marked this conversation as resolved.
Show resolved Hide resolved
{
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
Expand Down Expand Up @@ -403,4 +429,4 @@ gdal_cmd_builder <- function(executable,parameter_variables=c(),

return(cmd)

}
}
7 changes: 5 additions & 2 deletions R/gdal_contour.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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"

Expand All @@ -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())

Expand Down
7 changes: 5 additions & 2 deletions R/gdal_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"

Expand All @@ -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())

Expand Down
7 changes: 5 additions & 2 deletions R/gdal_translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -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))
Expand Down
13 changes: 8 additions & 5 deletions R/gdalinfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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))

Expand Down
13 changes: 11 additions & 2 deletions man/gdal_cmd_builder.Rd

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

2 changes: 1 addition & 1 deletion man/gdal_contour.Rd

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

2 changes: 1 addition & 1 deletion man/gdal_grid.Rd

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

2 changes: 1 addition & 1 deletion man/gdal_translate.Rd

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

2 changes: 1 addition & 1 deletion man/gdalinfo.Rd

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