Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ License: GPL (>= 3)
URL: https://r-spatial.github.io/qgisprocess/,
https://github.com/r-spatial/qgisprocess
BugReports: https://github.com/r-spatial/qgisprocess/issues
Depends: R (>= 3.6.0)
Imports:
assertthat,
glue,
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ S3method(qgis_clean_argument,qgis_list_input)
S3method(qgis_clean_argument,qgis_tempfile_arg)
S3method(qgis_run_algorithm_p,default)
S3method(qgis_run_algorithm_p,qgis_result)
S3method(sf::st_as_sf,qgis_outputLayer)
S3method(sf::st_as_sf,qgis_outputVector)
S3method(sf::st_as_sf,qgis_result)
S3method(stars::st_as_stars,qgis_outputLayer)
S3method(stars::st_as_stars,qgis_outputRaster)
S3method(stars::st_as_stars,qgis_result)
export(as_qgis_argument)
export(has_qgis)
export(qgis_algorithms)
Expand Down
6 changes: 3 additions & 3 deletions R/compat-raster.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#' Convert a qgis_result object or one of its elements to a raster object
#'
#' @note Just use `qgis_as_raster()` and `qgis_as_brick()` in R scripts;
#' it will use the correct method.
#'
#' @family topics about coercing processing output
#' @family topics about accessing or managing processing results
#'
Expand All @@ -13,6 +10,8 @@
#' @returns A `RasterLayer` or a `RasterBrick` object.
#'
#' @examplesIf has_qgis() && requireNamespace("raster", quietly = TRUE)
#' \donttest{
#' # not running below examples in R CMD check to save time
#' result <- qgis_run_algorithm(
#' "native:slope",
#' INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess")
Expand All @@ -25,6 +24,7 @@
#' # if you need more control, extract the needed output element first:
#' output_raster <- qgis_extract_output(result, "OUTPUT")
#' qgis_as_raster(output_raster)
#' }
#'
#' @name qgis_as_raster

Expand Down
14 changes: 10 additions & 4 deletions R/compat-sf.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#' Convert a qgis_result object to an sf object
#' Convert a qgis_result object or one of its elements to an sf object
#'
#' @details
#' The sf package must be loaded explicitly to use these methods.
#'
#' @note Just use `st_as_sf()` in R scripts, it will use the correct
#' method.
Expand All @@ -12,6 +15,8 @@
#' @returns An `sf` object.
#'
#' @examplesIf has_qgis() && requireNamespace("sf", quietly = TRUE)
#' \donttest{
#' # not running below examples in R CMD check to save time
#' result <- qgis_run_algorithm(
#' "native:buffer",
#' INPUT = system.file("longlake/longlake_depth.gpkg", package = "qgisprocess"),
Expand All @@ -25,20 +30,21 @@
#' # if you need more control, extract the needed output element first:
#' output_vector <- qgis_extract_output(result, "OUTPUT")
#' sf::st_as_sf(output_vector)
#' }
#'
#' @name st_as_sf


#' @rdname st_as_sf
# dynamically registered in zzz.R
#' @exportS3Method sf::st_as_sf
st_as_sf.qgis_result <- function(x, ...) {
output <- qgis_extract_output_by_class(x, c("qgis_outputVector", "qgis_outputLayer"))
sf::st_as_sf(output, ...)
}


