Skip to content

Commit 3681d45

Browse files
authored
Merge pull request #186 from r-spatial/various
Smaller improvements
2 parents 302e06d + a2dd62a commit 3681d45

File tree

12 files changed

+177
-78
lines changed

12 files changed

+177
-78
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ jobs:
2323
- {os: windows-latest, qgis: 'none', r: 'devel', dep: '', r-pkg-cache: 'v11'}
2424
- {os: ubuntu-22.04, qgis: 'none', r: 'release', dep: '', r-pkg-cache: 'v11'}
2525
- {os: macOS-latest, qgis: 'macos-brew', r: 'release', dep: '', r-pkg-cache: 'v0'}
26-
- {os: windows-latest, qgis: 'windows-chocolatey', r: 'release', dep: '', r-pkg-cache: 'v0'}
27-
- {os: windows-latest, qgis: 'windows-chocolatey', r: 'devel', dep: '', r-pkg-cache: 'v2'}
26+
- {os: windows-latest, qgis: 'chocolatey', r: 'release', dep: '', r-pkg-cache: 'v0'}
27+
- {os: windows-latest, qgis: 'chocolatey-ltr', r: 'release', dep: '', r-pkg-cache: 'v0'}
28+
- {os: windows-latest, qgis: 'chocolatey', r: 'devel', dep: '', r-pkg-cache: 'v2'}
2829
- {os: ubuntu-22.04, qgis: 'ubuntu-nightly', r: 'release', dep: '', r-pkg-cache: 'v0'}
2930
- {os: ubuntu-22.04, qgis: 'ubuntu-nightly', r: 'devel', dep: '', r-pkg-cache: 'v2'}
3031
- {os: ubuntu-22.04, qgis: 'ubuntugis', r: 'release', dep: '', r-pkg-cache: 'v1'}
@@ -45,7 +46,6 @@ jobs:
4546
- uses: r-lib/actions/setup-r@v2
4647
with:
4748
r-version: ${{ matrix.config.r }}
48-
http-user-agent: ${{ matrix.config.http-user-agent }}
4949
use-public-rspm: true
5050
extra-repositories: https://geocompr.r-universe.dev
5151

@@ -115,11 +115,17 @@ jobs:
115115
sudo cp -R qgis/QGIS.app /Applications
116116
117117
- name: Install QGIS (Windows chocolatey)
118-
if: matrix.config.qgis == 'windows-chocolatey'
118+
if: matrix.config.qgis == 'chocolatey'
119119
uses: crazy-max/ghaction-chocolatey@v2
120120
with:
121121
args: install qgis
122122

