Skip to content

Commit

Permalink
more for arrow, and lots of experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsumner committed Sep 26, 2023
1 parent c35e292 commit df3ec25
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 116 deletions.
20 changes: 18 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 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, wkt_filter, dsn_exists, dsn_isdb, fid_column_name, width) {
.Call('_vapour_gdal_dsn_read_vector_stream', PACKAGE = 'vapour', stream_xptr, dsn, layer, sql, options, quiet, drivers, wkt_filter, dsn_exists, dsn_isdb, fid_column_name, width)
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) {
Expand Down Expand Up @@ -213,3 +213,19 @@ raster_warp_file_cpp <- function(source_filename, target_crs, target_extent, tar
.Call('_vapour_raster_warp_file_cpp', PACKAGE = 'vapour', source_filename, target_crs, target_extent, target_dim, target_filename, bands, resample, silent, band_output_type, warp_options, transformation_options)
}

gdal_ptrs_cpp <- function(dsn, layer) {
.Call('_vapour_gdal_ptrs_cpp', PACKAGE = 'vapour', dsn, layer)
}

timesTwo <- function(x) {
.Call('_vapour_timesTwo', PACKAGE = 'vapour', x)
}

n_layers <- function(xp) {
.Call('_vapour_n_layers', PACKAGE = 'vapour', xp)
}

ptr_query <- function(xp) {
.Call('_vapour_ptr_query', PACKAGE = 'vapour', xp)
}

43 changes: 29 additions & 14 deletions R/read_stream_internal.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
.read_stream <- function(dsn, layer, ..., sql = NA, options = NULL, quiet = FALSE,
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),
drivers = character(0), ## replace with vrt://..?if=
wkt_filter = character(0), ## extent
if_drivers = character(0),
extent = NA,
optional = FALSE, return_stream = FALSE) {

## vapourize this
Expand All @@ -10,32 +19,38 @@
} else {
enc2utf8(layer)
}
if (nchar(dsn) < 1L) {
stop("`dsn` must describe a valid data source name for GDAL (input wasan empty string).", call. = FALSE)
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(dsn)
dsn_exists <- file.exists(dsource)

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


stream = nanoarrow::nanoarrow_allocate_array_stream()
stream <- nanoarrow::nanoarrow_allocate_array_stream()

info = gdal_dsn_read_vector_stream(stream, dsn, layer, sql, as.character(options), quiet,
drivers, wkt_filter, dsn_exists, dsn_isdb = FALSE, fid_column_name, 80L)

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(stream)
##// layer has been freed as this point

# 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
}
list(data = suppressWarnings(nanoarrow::convert_array_stream(stream, size = num_features)), crs = crs)

# 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
}


Expand Down
11 changes: 11 additions & 0 deletions inst/include/common/common_vapour.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

// written by R Hijmans in terra
inline std::vector<char *> string_to_charptr(std::vector<std::string> s) {
size_t n = s.size();
std::vector<char *> out(n + 1);
for (size_t i = 0; i < n; i++) {
out[i] = (char *) (s[i].c_str());
}
out[n] = NULL;
return out;
}
Loading

0 comments on commit df3ec25

Please sign in to comment.