#' @rdname st_as_sf
# dynamically registered in zzz.R
#' @exportS3Method sf::st_as_sf
st_as_sf.qgis_outputVector <- function(x, ...) {
if (grepl("\\|layer", x)) {
output_splitted <- strsplit(x, "\\|layer.*=")[[1]]
Expand All @@ -49,7 +55,7 @@ st_as_sf.qgis_outputVector <- function(x, ...) {
}

#' @rdname st_as_sf
# dynamically registered in zzz.R
#' @exportS3Method sf::st_as_sf
st_as_sf.qgis_outputLayer <- function(x, ...) {
if (grepl("\\|layer", x)) {
output_splitted <- strsplit(x, "\\|layer.*=")[[1]]
Expand Down
12 changes: 9 additions & 3 deletions R/compat-stars.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#' Convert a qgis_result object or one of its elements to a stars object
#'
#' @details
#' The stars package must be loaded explicitly to use these methods.
#'
#' @note Just use `st_as_stars()` in R scripts, it will use the correct
#' method.
#'
Expand All @@ -12,6 +15,8 @@
#' @returns A `stars` or a `stars_proxy` object.
#'
#' @examplesIf has_qgis() && requireNamespace("stars", quietly = TRUE)
#' \donttest{
#' # not running below examples in R CMD check to save time
#' result <- qgis_run_algorithm(
#' "native:slope",
#' INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess")
Expand All @@ -25,23 +30,24 @@
#' # if you need more control, extract the needed output element first:
#' output_raster <- qgis_extract_output(result, "OUTPUT")
#' stars::st_as_stars(output_raster)
#' }
#'
#' @name st_as_stars

#' @rdname st_as_stars
# dynamically registered in zzz.R
#' @exportS3Method stars::st_as_stars
st_as_stars.qgis_outputRaster <- function(x, ...) {
stars::read_stars(unclass(x), ...)
}

#' @rdname st_as_stars
# dynamically registered in zzz.R
#' @exportS3Method stars::st_as_stars
st_as_stars.qgis_outputLayer <- function(x, ...) {
stars::read_stars(unclass(x), ...)
}

#' @rdname st_as_stars
# dynamically registered in zzz.R
#' @exportS3Method stars::st_as_stars
st_as_stars.qgis_result <- function(x, ...) {
result <- qgis_extract_output_by_class(x, c("qgis_outputRaster", "qgis_outputLayer"))
stars::read_stars(unclass(result), ...)
Expand Down
6 changes: 3 additions & 3 deletions R/compat-terra.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#' Convert a qgis_result object or one of its elements to a terra object
#'
#' @note Just use `qgis_as_terra()` in R scripts, it will use the correct
#' method.
#'
#' @family topics about coercing processing output
#' @family topics about accessing or managing processing results
#'
Expand All @@ -12,6 +9,8 @@
#' @returns A `SpatRaster` or a `SpatVector` object.
#'
#' @examplesIf has_qgis() && requireNamespace("terra", quietly = TRUE)
#' \donttest{
#' # not running below examples in R CMD check to save time
#' result <- qgis_run_algorithm(
#' "native:slope",
#' INPUT = system.file("longlake/longlake_depth.tif", package = "qgisprocess")
Expand All @@ -24,6 +23,7 @@
#' # if you need more control, extract the needed output element first:
#' output_raster <- qgis_extract_output(result, "OUTPUT")
#' qgis_as_terra(output_raster)
#' }
#'
#' @name qgis_as_terra

Expand Down
21 changes: 17 additions & 4 deletions R/qgis-configure.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@
#' @returns The result of [processx::run()].
#'
#' @examples
#' \donttest{
#' # not running in R CMD check to save time
#' qgis_configure(use_cached_data = TRUE)
#' }
#'
#' # Not run in the examples:
#' if (FALSE) qgis_configure()
#' \dontrun{
#' # package reconfiguration
#' # (not run in example() as it rewrites the package cache file)
#' qgis_configure()
#' }
#'
#' @export
qgis_configure <- function(quiet = FALSE, use_cached_data = FALSE) {
Expand Down Expand Up @@ -358,8 +364,15 @@ qgis_env <- function() {
#' @returns `NULL`, invisibly.
#'
#' @examples
#' if (FALSE) {
#' qgis_unconfigure()
#' \dontrun{
#' # not running this function in example() as it clears the cache environment.
#' qgis_unconfigure()
#' }
#'
#' # undoing qgis_unconfigure() by repopulating the cache environment from file:
#' \donttest{
#' # not running in R CMD check to save time
#' qgis_configure(use_cached_data = TRUE)
#' }
#'
#' @export
Expand Down
3 changes: 3 additions & 0 deletions R/qgis-help.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#'
#' @examplesIf has_qgis()
#' qgis_get_description("native:filedownloader")
#' \donttest{
#' # not running below examples in R CMD check to save time
#' qgis_get_argument_specs("native:filedownloader")
#' qgis_get_output_specs("native:filedownloader")
#' qgis_show_help("native:filedownloader")
#' }
#'
#' @export
qgis_show_help <- function(algorithm) {
Expand Down
7 changes: 0 additions & 7 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
.onLoad <- function(...) {
qgis_configure(quiet = TRUE, use_cached_data = TRUE)

vctrs::s3_register("sf::st_as_sf", "qgis_result")
vctrs::s3_register("sf::st_as_sf", "qgis_outputVector")
vctrs::s3_register("sf::st_as_sf", "qgis_outputLayer")
vctrs::s3_register("stars::st_as_stars", "qgis_result")
vctrs::s3_register("stars::st_as_stars", "qgis_outputLayer")
vctrs::s3_register("stars::st_as_stars", "qgis_outputRaster")

# create package temporary directory
qgisprocess_internal_obj$qgis_tmp_dir_location <- tempfile()
dir.create(qgisprocess_internal_obj$qgis_tmp_dir_location)
Expand Down
7 changes: 3 additions & 4 deletions man/qgis_as_raster.Rd

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

7 changes: 3 additions & 4 deletions man/qgis_as_terra.Rd

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

10 changes: 8 additions & 2 deletions man/qgis_configure.Rd

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

3 changes: 3 additions & 0 deletions man/qgis_show_help.Rd

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

11 changes: 9 additions & 2 deletions man/qgis_unconfigure.Rd

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

10 changes: 8 additions & 2 deletions man/st_as_sf.Rd

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

6 changes: 6 additions & 0 deletions man/st_as_stars.Rd

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

Loading