Skip to content

Commit

Permalink
Driver vs Connection mixup
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejohnson51 committed Oct 7, 2024
1 parent 797b227 commit 9e8c0e0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion R/OGRSQLConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
setClass(
"OGRSQLConnection",
contains = "DBIConnection",
slots = list(DSN = "character", readonly = "logical")
slots = list(DSN = "character",
readonly = "logical")
)

#' @rdname OGRSQLConnection-class
Expand Down
12 changes: 5 additions & 7 deletions R/sf_ogr.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ OGRSQL <- function(){ new("OGRSQLDriver") }

setMethod("dbConnect", "OGRSQLDriver",
function(drv, DSN = "", readonly = TRUE, ...) {
## FIXME: could be a new MEM dataset
if (nchar(DSN) < 1) stop("DSN must be a valid data source name (file, connection string, url, ...)")
new("OGRSQLDriver", DSN = DSN, readonly = readonly, ...)
new("OGRSQLConnection", DSN = DSN, readonly = readonly, ...)
})

#' @rdname OGRSQLConnection-class
Expand All @@ -34,7 +33,6 @@ setMethod("dbDisconnect", "OGRSQLConnection", function(conn, ...) {
conn
})


#' Delayed read for vector resources
#'
#' A lazy data frame for GDAL vector data sources. as_ogr is DBI compatible and designed to work with dplyr.
Expand All @@ -54,20 +52,20 @@ setMethod("dbDisconnect", "OGRSQLConnection", function(conn, ...) {
#' @return a 'tbl_OGRSQLConnection'
#' @export

as_ogr <- function(x, layer, query = NA, ignore_lyrs = "gpkg_|rtree_|sqlite_") {
as_ogr <- function(x, layer,..., query = NA, ignore_lyrs = "gpkg_|rtree_|sqlite_") {
UseMethod("as_ogr")
}

#' @name as_ogr
#' @export
as_ogr.character <- function(x, layer, query, ignore_lyrs) {
as_ogr.character <- function(x, layer, ..., query = NA, ignore_lyrs = "gpkg_|rtree_|sqlite_") {
db <- dbConnect(OGRSQL(), x)
as_ogr(db, layer, query = query, ignore_lyrs = ignore_lyrs)
as_ogr(db, layer, ..., query = query, ignore_lyrs = ignore_lyrs)
}

#' @name as_ogr
#' @export
as_ogr.OGRSQLConnection <- function(x, layer, query, ignore_lyrs) {
as_ogr.OGRSQLConnection <- function(x, layer, ..., query = NA, ignore_lyrs = "gpkg_|rtree_|sqlite_") {

if (!is.na(query)) {
if (!missing(layer)) message("'layer' argument ignored, using 'query'")
Expand Down
4 changes: 2 additions & 2 deletions man/OGRSQLConnection-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions man/as_ogr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/hfsubsetR-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e8c0e0

Please sign in to comment.