-
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
Problem extracting output after using native:zonalstatistics
algorithm
#193
Comments
Thanks for reporting this @damianooldoni. Indeed the reported result is like this: > zonal_st
<Result of `qgis_run_algorithm("native:zonalstatistics", ...)`>
List of 1
$ INPUT_VECTOR: 'qgis_outputVector' chr "file16a8d6939f4fa_4970b7ba_1f37_4b5c_b0ca_81426615628a" You're actually hitting two different problems:
library(terra)
#> terra 1.7.65
library(sf)
#> Linking to GEOS 3.11.1, GDAL 3.6.4, PROJ 9.1.1; sf_use_s2() is TRUE
library(qgisprocess)
#> Attempting to load the package cache ...
#> Success!
#> QGIS version: 3.34.1-Prizren
#> Having access to 2084 algorithms from 19 QGIS processing providers.
#> Run `qgis_configure(use_cached_data = TRUE)` to reload cache and get more details.
# Download data
download.file("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_land_use_nara_2016_100m.tif", "20231214_land_use_nara_2016_100m.tif")
download.file("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_natura2000_protected_areas.gpkg", "20231214_natura2000_protected_areas.gpkg")
# Calculate zonal statistics
zonal_st <- qgis_run_algorithm("native:zonalstatistics",
INPUT_RASTER = "20231214_land_use_nara_2016_100m.tif",
COLUMN_PREFIX = "landuse_",
INPUT_VECTOR = "20231214_natura2000_protected_areas.gpkg",
STATISTICS = c("Majority", "Minority"))
#> Argument `RASTER_BAND` is unspecified (using QGIS default value).
qgis_result_args(zonal_st) |>
_$INPUT_VECTOR |>
read_sf() |> # or just read_sf("20231214_natura2000_protected_areas.gpkg")
st_drop_geometry() |>
dplyr::select(GEBCODE, landuse_minority, landuse_majority)
#> # A tibble: 38 × 3
#> GEBCODE landuse_minority landuse_majority
#> <chr> <dbl> <dbl>
#> 1 BE2100015 9 2
#> 2 BE2100016 6 1
#> 3 BE2100017 9 2
#> 4 BE2100019 9 2
#> 5 BE2100020 9 2
#> 6 BE2100024 6 2
#> 7 BE2100026 9 2
#> 8 BE2100040 9 2
#> 9 BE2100045 1 2
#> 10 BE2200028 9 2
#> # ℹ 28 more rows Created on 2023-12-20 with reprex v2.0.2 Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.3.2 (2023-10-31)
#> os Linux Mint 21.2
#> system x86_64, linux-gnu
#> ui X11
#> language nl_BE:nl
#> collate nl_BE.UTF-8
#> ctype nl_BE.UTF-8
#> tz Europe/Brussels
#> date 2023-12-20
#> pandoc 3.1.1 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> assertthat 0.2.1 2019-03-21 [3] CRAN (R 4.0.1)
#> class 7.3-22 2023-05-03 [3] RSPM (R 4.2.0)
#> classInt 0.4-10 2023-09-05 [3] RSPM (R 4.3.0)
#> cli 3.6.2 2023-12-11 [3] RSPM (R 4.3.0)
#> codetools 0.2-19 2023-02-01 [3] RSPM (R 4.2.0)
#> DBI 1.1.3 2022-06-18 [3] RSPM (R 4.2.0)
#> digest 0.6.33 2023-07-07 [3] RSPM (R 4.2.0)
#> dplyr 1.1.4 2023-11-17 [3] RSPM (R 4.3.0)
#> e1071 1.7-14 2023-12-06 [3] RSPM (R 4.3.0)
#> evaluate 0.23 2023-11-01 [3] RSPM (R 4.3.0)
#> fansi 1.0.6 2023-12-08 [3] RSPM (R 4.3.0)
#> fastmap 1.1.1 2023-02-24 [3] RSPM (R 4.2.0)
#> fs 1.6.3 2023-07-20 [3] RSPM (R 4.2.0)
#> generics 0.1.3 2022-07-05 [3] RSPM (R 4.2.0)
#> glue 1.6.2 2022-02-24 [3] RSPM (R 4.2.0)
#> htmltools 0.5.7 2023-11-03 [3] RSPM (R 4.3.0)
#> jsonlite 1.8.8 2023-12-04 [3] RSPM (R 4.3.0)
#> KernSmooth 2.23-22 2023-07-10 [3] RSPM (R 4.2.0)
#> knitr 1.45 2023-10-30 [3] RSPM (R 4.3.0)
#> lifecycle 1.0.4 2023-11-07 [3] RSPM (R 4.3.0)
#> magrittr 2.0.3 2022-03-30 [3] RSPM (R 4.2.0)
#> pillar 1.9.0 2023-03-22 [3] RSPM (R 4.2.0)
#> pkgconfig 2.0.3 2019-09-22 [3] CRAN (R 4.0.1)
#> processx 3.8.3 2023-12-10 [3] RSPM (R 4.3.0)
#> proxy 0.4-27 2022-06-09 [3] RSPM (R 4.2.0)
#> ps 1.7.5 2023-04-18 [3] RSPM (R 4.3.0)
#> purrr 1.0.2 2023-08-10 [3] RSPM (R 4.2.0)
#> qgisprocess * 0.2.0 2023-12-20 [1] local
#> R.cache 0.16.0 2022-07-21 [3] RSPM (R 4.2.0)
#> R.methodsS3 1.8.2 2022-06-13 [3] RSPM (R 4.2.0)
#> R.oo 1.25.0 2022-06-12 [3] RSPM (R 4.2.0)
#> R.utils 2.12.3 2023-11-18 [3] RSPM (R 4.3.0)
#> R6 2.5.1 2021-08-19 [3] RSPM (R 4.2.0)
#> rappdirs 0.3.3 2021-01-31 [3] RSPM (R 4.2.0)
#> Rcpp 1.0.11 2023-07-06 [3] RSPM (R 4.2.0)
#> reprex 2.0.2 2022-08-17 [3] RSPM (R 4.2.0)
#> rlang 1.1.2 2023-11-04 [3] RSPM (R 4.3.0)
#> rmarkdown 2.25 2023-09-18 [3] RSPM (R 4.3.0)
#> rstudioapi 0.15.0 2023-07-07 [3] RSPM (R 4.2.0)
#> sessioninfo 1.2.2 2021-12-06 [3] RSPM (R 4.2.0)
#> sf * 1.0-15 2023-12-18 [1] CRAN (R 4.3.2)
#> stringi 1.8.3 2023-12-11 [3] RSPM (R 4.3.0)
#> stringr 1.5.1 2023-11-14 [3] RSPM (R 4.3.0)
#> styler 1.10.2 2023-08-29 [3] RSPM (R 4.2.0)
#> terra * 1.7-65 2023-12-15 [1] RSPM (R 4.3.2)
#> tibble 3.2.1 2023-03-20 [3] RSPM (R 4.3.0)
#> tidyselect 1.2.0 2022-10-10 [3] RSPM (R 4.2.0)
#> units 0.8-5 2023-11-28 [3] RSPM (R 4.3.0)
#> utf8 1.2.4 2023-10-22 [3] RSPM (R 4.3.0)
#> vctrs 0.6.5 2023-12-01 [3] RSPM (R 4.3.0)
#> withr 2.5.2 2023-10-30 [3] RSPM (R 4.3.0)
#> xfun 0.41 2023-11-01 [3] RSPM (R 4.3.0)
#> yaml 2.3.8 2023-12-11 [3] RSPM (R 4.3.0)
#>
#> [1] /home/floris/lib/R/library
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
|
Just discovered that So we shouldn't bother about getting this algorithm better in QGIS, or how to work around... You can see this in R too: library(qgisprocess)
#> Attempting to load the package cache ... Success!
#> QGIS version: 3.34.1-Prizren
#> Having access to 2084 algorithms from 19 QGIS processing providers.
#> Run `qgis_configure(use_cached_data = TRUE)` to reload cache and get more details.
library(dplyr, warn.conflicts = FALSE)
library(stringr)
qgis_algorithms() |>
filter(str_detect(algorithm_id, "^zonalstatistics")) |>
select(algorithm, deprecated)
#> # A tibble: 2 × 2
#> algorithm deprecated
#> <chr> <lgl>
#> 1 native:zonalstatistics TRUE
#> 2 native:zonalstatisticsfb FALSE Created on 2023-12-22 with reprex v2.0.2 Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.3.2 (2023-10-31)
#> os Linux Mint 21.2
#> system x86_64, linux-gnu
#> ui X11
#> language nl_BE:nl
#> collate nl_BE.UTF-8
#> ctype nl_BE.UTF-8
#> tz Europe/Brussels
#> date 2023-12-22
#> pandoc 3.1.1 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> assertthat 0.2.1 2019-03-21 [3] CRAN (R 4.0.1)
#> cli 3.6.2 2023-12-11 [3] RSPM (R 4.3.0)
#> digest 0.6.33 2023-07-07 [3] RSPM (R 4.2.0)
#> dplyr * 1.1.4 2023-11-17 [3] RSPM (R 4.3.0)
#> evaluate 0.23 2023-11-01 [3] RSPM (R 4.3.0)
#> fansi 1.0.6 2023-12-08 [3] RSPM (R 4.3.0)
#> fastmap 1.1.1 2023-02-24 [3] RSPM (R 4.2.0)
#> fs 1.6.3 2023-07-20 [3] RSPM (R 4.2.0)
#> generics 0.1.3 2022-07-05 [3] RSPM (R 4.2.0)
#> glue 1.6.2 2022-02-24 [3] RSPM (R 4.2.0)
#> htmltools 0.5.7 2023-11-03 [3] RSPM (R 4.3.0)
#> jsonlite 1.8.8 2023-12-04 [3] RSPM (R 4.3.0)
#> knitr 1.45 2023-10-30 [3] RSPM (R 4.3.0)
#> lifecycle 1.0.4 2023-11-07 [3] RSPM (R 4.3.0)
#> magrittr 2.0.3 2022-03-30 [3] RSPM (R 4.2.0)
#> pillar 1.9.0 2023-03-22 [3] RSPM (R 4.2.0)
#> pkgconfig 2.0.3 2019-09-22 [3] CRAN (R 4.0.1)
#> processx 3.8.3 2023-12-10 [3] RSPM (R 4.3.0)
#> ps 1.7.5 2023-04-18 [3] RSPM (R 4.3.0)
#> purrr 1.0.2 2023-08-10 [3] RSPM (R 4.2.0)
#> qgisprocess * 0.2.0 2023-12-20 [1] local
#> R.cache 0.16.0 2022-07-21 [3] RSPM (R 4.2.0)
#> R.methodsS3 1.8.2 2022-06-13 [3] RSPM (R 4.2.0)
#> R.oo 1.25.0 2022-06-12 [3] RSPM (R 4.2.0)
#> R.utils 2.12.3 2023-11-18 [3] RSPM (R 4.3.0)
#> R6 2.5.1 2021-08-19 [3] RSPM (R 4.2.0)
#> rappdirs 0.3.3 2021-01-31 [3] RSPM (R 4.2.0)
#> reprex 2.0.2 2022-08-17 [3] RSPM (R 4.2.0)
#> rlang 1.1.2 2023-11-04 [3] RSPM (R 4.3.0)
#> rmarkdown 2.25 2023-09-18 [3] RSPM (R 4.3.0)
#> rstudioapi 0.15.0 2023-07-07 [3] RSPM (R 4.2.0)
#> sessioninfo 1.2.2 2021-12-06 [3] RSPM (R 4.2.0)
#> stringi 1.8.3 2023-12-11 [3] RSPM (R 4.3.0)
#> stringr * 1.5.1 2023-11-14 [3] RSPM (R 4.3.0)
#> styler 1.10.2 2023-08-29 [3] RSPM (R 4.2.0)
#> tibble 3.2.1 2023-03-20 [3] RSPM (R 4.3.0)
#> tidyselect 1.2.0 2022-10-10 [3] RSPM (R 4.2.0)
#> utf8 1.2.4 2023-10-22 [3] RSPM (R 4.3.0)
#> vctrs 0.6.5 2023-12-01 [3] RSPM (R 4.3.0)
#> withr 2.5.2 2023-10-30 [3] RSPM (R 4.3.0)
#> xfun 0.41 2023-11-01 [3] RSPM (R 4.3.0)
#> yaml 2.3.8 2023-12-11 [3] RSPM (R 4.3.0)
#>
#> [1] /home/floris/lib/R/library
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
#>
#> ────────────────────────────────────────────────────────────────────────────── Will add a feature request here to throw a warning in the case of using a deprecated algorithm. |
See r-spatial/qgisprocess#193. Thanks @florisvdh Co-Authored-By: Floris Vanderhaeghe <[email protected]>
#198 has been handled. Current dev version of {qgisprocess} provides a warning while checking an algorithm if it is deprecated (triggered by library(qgisprocess)
#> Attempting to load the package cache ... Success!
#> QGIS version: 3.34.2-Prizren
#> Having access to 682 algorithms from 6 QGIS processing providers.
#> Run `qgis_configure(use_cached_data = TRUE)` to reload cache and get more details.
#> >>> Run `qgis_enable_plugins()` to enable 1 disabled plugin and access
#> its algorithms: otbprovider
# Download data
download.file("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_land_use_nara_2016_100m.tif", "20231214_land_use_nara_2016_100m.tif")
download.file("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_natura2000_protected_areas.gpkg", "20231214_natura2000_protected_areas.gpkg")
# Calculate zonal statistics
zonal_st <- qgis_run_algorithm("native:zonalstatistics",
INPUT_RASTER = "20231214_land_use_nara_2016_100m.tif",
COLUMN_PREFIX = "landuse_",
INPUT_VECTOR = "20231214_natura2000_protected_areas.gpkg",
STATISTICS = c("Majority", "Minority"))
#> Warning: Algorithm 'native:zonalstatistics' is deprecated and may be removed in a later QGIS version!
#> Currently using QGIS 3.34.2-Prizren.
#> Warning: Algorithm 'native:zonalstatistics' is deprecated and may be removed in a later QGIS version!
#> Currently using QGIS 3.34.2-Prizren.
#> Warning: Algorithm 'native:zonalstatistics' is deprecated and may be removed in a later QGIS version!
#> Currently using QGIS 3.34.2-Prizren.
#> Argument `RASTER_BAND` is unspecified (using QGIS default value).
#> Warning: Algorithm 'native:zonalstatistics' is deprecated and may be removed in a later QGIS version!
#> Currently using QGIS 3.34.2-Prizren. Created on 2024-01-06 with reprex v2.0.2 Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.3.2 (2023-10-31)
#> os Linux Mint 21.2
#> system x86_64, linux-gnu
#> ui X11
#> language nl_BE:nl
#> collate nl_BE.UTF-8
#> ctype nl_BE.UTF-8
#> tz Europe/Brussels
#> date 2024-01-06
#> pandoc 3.1.1 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> assertthat 0.2.1 2019-03-21 [3] RSPM (R 4.2.0)
#> cli 3.6.2 2023-12-11 [3] RSPM (R 4.3.0)
#> digest 0.6.33 2023-07-07 [3] RSPM (R 4.2.0)
#> evaluate 0.23 2023-11-01 [3] RSPM (R 4.3.0)
#> fansi 1.0.6 2023-12-08 [3] RSPM (R 4.3.0)
#> fastmap 1.1.1 2023-02-24 [3] RSPM (R 4.2.0)
#> fs 1.6.3 2023-07-20 [3] RSPM (R 4.2.0)
#> glue 1.6.2 2022-02-24 [3] RSPM (R 4.2.0)
#> htmltools 0.5.7 2023-11-03 [3] RSPM (R 4.3.0)
#> jsonlite 1.8.8 2023-12-04 [3] RSPM (R 4.3.0)
#> knitr 1.45 2023-10-30 [3] RSPM (R 4.3.0)
#> lifecycle 1.0.4 2023-11-07 [3] RSPM (R 4.3.0)
#> magrittr 2.0.3 2022-03-30 [3] RSPM (R 4.2.0)
#> pillar 1.9.0 2023-03-22 [3] RSPM (R 4.2.0)
#> pkgconfig 2.0.3 2019-09-22 [3] RSPM (R 4.2.0)
#> processx 3.8.3 2023-12-10 [3] RSPM (R 4.3.0)
#> ps 1.7.5 2023-04-18 [3] RSPM (R 4.3.0)
#> purrr 1.0.2 2023-08-10 [3] RSPM (R 4.2.0)
#> qgisprocess * 0.2.0.9003 2024-01-06 [1] local
#> R.cache 0.16.0 2022-07-21 [3] RSPM (R 4.2.0)
#> R.methodsS3 1.8.2 2022-06-13 [3] RSPM (R 4.2.0)
#> R.oo 1.25.0 2022-06-12 [3] RSPM (R 4.2.0)
#> R.utils 2.12.3 2023-11-18 [3] RSPM (R 4.3.0)
#> R6 2.5.1 2021-08-19 [3] RSPM (R 4.2.0)
#> rappdirs 0.3.3 2021-01-31 [3] RSPM (R 4.2.0)
#> reprex 2.0.2 2022-08-17 [3] RSPM (R 4.2.0)
#> rlang 1.1.2 2023-11-04 [3] RSPM (R 4.3.0)
#> rmarkdown 2.25 2023-09-18 [3] RSPM (R 4.3.0)
#> rstudioapi 0.15.0 2023-07-07 [3] RSPM (R 4.2.0)
#> sessioninfo 1.2.2 2021-12-06 [3] RSPM (R 4.2.0)
#> stringi 1.8.3 2023-12-11 [3] RSPM (R 4.3.0)
#> stringr 1.5.1 2023-11-14 [3] RSPM (R 4.3.0)
#> styler 1.10.2 2023-08-29 [3] RSPM (R 4.2.0)
#> tibble 3.2.1 2023-03-20 [3] RSPM (R 4.3.0)
#> utf8 1.2.4 2023-10-22 [3] RSPM (R 4.3.0)
#> vctrs 0.6.5 2023-12-01 [3] RSPM (R 4.3.0)
#> withr 2.5.2 2023-10-30 [3] RSPM (R 4.3.0)
#> xfun 0.41 2023-11-01 [3] RSPM (R 4.3.0)
#> yaml 2.3.8 2023-12-11 [3] RSPM (R 4.3.0)
#>
#> [1] /home/floris/lib/R/library
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
#>
#> ────────────────────────────────────────────────────────────────────────────── |
This is used internally to avoid producing the same warning multiple times in one user call. Following code was used in testing interactively (from #193 (comment)): library(qgisprocess) download.file("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_land_use_nara_2016_100m.tif", "20231214_land_use_nara_2016_100m.tif") download.file("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_natura2000_protected_areas.gpkg", "20231214_natura2000_protected_areas.gpkg") zonal_st <- qgis_run_algorithm("native:zonalstatistics", INPUT_RASTER = "20231214_land_use_nara_2016_100m.tif", COLUMN_PREFIX = "landuse_", INPUT_VECTOR = "20231214_natura2000_protected_areas.gpkg", STATISTICS = c("Majority", "Minority")) qgis_show_help("native:zonalstatistics") qgis_get_description("native:zonalstatistics") qgis_get_argument_specs("native:zonalstatistics") qgis_get_output_specs("native:zonalstatistics") qgis_function("native:zonalstatistics")
Things to check beforehand
Are QGIS plugins the cause?
The problem remains with all plugins disabled.
Description of the observed problem
Hi 👋
During the last coding club (see slide 23), I wrote this exercise:
However, nobody could solve (I neither) it as we didn't know how to extract the output generated by
native:zonalstatistics
algorithm. I hoped the solution could come from a participant, but unfortunately nobody succeeded it.The problem seems to be: how to extract the results?
I thought it could be possible to transform the output into a spatial vector object. Notice also that the arg
OUTPUT
is not allowed:Thanks!
Minimal reproducible example
Backend versions
QGIS plugin state
R session info
Additional context
No response
The text was updated successfully, but these errors were encountered: