Skip to content

Commit

Permalink
restore internal arrow read func
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Jun 19, 2024
1 parent f10c506 commit afd8428
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 476 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: vapour
Title: Access to the 'Geospatial Data Abstraction Library' ('GDAL')
Version: 0.10.0
Version: 0.10.9001
Authors@R: c(person("Michael", "Sumner", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2471-7511")),
person("Simon", "Wotherspoon", role = "ctb", comment = "RasterIO configuration for resampling options"),
person("Mark", "Padgham", role = "ctb", comment = "helped get started :)"),
Expand All @@ -27,8 +27,10 @@ LazyData: true
LinkingTo: Rcpp
Imports:
jsonlite,
nanoarrow,
Rcpp,
utils
utils,
wk
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Suggests:
Expand Down
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

gdal_dsn_read_vector_stream <- function(stream_xptr, dsn, layer, sql, options, quiet, drivers, extent, dsn_exists, fid_column_name, width) {
.Call('_vapour_gdal_dsn_read_vector_stream', PACKAGE = 'vapour', stream_xptr, dsn, layer, sql, options, quiet, drivers, extent, dsn_exists, fid_column_name, width)
}

warp_general_cpp <- function(dsn, target_crs, target_extent, target_dim, target_res, bands, resample, silent, band_output_type, options, dsn_outname, include_meta, nara) {
.Call('_vapour_warp_general_cpp', PACKAGE = 'vapour', dsn, target_crs, target_extent, target_dim, target_res, bands, resample, silent, band_output_type, options, dsn_outname, include_meta, nara)
}
Expand Down
109 changes: 52 additions & 57 deletions R/read_stream_internal.R
Original file line number Diff line number Diff line change
@@ -1,57 +1,52 @@
# gdal_ptrs <- function(dsource, layer) {
# layer <- if (missing(layer)) {
# character()
# } else {
# enc2utf8(layer)
# }
# #gdal_ptrs_cpp(dsource, layer)
# }
#
# gdal_vector_data <- function(dsource, layer, ..., sql = NA, options = NULL, quiet = FALSE,
# fid_column_name = character(0),
# if_drivers = character(0),
# extent = NA,
# optional = FALSE, return_stream = FALSE) {
#
# ## vapourize this
# layer <- if (missing(layer)) {
# character()
# } else {
# enc2utf8(layer)
# }
# if (nchar(dsource) < 1L) {
# stop("`dsour` must describe a valid source description for GDAL (input was an empty string).", call. = FALSE)
# }
# dsn_exists <- file.exists(dsource)
#
# if (length(dsource) == 1 && dsn_exists) {
# dsource <- enc2utf8(normalizePath(dsource))
# }
#
#
# stream <- nanoarrow::nanoarrow_allocate_array_stream()
#
# #
# # info <- gdal_dsn_read_vector_stream(stream,
# # dsource, layer, sql, as.character(options), quiet,
# # if_drivers, extent, dsn_exists, fid_column_name, 80L)
# #
# #
#
# # geometry_column <- unlist(lapply(
# # stream$get_schema()$children, function(s) identical(s$metadata[["ARROW:extension:name"]], "ogc.wkb")
# # ))
# crs <- info[[1L]]
# if (info[[2L]] == -1) {
# num_features = NULL
# }
#
# # df = suppressWarnings(nanoarrow::convert_array_stream(x$stream, x$num_features))
# #list(stream = stream, crs = crs, num_features = num_features)
# d <- nanoarrow::convert_array_stream(stream, num_features)
# #d$wkb_geometry <- wk::wkb(d$wkb_geometry, crs = crs)
# d
# }
#
#
#
gdal_ptrs <- function(dsource, layer) {
layer <- if (missing(layer)) {
character()
} else {
enc2utf8(layer)
}
#gdal_ptrs_cpp(dsource, layer)
}

gdal_vector_data <- function(dsource, layer, ..., sql = NA, options = NULL, quiet = FALSE,
fid_column_name = character(0),
if_drivers = character(0),
extent = NA,
optional = FALSE, return_stream = FALSE) {

## vapourize this
layer <- if (missing(layer)) {
character()
} else {
enc2utf8(layer)
}
if (nchar(dsource) < 1L) {
stop("`dsour` must describe a valid source description for GDAL (input was an empty string).", call. = FALSE)
}
dsn_exists <- file.exists(dsource)

if (length(dsource) == 1 && dsn_exists) {
dsource <- enc2utf8(normalizePath(dsource))
}


stream <- nanoarrow::nanoarrow_allocate_array_stream()

info <- gdal_dsn_read_vector_stream(stream,
dsource, layer, sql, as.character(options), quiet,
if_drivers, extent, dsn_exists, fid_column_name, 80L)

if (return_stream) return(structure(list(stream), crs = info[[1]], num_features = info[[2]]))
#
crs <- info[[1L]]
if (info[[2L]] == -1) {
num_features = NULL
}


d <- nanoarrow::convert_array_stream(stream, num_features)
d$wkb_geometry <- wk::wkb(d$wkb_geometry, crs = crs)
d
}



Loading

0 comments on commit afd8428

Please sign in to comment.