123+
- name: Install QGIS LTR (Windows chocolatey)
124+
if: matrix.config.qgis == 'chocolatey-ltr'
125+
uses: crazy-max/ghaction-chocolatey@v2
126+
with:
127+
args: install qgis-ltr
128+
123129
- name: Query R dependencies and report available versions
124130
id: query
125131
if: matrix.config.dep == ''

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: qgisprocess
22
Title: Use 'QGIS' Processing Algorithms
3-
Version: 0.1.0.9179
3+
Version: 0.1.0.9180
44
Authors@R: c(
55
person("Dewey", "Dunnington", , "dewey@fishandwhistle.net", role = "aut",
66
comment = c(ORCID = "0000-0002-9415-4582", affiliation = "Voltron Data")),

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Allow half-configured states with abundant messages, so that remaining functionality can be used in debugging or even for some real stuff (#177).
55
- Add vector support for {terra} (#184).
66
This makes it possible to use SpatVector(Proxy) objects as input arguments, and to coerce processing results to SpatVector(Proxy).
7+
- `qgis_run_algorithm()` documentation gains a section on QGIS models and scripts (8a20669).
78

89
# qgisprocess 0.1.0
910

R/qgis-run-algorithm.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,50 @@
55
#' for a detailed description of the algorithms provided
66
#' 'out of the box' on QGIS.
77
#'
8+
#' `qgis_run_algorithm()` accepts various R objects as algorithm arguments.
9+
#' Examples include an R matrix or data frame for the
10+
#' argument type 'matrix', R colors for the argument type 'color',
11+
#' sf or terra (SpatVector) objects for the argument type 'vector' and
12+
#' raster/terra/stars objects for the argument type 'raster', but there are many
13+
#' more.
14+
#' `qgis_run_algorithm()` preprocesses the provided objects into the format that
15+
#' QGIS expects for a given argument.
16+
#'
17+
#' For data objects in R that already exist as a stored file, it is best to
18+
#' instead provide the file path in order to prevent a superfluous file writing
19+
#' step from R, as QGIS expects a file path.
20+
#' However terra and stars objects can contain the file path as metadata: in
21+
#' these cases this path is retrieved from the R object and passed to QGIS;
22+
#' potential pitfalls are taken care of.
23+
#'
24+
#' Providing R objects that cannot be converted to the applicable argument type
25+
#' will lead to an error.
26+
#'
27+
#' @section Running QGIS models and Python scripts:
28+
#' QGIS models and Python scripts can be added to the Processing Toolbox in the
29+
#' QGIS GUI, by pointing at their corresponding file.
30+
#' This will put the model or script below the provider 'Models' or
31+
#' 'Scripts', respectively.
32+
#' Next, it is necessary to run [qgis_configure()] in R in order to make the
33+
#' model or script available to qgisprocess (even reloading the package won't
34+
#' detect it, since these providers have dynamic content, not tied to a
35+
#' plugin or to a QGIS version).
36+
#' You can check the outcome with [qgis_providers()] and
37+
#' [qgis_search_algorithms()].
38+
#' Now, just as with other algorithms, you can provide the `model:<name>` or
39+
#' `script:<name>` identifier to the `algorithm` argument of
40+
#' `qgis_run_algorithm()`.
41+
#'
42+
#' As the output argument name of a QGIS model can have an R-unfriendly
43+
#' syntax, you may need to take the JSON parameter string from the QGIS
44+
#' processing dialog and feed the JSON string to the `.raw_json_input` argument
45+
#' of `qgis_run_algorithm()` instead of providing separate arguments.
46+
#'
47+
#' Although the 'qgis_process' backend also supports replacing the 'algorithm'
48+
#' parameter by the file path of a model file or a Python script, it is not
49+
#' planned to implement this in qgisprocess, as it would bypass argument
50+
#' preprocessing in R (including checks).
51+
#'
852
#' @family functions to run one geoprocessing algorithm
953
#'
1054
#' @param algorithm A qualified algorithm name (e.g., `"native:buffer"`) or

man/qgis_run_algorithm.Rd

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-qgis-algorithms.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ test_that("qgis_algorithms() works", {
1212
expect_true(all(vapply(algs[old_names], function(x) all(!is.na(x)), logical(1))))
1313
})
1414

15-
test_that("qgis_has_algorithm() works", {
16-
skip_if_not(has_qgis())
17-
expect_true(qgis_has_algorithm("native:filedownloader"))
18-
expect_false(qgis_has_algorithm("notanalgorithm"))
19-
})
20-
21-
test_that("qgis_has_provider() works", {
22-
skip_if_not(has_qgis())
23-
expect_true(qgis_has_provider("native"))
24-
expect_false(qgis_has_provider("notaprovider"))
25-
})
26-
2715
test_that("qgis_providers() works", {
2816
skip_if_not(has_qgis())
2917
expect_s3_class(qgis_providers(), "data.frame")

tests/testthat/test-qgis-configure.R

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,3 @@
1-
test_that("qgis_version() works", {
2-
skip_if_not(has_qgis())
3-
4-
expect_match(qgis_version(), "^\\d{1,2}\\.\\d+.*-.+")
5-
expect_match(qgis_version(full = FALSE), "^\\d{1,2}\\.\\d+.\\d+$")
6-
})
7-
8-
test_that("qgis_version(debug = TRUE) works", {
9-
skip_if_not(has_qgis())
10-
skip_if(
11-
package_version(qgis_version(full = FALSE)) < "3.22.0",
12-
"QGIS version is older than 3.22.0"
13-
)
14-
15-
capture.output({
16-
expect_message(
17-
qgis_version(debug = TRUE),
18-
glue("Using.+{getNamespaceVersion('qgisprocess')}")
19-
)
20-
expect_message(qgis_version(debug = TRUE), "PROJ version")
21-
expect_message(qgis_version(debug = TRUE), "EPSG ")
22-
})
23-
})
24-
25-
test_that("qgis_query_version() works", {
26-
skip_if_not(has_qgis())
27-
28-
expect_match(qgis_query_version(), "^\\d{1,2}\\.\\d+.*-.+")
29-
})
30-
31-
test_that("qgis_query_version() works for development versions of QGIS", {
32-
skip_if_not(has_qgis())
33-
qversion <- qgis_query_version()
34-
skip_if_not(
35-
stringr::str_detect(
36-
qversion,
37-
"^\\d{1,2}\\.\\d*[13579][\\.-]"
38-
),
39-
paste("QGIS version", qversion, "is not a development version.")
40-
)
41-
42-
expect_match(
43-
qversion,
44-
"^\\d{1,2}\\.\\d+.*-\\p{L}+, development state ([0-9a-f]{7,}|unclear:.+)",
45-
perl = TRUE
46-
)
47-
48-
if (stringr::str_detect(qversion, ".+development state unclear:.+")) {
49-
expect_warning(qgis_query_version(), "version identifier")
50-
}
51-
})
52-
531
test_that("qgis_configure() returns FALSE with no QGIS", {
542
skip_if(has_qgis())
553
expect_false(

tests/testthat/test-qgis-has.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
test_that("qgis_has_algorithm() works", {
2+
skip_if_not(has_qgis())
3+
expect_true(qgis_has_algorithm("native:filedownloader"))
4+
expect_false(qgis_has_algorithm("notanalgorithm"))
5+
})
6+
7+
test_that("qgis_has_provider() works", {
8+
skip_if_not(has_qgis())
9+
expect_true(qgis_has_provider("native"))
10+
expect_false(qgis_has_provider("notaprovider"))
11+
})
12+
13+
test_that("qgis_has_plugin() works", {
14+
skip_if_not(has_qgis())
15+
expect_true(qgis_has_plugin("processing"))
16+
expect_false(qgis_has_plugin("notaplugin"))
17+
})

tests/testthat/test-qgis-plugins.R

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ test_that("message_disabled_plugins() works", {
6868
})
6969

7070

71-
test_that("qgis_has_plugin() works", {
72-
skip_if_not(has_qgis())
73-
expect_true(qgis_has_plugin("processing"))
74-
expect_false(qgis_has_plugin("notaplugin"))
75-
})
76-
77-
7871
test_that("qgis_enable_plugins() messages are OK", {
7972
skip_if_not(has_qgis())
8073
expect_message(qgis_enable_plugins(names = ""), "exiting")

tests/testthat/test-qgis-state.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
test_that("qgis_version() works", {
2+
skip_if_not(has_qgis())
3+
4+
expect_match(qgis_version(), "^\\d{1,2}\\.\\d+.*-.+")
5+
expect_match(qgis_version(full = FALSE), "^\\d{1,2}\\.\\d+.\\d+$")
6+
})
7+
8+
test_that("qgis_version(debug = TRUE) works", {
9+
skip_if_not(has_qgis())
10+
skip_if(
11+
package_version(qgis_version(full = FALSE)) < "3.22.0",
12+
"QGIS version is older than 3.22.0"
13+
)
14+
15+
capture.output({
16+
expect_message(
17+
qgis_version(debug = TRUE),
18+
glue("Using.+{getNamespaceVersion('qgisprocess')}")
19+
)
20+
expect_message(qgis_version(debug = TRUE), "PROJ version")
21+
expect_message(qgis_version(debug = TRUE), "EPSG ")
22+
})
23+
})
24+
25+
test_that("qgis_query_version() works", {
26+
skip_if_not(has_qgis())
27+
28+
expect_match(qgis_query_version(), "^\\d{1,2}\\.\\d+.*-.+")
29+
})
30+
31+
test_that("qgis_query_version() works for development versions of QGIS", {
32+
skip_if_not(has_qgis())
33+
qversion <- qgis_query_version()
34+
skip_if_not(
35+
stringr::str_detect(
36+
qversion,
37+
"^\\d{1,2}\\.\\d*[13579][\\.-]"
38+
),
39+
paste("QGIS version", qversion, "is not a development version.")
40+
)
41+
42+
expect_match(
43+
qversion,
44+
"^\\d{1,2}\\.\\d+.*-\\p{L}+, development state ([0-9a-f]{7,}|unclear:.+)",
45+
perl = TRUE
46+
)
47+
48+
if (stringr::str_detect(qversion, ".+development state unclear:.+")) {
49+
expect_warning(qgis_query_version(), "version identifier")
50+
}
51+
})

0 commit comments

Comments
 (0)