Skip to content
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

Closed
2 tasks done
damianooldoni opened this issue Dec 20, 2023 · 3 comments
Closed
2 tasks done
Labels

Comments

@damianooldoni
Copy link

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:

Let's do some zonal statistics: calculate the most and the least occurring land use category in each of the Natura2000 protected areas.

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:

> qgis_get_output_specs("native:zonalstatistics")
# A tibble: 1 × 3
  name         description      qgis_output_type
  <chr>        <chr>            <chr>           
1 INPUT_VECTOR Zonal statistics outputVector

Thanks!

Minimal reproducible example

library(terra)
library(sf)
library(qgisprocess)

# Read data
land_use <- terra::rast("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_land_use_nara_2016_100m.tif")
prot_areas <- sf::st_read("https://github.com/inbo/coding-club/raw/main/data/20231214/20231214_natura2000_protected_areas.gpkg")

# Calculate zonal statistics
zonal_st <- qgis_run_algorithm("native:zonalstatistics",
                        INPUT_RASTER = land_use,
                        RASTER_BAND = 1,
                        INPUT_VECTOR = prot_areas,
                        STATISTICS = c("Majority", "Minority")) # Majority, Minority

# Extract output
zonal_sf_output <- qgis_extract_output(zonal_st, "INPUT_VECTOR")
zonal_st <- sf::st_as_sf(zonal_sf_output)
Error: Cannot open "file4124344879d_01efa7f7_4d83_47ba_94ac_ae2752b8eaf2"; The file doesn't seem to exist.

Backend versions

> qgis_version(query = TRUE, debug = TRUE)
[1] "3.30.3-'s-Hertogenbosch"

Versions reported by 'qgis_process':
------------------------------------
QGIS 3.30.3-'s-Hertogenbosch ''s-Hertogenbosch' (2411cec1)
QGIS code revision 2411cec1
Qt version 5.15.3
Python version 3.9.5
GDAL/OGR version 3.7.0
PROJ version 9.2.0
EPSG Registry database version v10.082 (2023-02-06)
GEOS version 3.11.2-CAPI-1.17.2
SQLite version 3.41.1
OS Windows 10 Version 2009

QGIS plugin state

> qgis_plugins(query = TRUE)
# A tibble: 3 × 2
  name          enabled
  <chr>         <lgl>  
1 grassprovider TRUE   
2 otbprovider   TRUE   
3 processing    TRUE   

R session info

> sessioninfo::session_info()
─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.0 (2023-04-21 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  Dutch_Belgium.utf8
 ctype    Dutch_Belgium.utf8
 tz       Europe/Brussels
 date     2023-12-20
 rstudio  2023.03.1+446 Cherry Blossom (desktop)
 pandoc   2.19.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 assertthat  * 0.2.1   2019-03-21 [1] CRAN (R 4.3.0)
 bit           4.0.5   2022-11-15 [1] CRAN (R 4.3.0)
 bit64         4.0.5   2020-08-30 [1] CRAN (R 4.3.0)
 class         7.3-22  2023-05-03 [2] CRAN (R 4.3.0)
 classInt      0.4-10  2023-09-05 [1] CRAN (R 4.3.1)
 cli           3.6.1   2023-03-23 [1] CRAN (R 4.3.0)
 clisymbols    1.2.0   2017-05-21 [1] CRAN (R 4.3.0)
 codetools     0.2-19  2023-02-01 [2] CRAN (R 4.3.0)
 colorspace    2.1-0   2023-01-23 [1] CRAN (R 4.3.0)
 crayon        1.5.2   2022-09-29 [1] CRAN (R 4.3.0)
 crul          1.4.0   2023-05-17 [1] CRAN (R 4.3.0)
 curl          5.1.0   2023-10-02 [1] CRAN (R 4.3.2)
 data.table    1.14.8  2023-02-17 [1] CRAN (R 4.3.0)
 DBI           1.1.3   2022-06-18 [1] CRAN (R 4.3.0)
 digest        0.6.33  2023-07-07 [1] CRAN (R 4.3.1)
 dplyr       * 1.1.3   2023-09-03 [1] CRAN (R 4.3.0)
 e1071         1.7-13  2023-02-01 [1] CRAN (R 4.3.0)
 evaluate      0.23    2023-11-01 [1] CRAN (R 4.3.2)
 fansi         1.0.5   2023-10-08 [1] CRAN (R 4.3.2)
 fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.3.0)
 fortunes      1.5-4   2016-12-29 [1] CRAN (R 4.3.0)
 generics      0.1.3   2022-07-05 [1] CRAN (R 4.3.0)
 ggplot2       3.4.4   2023-10-12 [1] CRAN (R 4.3.2)
 glue          1.6.2   2022-02-24 [1] CRAN (R 4.3.0)
 gtable        0.3.4   2023-08-21 [1] CRAN (R 4.3.1)
 here        * 1.0.1   2020-12-13 [1] CRAN (R 4.3.0)
 hms           1.1.3   2023-03-21 [1] CRAN (R 4.3.0)
 htmltools     0.5.7   2023-11-03 [1] CRAN (R 4.3.2)
 httpcode      0.3.0   2020-04-10 [1] CRAN (R 4.3.0)
 httr          1.4.7   2023-08-15 [1] CRAN (R 4.3.1)
 jsonlite      1.8.7   2023-06-29 [1] CRAN (R 4.3.0)
 KernSmooth    2.23-22 2023-07-10 [2] CRAN (R 4.3.1)
 knitr         1.45    2023-10-30 [1] CRAN (R 4.3.2)
 lazyeval      0.2.2   2019-03-15 [1] CRAN (R 4.3.0)
 lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.3.0)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.0)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.3.0)
 oai           0.4.0   2022-11-10 [1] CRAN (R 4.3.0)
 pillar        1.9.0   2023-03-22 [1] CRAN (R 4.3.0)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.3.0)
 plyr          1.8.9   2023-10-02 [1] CRAN (R 4.3.2)
 processx      3.8.2   2023-06-30 [1] CRAN (R 4.3.0)
 proxy         0.4-27  2022-06-09 [1] CRAN (R 4.3.0)
 ps            1.7.5   2023-04-18 [1] CRAN (R 4.3.0)
 purrr       * 1.0.2   2023-08-10 [1] CRAN (R 4.3.1)
 qgisprocess * 0.1.0   2023-08-17 [1] CRAN (R 4.3.1)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.3.0)
 rappdirs      0.3.3   2021-01-31 [1] CRAN (R 4.3.0)
 Rcpp          1.0.11  2023-07-06 [1] CRAN (R 4.3.1)
 readr       * 2.1.4   2023-02-10 [1] CRAN (R 4.3.0)
 rgbif       * 3.7.8   2023-09-11 [1] CRAN (R 4.3.1)
 rlang         1.1.2   2023-11-04 [1] CRAN (R 4.3.2)
 rmarkdown     2.25    2023-09-18 [1] CRAN (R 4.3.1)
 rprojroot     2.0.4   2023-11-05 [1] CRAN (R 4.3.0)
 rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.3.1)
 scales        1.2.1   2022-08-20 [1] CRAN (R 4.3.0)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.0)
 sf          * 1.0-14  2023-07-11 [1] CRAN (R 4.3.1)
 stringi       1.7.12  2023-01-11 [1] CRAN (R 4.3.0)
 stringr       1.5.0   2022-12-02 [1] CRAN (R 4.3.0)
 terra       * 1.7-55  2023-10-13 [1] CRAN (R 4.3.2)
 tibble        3.2.1   2023-03-20 [1] CRAN (R 4.3.0)
 tidylog     * 1.0.2   2020-07-03 [1] CRAN (R 4.3.0)
 tidyr         1.3.0   2023-01-24 [1] CRAN (R 4.3.0)
 tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.3.0)
 triebeard     0.4.1   2023-03-04 [1] CRAN (R 4.3.0)
 tzdb          0.4.0   2023-05-12 [1] CRAN (R 4.3.0)
 units         0.8-4   2023-09-13 [1] CRAN (R 4.3.1)
 urltools      1.7.3   2019-04-14 [1] CRAN (R 4.3.0)
 utf8          1.2.4   2023-10-22 [1] CRAN (R 4.3.2)
 vctrs         0.6.4   2023-10-12 [1] CRAN (R 4.3.2)
 vroom         1.6.4   2023-10-02 [1] CRAN (R 4.3.2)
 whisker       0.4.1   2022-12-05 [1] CRAN (R 4.3.0)
 withr         2.5.2   2023-10-30 [1] CRAN (R 4.3.2)
 xfun          0.41    2023-11-01 [1] CRAN (R 4.3.2)
 xml2          1.3.5   2023-07-06 [1] CRAN (R 4.3.1)
 yaml          2.3.7   2023-01-23 [1] CRAN (R 4.3.0)

 [1] C:/R/library
 [2] C:/R/R-4.3.0/library

