Skip to content

Commit

Permalink
resolve merge
Browse files Browse the repository at this point in the history
Merge branch 'main' of github.com:hypertidy/vapour

# Conflicts:
#	DESCRIPTION
#	NEWS.md
#	R/vapour_vrt.R
  • Loading branch information
mdsumner committed Jan 24, 2024
2 parents ff86145 + 6dcd5f7 commit 8216dd2
Show file tree
Hide file tree
Showing 23 changed files with 2,082 additions and 1,886 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, dev-main]
branches: [main, young-gdal]
pull_request:
branches: [main, master]
branches: [main]

name: R-CMD-check

Expand Down
6 changes: 3 additions & 3 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.9.5.9006
Version: 0.9.5.9008
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 Down Expand Up @@ -29,7 +29,7 @@ Imports:
nanoarrow,
Rcpp,
utils
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
Roxygen: list(markdown = TRUE)
Suggests:
testthat,
Expand All @@ -39,6 +39,6 @@ Suggests:
spelling
SystemRequirements: libgdal-dev, GDAL (>= 2.2.3), PROJ (>= 4.8.0)
VignetteBuilder: knitr
URL: https://github.com/hypertidy/vapour
URL: https://github.com/hypertidy/vapour, https://hypertidy.github.io/vapour/
BugReports: https://github.com/hypertidy/vapour/issues
Language: en-US
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(buildvrt)
export(gdal_raster_data)
export(gdal_raster_dsn)
export(gdal_raster_image)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

* New function `vector_vrt()` to generate VRT for SQL and/or reprojection.

* Fix cross-compilation for ARM on universe, thanks to Jeroen Ooms.

* New function `buildvrt()` as a special-case for -separate from gdalbuildvrt app.

* `vapour_vrt()` gains 'options' argument, so we can in particular do `options = c("-expand", "rgb", "-ot", "Byte")` to warp
16-bit integer colour palettes from GTiff to PNG. :)

Expand Down
2 changes: 1 addition & 1 deletion R/00_read_block.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ vapour_read_raster_block <- function(dsource, offset, dimension, band = 1L, band
#' dimension = c(2L, 3L), band = 1L))
#' if (file.exists(tf)) file.remove(tf)
vapour_write_raster_block <- function(dsource, data, offset, dimension, band = 1L, overwrite = FALSE) {
if (!file.exists(dsource)) stop("file dsource must exist")
## if (!file.exists(dsource)) stop("file dsource must exist")
if (!overwrite) stop(sprintf("set 'overwrite' to TRUE if you really mean to write to file %s", dsource))
if (anyNA(band) || length(band) < 1L) stop("missing band value")
band <- as.integer(band[1L])
Expand Down
8 changes: 4 additions & 4 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# 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)
}

warp_general_cpp <- function(dsn, target_crs, target_extent, target_dim, target_res, bands, resample, silent, band_output_type, options, dsn_outname, include_meta) {
.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)
}
Expand Down Expand Up @@ -209,6 +205,10 @@ raster_vrt_cpp <- function(dsn, extent, projection, sds, bands, geolocation, nom
.Call('_vapour_raster_vrt_cpp', PACKAGE = 'vapour', dsn, extent, projection, sds, bands, geolocation, nomd, overview, options)
}

raster_buildvrt_cpp <- function(dsn, options) {
.Call('_vapour_raster_buildvrt_cpp', PACKAGE = 'vapour', dsn, options)
}

raster_warp_file_cpp <- function(source_filename, target_crs, target_extent, target_dim, target_filename, bands, resample, silent, band_output_type, warp_options, transformation_options) {
.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)
}
Expand Down
3 changes: 2 additions & 1 deletion R/raster-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ vapour_raster_info <- function(x, ..., sds = NULL, min_max = FALSE) {

corners <- NULL
extent <- NULL
if (!is.null(json$cornerCoodinates)) {
if (!is.null(json$cornerCoordinates)) {
corners <- do.call(rbind, json$cornerCoordinates)
extent <- c(range(corners[,1]), range(corners[,2]))
}


if (is.null(json$geoTransform) && !is.null(extent)) {
geoTransform <- c(extent[1], diff(extent[c(1,2)])/json$size[1], 0,
extent[4], 0, diff(extent[c(4:3)])/json$size[2])
Expand Down
99 changes: 57 additions & 42 deletions R/read_stream_internal.R
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
.read_stream <- function(dsn, layer, ..., sql = NA, options = NULL, quiet = FALSE,
fid_column_name = character(0),
drivers = character(0), ## replace with vrt://..?if=
wkt_filter = character(0), ## extent
optional = FALSE, return_stream = FALSE) {

## vapourize this
layer <- if (missing(layer)) {
character()
} else {
enc2utf8(layer)
}
if (nchar(dsn) < 1L) {
stop("`dsn` must describe a valid data source name for GDAL (input wasan empty string).", call. = FALSE)
}
dsn_exists <- file.exists(dsn) ## good to see this finally stuck in sf

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


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)

browser()
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)
}



# 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
# }
#
#
#
18 changes: 17 additions & 1 deletion R/vapour_vrt.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ vapour_vrt <- function(x, extent = NULL, projection = NULL, sds = 1L, bands = N
out
}



#' Vector VRT
#'
Expand Down Expand Up @@ -221,3 +221,19 @@ vector_vrt <- function(x, layer = 1L, projection = NULL, sql = NULL, a_srs = NUL
out
}


#' Build vrt, special case "-separate"
#'
#' @param dsn one or more raster sources
#'
#' @return a character string of the builtvrt, multiple sources treated as bands
#' @export
#'
#' @examples
#' f <- system.file("extdata/sst.tif", package = "vapour", mustWork = TRUE)
#' vrt <- buildvrt(c(f, vapour_vrt(f)))
#' writeLines(vrt)
buildvrt <- function(dsn) {
options = c("-separate")
raster_buildvrt_cpp(dsn, options)
}
Loading

0 comments on commit 8216dd2

Please sign in to comment.