-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing qgis_run_algorithm methods #146
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,19 @@ | ||||||||||||||||||||
#' Run algorithms using 'qgis_process' | ||||||||||||||||||||
#' | ||||||||||||||||||||
#' @rdname qgis_run_algorithm | ||||||||||||||||||||
#' @export | ||||||||||||||||||||
qgis_run_algorithm <- function(.data = NULL, | ||||||||||||||||||||
algorithm, ..., PROJECT_PATH = NULL, ELLIPSOID = NULL, | ||||||||||||||||||||
.raw_json_input = NULL, .quiet = FALSE) { | ||||||||||||||||||||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you'll need to add |
||||||||||||||||||||
UseMethod("qgis_run_algorithm", .data) | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
#' Run QGIS algorithms. | ||||||||||||||||||||
#' See the [QGIS docs](https://docs.qgis.org/testing/en/docs/user_manual/processing_algs/qgis/index.html) | ||||||||||||||||||||
#' for a detailed description of the algorithms provided | ||||||||||||||||||||
#' 'out of the box' on QGIS (versions >= 3.14). | ||||||||||||||||||||
#' | ||||||||||||||||||||
#' @param .data some data needed for piping | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The 'pipe-friendly' character of the function can be described in general. It is not necessary for this argument to be used in a piping context. |
||||||||||||||||||||
#' @param algorithm A qualified algorithm name (e.g., "native:filedownloader") or | ||||||||||||||||||||
#' a path to a QGIS model file. | ||||||||||||||||||||
#' @param PROJECT_PATH,ELLIPSOID Global values for QGIS project file and | ||||||||||||||||||||
|
@@ -26,7 +35,8 @@ | |||||||||||||||||||
#' ) | ||||||||||||||||||||
#' } | ||||||||||||||||||||
#' | ||||||||||||||||||||
qgis_run_algorithm <- function(algorithm, ..., PROJECT_PATH = NULL, ELLIPSOID = NULL, | ||||||||||||||||||||
qgis_run_algorithm.default <- function(.data = NULL, | ||||||||||||||||||||
algorithm, ..., PROJECT_PATH = NULL, ELLIPSOID = NULL, | ||||||||||||||||||||
.raw_json_input = NULL, .quiet = FALSE) { | ||||||||||||||||||||
assert_qgis() | ||||||||||||||||||||
assert_qgis_algorithm(algorithm) | ||||||||||||||||||||
|
@@ -104,3 +114,55 @@ qgis_run_algorithm <- function(algorithm, ..., PROJECT_PATH = NULL, ELLIPSOID = | |||||||||||||||||||
qgis_check_stdout(result) | ||||||||||||||||||||
result | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
#' @keywords internal | ||||||||||||||||||||
#' @export | ||||||||||||||||||||
qgis_run_algorithm.qgis_result <- function( | ||||||||||||||||||||
.data, | ||||||||||||||||||||
algorithm, | ||||||||||||||||||||
..., | ||||||||||||||||||||
PROJECT_PATH = NULL, | ||||||||||||||||||||
ELLIPSOID = NULL, | ||||||||||||||||||||
.raw_json_input = NULL, | ||||||||||||||||||||
.select = "OUTPUT", | ||||||||||||||||||||
.clean = TRUE, | ||||||||||||||||||||
.quiet = TRUE | ||||||||||||||||||||
) { | ||||||||||||||||||||
assert_that(is.string(.select)) | ||||||||||||||||||||
withr::with_options( | ||||||||||||||||||||
list(warning.length = 6e3), | ||||||||||||||||||||
assert_that( | ||||||||||||||||||||
.select %in% names(.data), | ||||||||||||||||||||
msg = glue( | ||||||||||||||||||||
"The qgis_result object misses a '{.select}' element.\n", | ||||||||||||||||||||
"The included JSON-output was:\n", | ||||||||||||||||||||
"{jsonlite::prettify(.data$.processx_result$stdout)}" | ||||||||||||||||||||
) | ||||||||||||||||||||
) | ||||||||||||||||||||
) | ||||||||||||||||||||
output <- unclass(.data[[.select]]) | ||||||||||||||||||||
fun <- qgis_function(algorithm) | ||||||||||||||||||||
result <- fun(output, ..., .quiet = .quiet) | ||||||||||||||||||||
if (.clean) qgis_result_clean(.data) | ||||||||||||||||||||
result | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
#' @keywords internal | ||||||||||||||||||||
#' @export | ||||||||||||||||||||
qgis_run_algorithm.character <- function( | ||||||||||||||||||||
.data = NULL, | ||||||||||||||||||||
algorithm, | ||||||||||||||||||||
..., | ||||||||||||||||||||
PROJECT_PATH = NULL, | ||||||||||||||||||||
ELLIPSOID = NULL, | ||||||||||||||||||||
.raw_json_input = NULL, | ||||||||||||||||||||
.clean = TRUE, | ||||||||||||||||||||
.quiet = TRUE | ||||||||||||||||||||
) { | ||||||||||||||||||||
browser() | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be dropped? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for reviewing and your comments, @florisvdh. And no worries, I completely agree with you, the |
||||||||||||||||||||
assert_that(is.string(.data)) | ||||||||||||||||||||
|
||||||||||||||||||||
fun <- qgis_function(algorithm) | ||||||||||||||||||||
fun(.data, ..., .quiet = .quiet) | ||||||||||||||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure, but probably
.data = NULL
should also be added to the list in line 93 above: