diff --git a/R/vect.R b/R/vect.R index ed1743620..eaedd0f3c 100644 --- a/R/vect.R +++ b/R/vect.R @@ -45,7 +45,7 @@ setMethod("vect", signature(x="SpatVectorCollection"), setMethod("vect", signature(x="character"), - function(x, layer="", query="", extent=NULL, filter=NULL, crs="", proxy=FALSE, what="") { + function(x, layer="", query="", extent=NULL, filter=NULL, crs="", proxy=FALSE, what="", opts=NULL) { what <- trimws(tolower(what)) if (what != "") what <- match.arg(trimws(tolower(what)), c("geoms", "attributes")) @@ -98,7 +98,8 @@ setMethod("vect", signature(x="character"), } else { extent <- as.vector(ext(extent)) } - p@cpp$read(x, layer, query, extent, filter, proxy, what) + if (is.null(opts)) opts <- ""[0] + p@cpp$read(x, layer, query, extent, filter, proxy, what, opts) if (isTRUE(crs != "")) { crs(p, warn=FALSE) <- crs } diff --git a/man/vect.Rd b/man/vect.Rd index 98fe92163..a8fe663ad 100644 --- a/man/vect.Rd +++ b/man/vect.Rd @@ -34,7 +34,7 @@ SpatVectors can also be created from "Well Known Text", and from spatial vector \usage{ \S4method{vect}{character}(x, layer="", query="", extent=NULL, filter=NULL, - crs="", proxy=FALSE, what="") + crs="", proxy=FALSE, what="", opts=NULL) \S4method{vect}{matrix}(x, type="points", atts=NULL, crs="") @@ -60,6 +60,7 @@ SpatVectors can also be created from "Well Known Text", and from spatial vector \item{crs}{character. The coordinate reference system in one of the following formats: WKT/WKT2, :, or PROJ-string notation (see \code{\link{crs}}). See \code{\link{crs}}} \item{proxy}{logical. If \code{TRUE} a SpatVectorProxy is returned} \item{what}{character indicating what to read. Either \code{""} for geometries and attributes, or \code{"geoms"} to only read the geometries, \code{"attributes"} to only read the attributes (that are returned as a data.frame)} +\item{opts}{character. GDAL dataset open options} \item{geom}{character. The field name(s) with the geometry data. Either two names for x and y coordinates of points, or a single name for a single column with WKT geometries)} \item{keepgeom}{logical. If \code{TRUE} the geom variable(s) is (are) also included in the attributes} } diff --git a/src/read_gdal.cpp b/src/read_gdal.cpp index 26eaee458..d525d5928 100644 --- a/src/read_gdal.cpp +++ b/src/read_gdal.cpp @@ -256,7 +256,7 @@ bool GetVAT(std::string filename, SpatCategories &vat) { SpatVector v, fvct; std::vector fext; - v.read(filename, "", "", fext, fvct, false, ""); + v.read(filename, "", "", fext, fvct, false, "", {}); if (v.df.nrow() == 0) return false; diff --git a/src/read_ogr.cpp b/src/read_ogr.cpp index a5ca2f74f..e8c139c4e 100644 --- a/src/read_ogr.cpp +++ b/src/read_ogr.cpp @@ -673,9 +673,17 @@ bool SpatVector::read_ogr(GDALDataset *&poDS, std::string layer, std::string que } -bool SpatVector::read(std::string fname, std::string layer, std::string query, std::vector extent, SpatVector filter, bool as_proxy, std::string what) { - //OGRRegisterAll(); - GDALDataset *poDS = static_cast(GDALOpenEx( fname.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL )); +bool SpatVector::read(std::string fname, std::string layer, std::string query, std::vector extent, SpatVector filter, bool as_proxy, std::string what, std::vector options) { + + char ** openops = NULL; + for (size_t i=0; i opt = strsplit(options[i], "="); + if (opt.size() == 2) { + openops = CSLSetNameValue(openops, opt[0].c_str(), opt[1].c_str()); + } + } + + GDALDataset *poDS = static_cast(GDALOpenEx( fname.c_str(), GDAL_OF_VECTOR, NULL, openops, NULL )); if( poDS == NULL ) { if (!file_exists(fname)) { setError("file does not exist: " + fname); diff --git a/src/spatVector.h b/src/spatVector.h index 35990c00f..091025453 100644 --- a/src/spatVector.h +++ b/src/spatVector.h @@ -214,7 +214,7 @@ class SpatVector { SpatVector set_holes(SpatVector x, size_t i); SpatVector remove_duplicate_nodes(int digits); - bool read(std::string fname, std::string layer, std::string query, std::vector extent, SpatVector filter, bool as_proxy, std::string what); + bool read(std::string fname, std::string layer, std::string query, std::vector extent, SpatVector filter, bool as_proxy, std::string what, std::vector options); bool write(std::string filename, std::string lyrname, std::string driver, bool append, bool overwrite, std::vector);