Additional context

No response

@florisvdh florisvdh added the QGIS label Dec 20, 2023
@florisvdh
Copy link
Member

florisvdh commented Dec 20, 2023

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:

  1. qgis_process doesn't seem to handle remote layers qgis/QGIS#54264 (did your reprex run successfully?); it should be handled quite soon at the QGIS side. I.e. remote sources are not yet handled by the qgis_process backend.
    • This applies specifically to the terra part, since it still passes the URL from the terra object to qgis_process (so I had to first download locally, then read with terra to make your code work).
    • For the sf part, in the background the R object is written first as GPKG before passing this to qgis_process, as this R object has no pointer to its source file.
    • Note that just passing the data file path is more efficient than passing R object, unless one has updated the object in R which makes it unique (then it makes more sense to pass R objects really: they get written to a temporary file, then read by qgis_process).
  2. The problem that you report is that the algorithm outputs a layer_id variable rather than the path.
    • The INPUT_VECTOR file is overwritten by this algorithm (and not reported in the result), but the extra complication here is that it is gone. qgis_result_args(zonal_st)$INPUT_VECTOR will show the path to the tempfile that was written as input argument for qgis_process; however qgis_run_algorithm() cleans all temporarily written input files once the function exits. So in fact here the temporary file contained the solution, and was destroyed subsequently. The workaround for this specific algorithm is obvious, by using an explicit file path.
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 info
sessioninfo::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
#> 
#> ──────────────────────────────────────────────────────────────────────────────
  • however it would be more appropriate to either:
    • use a proper OUTPUT argument. And this is what native:zonalstatisticsfb provides (mind the fb suffix), so I guess overwriting INPUT_VECTOR is the deliberate aim of native:zonalstatistics. So using native:zonalstatisticsfb is a more direct way of answering the question.
    • in the case of native:zonalstatistics: return the path to the used INPUT_VECTOR file, not a layer id. This is an idea for an issue at QGIS ; I plan to point it out.

@florisvdh
Copy link
Member

Just discovered that native:zonalstatistics is deprecated! (qgis/QGIS#55692 (comment))

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 info
sessioninfo::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.

@florisvdh
Copy link
Member

#198 has been handled. Current dev version of {qgisprocess} provides a warning while checking an algorithm if it is deprecated (triggered by qgis_run_algorithms(), qgis_show_help() and others).

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 info
sessioninfo::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
#> 
#> ──────────────────────────────────────────────────────────────────────────────

florisvdh added a commit that referenced this issue Jan 9, 2024
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants