Skip to content

Commit a27e662

Browse files
committed
address #2460
1 parent 674a412 commit a27e662

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

R/RcppExports.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ CPL_gdalinfo <- function(obj, options, oo, co) {
117117
.Call(`_sf_CPL_gdalinfo`, obj, options, oo, co)
118118
}
119119

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

124124
CPL_gdaladdo <- function(obj, method, overviews, bands, oo, co, clean = FALSE, read_only = FALSE) {

R/gdal_utils.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ resampling_method = function(option = "near") {
3131
#' @param quiet logical; if \code{TRUE}, suppress printing the output for \code{info} and \code{mdiminfo}, and suppress printing progress
3232
#' @param processing character; processing options for \code{demprocessing}
3333
#' @param colorfilename character; name of color file for \code{demprocessing} (mandatory if \code{processing="color-relief"})
34+
#' @param read_only logical; only for `ogrinfo`: if `TRUE`, source is opened in read-only mode
3435
#' @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.
3536
#' @export
3637
#' @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
@@ -76,7 +77,7 @@ gdal_utils = function(util = "info", source, destination, options = character(0)
7677
quiet = !(util %in% c("info", "gdalinfo", "ogrinfo", "vectorinfo",
7778
"mdiminfo")) || ("-multi" %in% options),
7879
processing = character(0), colorfilename = character(0),
79-
config_options = character(0)) {
80+
config_options = character(0), read_only = FALSE) {
8081

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

104105
ret = switch(util,
105106
gdalinfo =, info = CPL_gdalinfo(if (missing(source)) character(0) else source, options, oo, config_options),
106-
vectorinfo =, ogrinfo = CPL_ogrinfo(if (missing(source)) character(0) else source, options, oo, config_options),
107+
vectorinfo =, ogrinfo = CPL_ogrinfo(if (missing(source)) character(0) else source, options, oo, config_options,
108+
isTRUE(read_only) || "-ro" %in% options),
107109
warp = CPL_gdalwarp(source, destination, options, oo, doo, config_options, quiet, "-overwrite" %in% options),
108110
warper = CPL_gdal_warper(source, destination, as.integer(resampling_method(options)),
109111
oo, doo, config_options, quiet), # nocov

man/gdal_utils.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RcppExports.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,17 @@ BEGIN_RCPP
373373
END_RCPP
374374
}
375375
// CPL_ogrinfo
376-
Rcpp::CharacterVector CPL_ogrinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVector options, Rcpp::CharacterVector oo, Rcpp::CharacterVector co);
377-
RcppExport SEXP _sf_CPL_ogrinfo(SEXP objSEXP, SEXP optionsSEXP, SEXP ooSEXP, SEXP coSEXP) {
376+
Rcpp::CharacterVector CPL_ogrinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVector options, Rcpp::CharacterVector oo, Rcpp::CharacterVector co, bool read_only);
377+
RcppExport SEXP _sf_CPL_ogrinfo(SEXP objSEXP, SEXP optionsSEXP, SEXP ooSEXP, SEXP coSEXP, SEXP read_onlySEXP) {
378378
BEGIN_RCPP
379379
Rcpp::RObject rcpp_result_gen;
380380
Rcpp::RNGScope rcpp_rngScope_gen;
381381
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type obj(objSEXP);
382382
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type options(optionsSEXP);
383383
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type oo(ooSEXP);
384384
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type co(coSEXP);
385-
rcpp_result_gen = Rcpp::wrap(CPL_ogrinfo(obj, options, oo, co));
385+
Rcpp::traits::input_parameter< bool >::type read_only(read_onlySEXP);
386+
rcpp_result_gen = Rcpp::wrap(CPL_ogrinfo(obj, options, oo, co, read_only));
386387
return rcpp_result_gen;
387388
END_RCPP
388389
}
@@ -1510,7 +1511,7 @@ static const R_CallMethodDef CallEntries[] = {
15101511
{"_sf_CPL_read_ogr", (DL_FUNC) &_sf_CPL_read_ogr, 14},
15111512
{"_sf_CPL_read_gdal_stream", (DL_FUNC) &_sf_CPL_read_gdal_stream, 12},
15121513
{"_sf_CPL_gdalinfo", (DL_FUNC) &_sf_CPL_gdalinfo, 4},
1513-
{"_sf_CPL_ogrinfo", (DL_FUNC) &_sf_CPL_ogrinfo, 4},
1514+
{"_sf_CPL_ogrinfo", (DL_FUNC) &_sf_CPL_ogrinfo, 5},
15141515
{"_sf_CPL_gdaladdo", (DL_FUNC) &_sf_CPL_gdaladdo, 8},
15151516
{"_sf_CPL_gdalwarp", (DL_FUNC) &_sf_CPL_gdalwarp, 8},
15161517
{"_sf_CPL_gdalrasterize", (DL_FUNC) &_sf_CPL_gdalrasterize, 8},

src/gdal_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ Rcpp::CharacterVector CPL_gdalinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVec
7070

7171
// [[Rcpp::export]]
7272
Rcpp::CharacterVector CPL_ogrinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVector options,
73-
Rcpp::CharacterVector oo, Rcpp::CharacterVector co) {
73+
Rcpp::CharacterVector oo, Rcpp::CharacterVector co, bool read_only = false) {
7474
set_config_options(co);
7575
std::vector <char *> options_char = create_options(options, true);
7676
std::vector <char *> oo_char = create_options(oo, true); // open options
7777
GDALDatasetH ds = NULL;
7878
#if GDAL_VERSION_NUM >= 3070000
7979
if (obj.size())
80-
ds = GDALOpenEx((const char *) obj[0], GA_Update, NULL, oo_char.data(), NULL);
80+
ds = GDALOpenEx((const char *) obj[0], read_only ? GA_ReadOnly : GA_Update, NULL, oo_char.data(), NULL);
8181
GDALVectorInfoOptions* opt = GDALVectorInfoOptionsNew(options_char.data(), NULL);
8282
char *ret_val = GDALVectorInfo(ds, opt);
8383
if (ret_val == NULL)

0 commit comments

Comments
 (0)