Skip to content
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
35 changes: 23 additions & 12 deletions src/gdalvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rcpp::CharacterVector>
&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<Rcpp::CharacterVector>
&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<std::string>(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_();
}
Expand Down
4 changes: 4 additions & 0 deletions src/gdalvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rcpp::CharacterVector> &open_options,
const std::string &spatial_filter);
GDALVector(const Rcpp::CharacterVector &dsn, const std::string &layer,
bool read_only,
const Rcpp::Nullable<Rcpp::CharacterVector> &open_options,
Expand Down
12 changes: 11 additions & 1 deletion tests/testthat/test-GDALVector-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ 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),
dialect = ""))
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"))

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