diff --git a/DESCRIPTION b/DESCRIPTION index f69058982..bdf38ad83 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -113,7 +113,7 @@ LinkingTo: VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 Roxygen: list(markdown = TRUE) Config/testthat/edition: 2 SystemRequirements: GDAL (>= 2.0.1), GEOS (>= 3.4.0), diff --git a/NAMESPACE b/NAMESPACE index 0ccba950d..e9862deb9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -42,6 +42,8 @@ S3method(is.na,bbox) S3method(is.na,crs) S3method(is.na,m_range) S3method(is.na,z_range) +S3method(is_geometry_column,PqConnection) +S3method(is_geometry_column,default) S3method(merge,sf) S3method(plot,sf) S3method(plot,sfc_CIRCULARSTRING) diff --git a/R/db.R b/R/db.R index 40a4d9dc8..546b66b49 100644 --- a/R/db.R +++ b/R/db.R @@ -559,10 +559,12 @@ setMethod("dbDataType", c("DBIObject", "sf"), function(dbObj, obj) { #' @param classes classes inherited is_geometry_column <- function(con, x, classes = "") UseMethod("is_geometry_column") +#' @export is_geometry_column.PqConnection <- function(con, x, classes = c("pq_geometry")) { vapply(x, inherits, logical(1), classes) } +#' @export is_geometry_column.default <- function(con, x, classes = c("character")) { # try all character columns (in conjunction with try_postgis_as_sfc) vapply(x, function(x) inherits(x, classes) && !all(is.na(x)), diff --git a/R/init.R b/R/init.R index ba875ec24..a29f96320 100644 --- a/R/init.R +++ b/R/init.R @@ -1,7 +1,7 @@ #' @importFrom utils head object.size str tail packageVersion compareVersion globalVariables #' @importFrom stats aggregate dist na.omit rbinom runif setNames #' @importFrom tools file_ext file_path_sans_ext -#' @importFrom methods as new slot slotNames "slot<-" +#' @importFrom methods as new slot slotNames slot<- #' @importFrom grid convertHeight convertUnit convertWidth current.viewport linesGrob nullGrob pathGrob pointsGrob polylineGrob unit viewport #' @import graphics #' @importFrom grDevices dev.size rgb cm diff --git a/man/sf-package.Rd b/man/sf-package.Rd index 09105a314..5826ccd20 100644 --- a/man/sf-package.Rd +++ b/man/sf-package.Rd @@ -3,7 +3,6 @@ \docType{package} \name{sf-package} \alias{sf-package} -\alias{_PACKAGE} \title{sf: Simple Features for R} \description{ \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} diff --git a/src/mdim.cpp b/src/mdim.cpp index 9d80eda06..3edf9094b 100644 --- a/src/mdim.cpp +++ b/src/mdim.cpp @@ -307,6 +307,7 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV dimensions.attr("names") = dim_names; if (! proxy) { // read the arrays: auto data_type(arr->GetDataType()); + size_t sz = data_type.GetSize(); if (data_type.GetClass() == GEDTC_NUMERIC) { NumericVector vec(nValues); if (debug) @@ -342,7 +343,6 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV vec_lst[i] = vec; } else if (data_type.GetClass() == GEDTC_COMPOUND) { const auto &components = data_type.GetComponents(); - size_t sz = data_type.GetSize(); std::vector buf(sz * nValues); bool ok = arr->Read(offst.data(), anCount.data(), @@ -350,21 +350,23 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV nullptr, /* stride: default to row-major convention */ data_type, &buf[0]); + if (!ok) + stop("Cannot read array into Compound buffer"); DataFrame tbl; GByte *v = buf.data(); for (const auto &co: components) { auto t(co->GetType()); if (t.GetClass() == GEDTC_NUMERIC) { - if (t.GetSize() != sizeof(double)) + if (t.GetNumericDataType() != GDT_Float64) stop("only Float64 data supported in numeric compounds"); NumericVector vec(nValues); - for (int j = 0; j < nValues; j++) + for (size_t j = 0; j < nValues; j++) memcpy(&(vec[j]), v + j * sz + co->GetOffset(), sizeof(double)); tbl.push_back(vec, co->GetName()); } else if (t.GetClass() == GEDTC_STRING) { CharacterVector vec(nValues); const char *str; - for (int j = 0; j < nValues; j++) { + for (size_t j = 0; j < nValues; j++) { memcpy(&str, v + j * sz + co->GetOffset(), sizeof(const char *)); vec[j] = str; // deep copy } @@ -374,7 +376,25 @@ List CPL_read_mdim(CharacterVector file, CharacterVector array_names, CharacterV } vec_lst[i] = tbl; } else { // GEDTC_STRING: - stop("reading string data not implemented"); + std::vector buf(sz * nValues); + bool ok = arr->Read(offst.data(), + anCount.data(), + stp.data(), /* step: defaults to 1,1,1 */ + nullptr, /* stride: default to row-major convention */ + data_type, + &buf[0]); + if (!ok) + stop("Cannot read array into string buffer"); + GByte *v = buf.data(); + CharacterVector vec(nValues); + const char *str; + for (size_t j = 0; j < nValues; j++) { + memcpy(&str, v + j * sz, sizeof(const char *)); + vec[j] = str; // deep copy + } + vec.attr("dim") = dims; + vec.attr("units") = arr->GetUnit(); + vec_lst[i] = vec; } } }