diff --git a/DESCRIPTION b/DESCRIPTION index 965af870a..76d9b0471 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gdalraster Title: Bindings to 'GDAL' -Version: 2.5.0.9014 +Version: 2.5.0.9015 Authors@R: c( person("Chris", "Toney", email = "jctoney@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5734-6510")), diff --git a/NEWS.md b/NEWS.md index d73ab3708..414eada5c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,6 @@ -# gdalraster 2.5.0.9014 (dev) +# gdalraster 2.5.0.9015 (dev) + +* class `GDALVector`: lint/cleanup class constructors, also addressing [Rcpp 1471 comment](https://github.com/RcppCore/Rcpp/pull/1471#issuecomment-4225783579) (2026-04-12) * suppress warning messages in the `show()` method for `GDALRaster` and `GDALVector` (e.g., if no spatial reference is defined) (2026-04-03) diff --git a/src/gdalvector.cpp b/src/gdalvector.cpp index c47486b69..c9c6cbfc7 100644 --- a/src/gdalvector.cpp +++ b/src/gdalvector.cpp @@ -49,37 +49,48 @@ GDALVector::GDALVector() } GDALVector::GDALVector(const Rcpp::CharacterVector &dsn) - : GDALVector(dsn, "", true, Rcpp::CharacterVector::create(), "", "") {} + : GDALVector(dsn, "", true, R_NilValue, "", "") {} GDALVector::GDALVector(const Rcpp::CharacterVector &dsn, const std::string &layer) - : GDALVector(dsn, layer, true, Rcpp::CharacterVector::create(), "", - "") {} + : GDALVector(dsn, layer, true, R_NilValue, "", "") {} GDALVector::GDALVector(const Rcpp::CharacterVector &dsn, const std::string &layer, bool read_only) - : GDALVector(dsn, layer, read_only, Rcpp::CharacterVector::create(), "", - "") {} + : GDALVector(dsn, layer, read_only, R_NilValue, "", "") {} GDALVector::GDALVector(const Rcpp::CharacterVector &dsn, const std::string &layer, bool read_only, const Rcpp::CharacterVector &open_options) : GDALVector(dsn, layer, read_only, open_options, "", "") {} +GDALVector::GDALVector(const Rcpp::CharacterVector &dsn, + const std::string &layer, bool read_only, + const Rcpp::Nullable + &open_options, + const std::string &spatial_filter) + : GDALVector(dsn, layer, read_only, open_options, spatial_filter, "") {} + GDALVector::GDALVector(const Rcpp::CharacterVector &dsn, const std::string &layer, bool read_only, const Rcpp::Nullable &open_options, const std::string &spatial_filter, - const std::string &dialect = "") - : m_layer_name(layer), m_dialect(dialect), - m_open_options(open_options.isNotNull() ? - open_options : Rcpp::CharacterVector::create()), - m_spatial_filter(spatial_filter), - m_ignored_fields(Rcpp::CharacterVector::create()), - m_hDataset(nullptr), m_eAccess(GA_ReadOnly), m_hLayer(nullptr) { + const std::string &dialect) { m_dsn = Rcpp::as(check_gdal_filename(dsn)); + m_layer_name = layer; + + if (open_options.isNotNull()) + m_open_options = Rcpp::CharacterVector(open_options); + else + m_open_options = Rcpp::CharacterVector::create(); + + m_spatial_filter = spatial_filter; + m_dialect = dialect; + + m_ignored_fields = Rcpp::CharacterVector::create(); + open(read_only); setFieldNames_(); } diff --git a/src/gdalvector.h b/src/gdalvector.h index a5377e396..b916ddf86 100644 --- a/src/gdalvector.h +++ b/src/gdalvector.h @@ -39,6 +39,10 @@ class GDALVector { bool read_only); GDALVector(const Rcpp::CharacterVector &dsn, const std::string &layer, bool read_only, const Rcpp::CharacterVector &open_options); + GDALVector(const Rcpp::CharacterVector &dsn, const std::string &layer, + bool read_only, + const Rcpp::Nullable &open_options, + const std::string &spatial_filter); GDALVector(const Rcpp::CharacterVector &dsn, const std::string &layer, bool read_only, const Rcpp::Nullable &open_options, diff --git a/tests/testthat/test-GDALVector-class.R b/tests/testthat/test-GDALVector-class.R index 16bc54294..cd2fa2d5c 100644 --- a/tests/testthat/test-GDALVector-class.R +++ b/tests/testthat/test-GDALVector-class.R @@ -39,7 +39,7 @@ test_that("class constructors work", { expect_equal(lyr$getFeatureCount(), 40) lyr$close() - # add dialect + # add empty dialect expect_no_error(lyr <- new(GDALVector, dsn, sql, read_only = TRUE, open_options = NULL, spatial_filter = bbox_to_wkt(bb), @@ -47,6 +47,15 @@ test_that("class constructors work", { expect_equal(lyr$getFeatureCount(), 40) lyr$close() + # OGRSQL instead of native dialect + expect_no_error(lyr <- new(GDALVector, dsn, sql, read_only = TRUE, + open_options = NULL, + spatial_filter = "", + dialect = "OGRSQL")) + expect_equal(lyr$m_dialect, "OGRSQL") + expect_equal(lyr$getFeatureCount(), 61) + lyr$close() + # invalid layer name expect_error(lyr <- new(GDALVector, dsn, "invalid_layer_name")) @@ -1073,6 +1082,7 @@ test_that("feature write methods work", { open_options = NULL, spatial_filter = "", dialect = "SQLITE")) lyr$returnGeomAs <- "WKT" + expect_equal(lyr$m_dialect, "SQLITE") expect_no_error(f <- lyr$getFeature(test1_fid)) expect_equal(f$id, feat1$id) expect_true(g_equals(f$geom, feat1$geom))