Skip to content

Commit

Permalink
address #2460
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Oct 23, 2024
1 parent 674a412 commit a27e662
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ CPL_gdalinfo <- function(obj, options, oo, co) {
.Call(`_sf_CPL_gdalinfo`, obj, options, oo, co)
}

CPL_ogrinfo <- function(obj, options, oo, co) {
.Call(`_sf_CPL_ogrinfo`, obj, options, oo, co)
CPL_ogrinfo <- function(obj, options, oo, co, read_only = FALSE) {
.Call(`_sf_CPL_ogrinfo`, obj, options, oo, co, read_only)
}

CPL_gdaladdo <- function(obj, method, overviews, bands, oo, co, clean = FALSE, read_only = FALSE) {
Expand Down
6 changes: 4 additions & 2 deletions R/gdal_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resampling_method = function(option = "near") {
#' @param quiet logical; if \code{TRUE}, suppress printing the output for \code{info} and \code{mdiminfo}, and suppress printing progress
#' @param processing character; processing options for \code{demprocessing}
#' @param colorfilename character; name of color file for \code{demprocessing} (mandatory if \code{processing="color-relief"})
#' @param read_only logical; only for `ogrinfo`: if `TRUE`, source is opened in read-only mode
#' @return \code{info} returns a character vector with the raster metadata; all other utils return (invisibly) a logical indicating success (i.e., \code{TRUE}); in case of failure, an error is raised.
#' @export
#' @seealso \link{gdal_addo} for adding overlays to a raster file; \link{st_layers} to query geometry type(s) and crs from layers in a (vector) data source
Expand Down Expand Up @@ -76,7 +77,7 @@ gdal_utils = function(util = "info", source, destination, options = character(0)
quiet = !(util %in% c("info", "gdalinfo", "ogrinfo", "vectorinfo",
"mdiminfo")) || ("-multi" %in% options),
processing = character(0), colorfilename = character(0),
config_options = character(0)) {
config_options = character(0), read_only = FALSE) {

stopifnot(is.character(options), is.character(config_options))
if (!quiet && "-multi" %in% options)
Expand All @@ -103,7 +104,8 @@ gdal_utils = function(util = "info", source, destination, options = character(0)

ret = switch(util,
gdalinfo =, info = CPL_gdalinfo(if (missing(source)) character(0) else source, options, oo, config_options),
vectorinfo =, ogrinfo = CPL_ogrinfo(if (missing(source)) character(0) else source, options, oo, config_options),
vectorinfo =, ogrinfo = CPL_ogrinfo(if (missing(source)) character(0) else source, options, oo, config_options,
isTRUE(read_only) || "-ro" %in% options),
warp = CPL_gdalwarp(source, destination, options, oo, doo, config_options, quiet, "-overwrite" %in% options),
warper = CPL_gdal_warper(source, destination, as.integer(resampling_method(options)),
oo, doo, config_options, quiet), # nocov
Expand Down
5 changes: 4 additions & 1 deletion man/gdal_utils.Rd

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

9 changes: 5 additions & 4 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,17 @@ BEGIN_RCPP
END_RCPP
}
// CPL_ogrinfo
Rcpp::CharacterVector CPL_ogrinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVector options, Rcpp::CharacterVector oo, Rcpp::CharacterVector co);
RcppExport SEXP _sf_CPL_ogrinfo(SEXP objSEXP, SEXP optionsSEXP, SEXP ooSEXP, SEXP coSEXP) {
Rcpp::CharacterVector CPL_ogrinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVector options, Rcpp::CharacterVector oo, Rcpp::CharacterVector co, bool read_only);
RcppExport SEXP _sf_CPL_ogrinfo(SEXP objSEXP, SEXP optionsSEXP, SEXP ooSEXP, SEXP coSEXP, SEXP read_onlySEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type obj(objSEXP);
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type options(optionsSEXP);
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type oo(ooSEXP);
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type co(coSEXP);
rcpp_result_gen = Rcpp::wrap(CPL_ogrinfo(obj, options, oo, co));
Rcpp::traits::input_parameter< bool >::type read_only(read_onlySEXP);
rcpp_result_gen = Rcpp::wrap(CPL_ogrinfo(obj, options, oo, co, read_only));
return rcpp_result_gen;
END_RCPP
}
Expand Down Expand Up @@ -1510,7 +1511,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_sf_CPL_read_ogr", (DL_FUNC) &_sf_CPL_read_ogr, 14},
{"_sf_CPL_read_gdal_stream", (DL_FUNC) &_sf_CPL_read_gdal_stream, 12},
{"_sf_CPL_gdalinfo", (DL_FUNC) &_sf_CPL_gdalinfo, 4},
{"_sf_CPL_ogrinfo", (DL_FUNC) &_sf_CPL_ogrinfo, 4},
{"_sf_CPL_ogrinfo", (DL_FUNC) &_sf_CPL_ogrinfo, 5},
{"_sf_CPL_gdaladdo", (DL_FUNC) &_sf_CPL_gdaladdo, 8},
{"_sf_CPL_gdalwarp", (DL_FUNC) &_sf_CPL_gdalwarp, 8},
{"_sf_CPL_gdalrasterize", (DL_FUNC) &_sf_CPL_gdalrasterize, 8},
Expand Down
4 changes: 2 additions & 2 deletions src/gdal_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ Rcpp::CharacterVector CPL_gdalinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVec

// [[Rcpp::export]]
Rcpp::CharacterVector CPL_ogrinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVector options,
Rcpp::CharacterVector oo, Rcpp::CharacterVector co) {
Rcpp::CharacterVector oo, Rcpp::CharacterVector co, bool read_only = false) {
set_config_options(co);
std::vector <char *> options_char = create_options(options, true);
std::vector <char *> oo_char = create_options(oo, true); // open options
GDALDatasetH ds = NULL;
#if GDAL_VERSION_NUM >= 3070000
if (obj.size())
ds = GDALOpenEx((const char *) obj[0], GA_Update, NULL, oo_char.data(), NULL);
ds = GDALOpenEx((const char *) obj[0], read_only ? GA_ReadOnly : GA_Update, NULL, oo_char.data(), NULL);
GDALVectorInfoOptions* opt = GDALVectorInfoOptionsNew(options_char.data(), NULL);
char *ret_val = GDALVectorInfo(ds, opt);
if (ret_val == NULL)
Expand Down

0 comments on commit a27e662

Please sign in to comment.