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

make multiple input arguments work #33

Merged
merged 6 commits into from
Dec 17, 2020
Merged

make multiple input arguments work #33

merged 6 commits into from
Dec 17, 2020

Conversation

jannes-m
Copy link
Collaborator

Thanks to qgis/QGIS#40287 multiple input arguments are now accepted by qgisprocess. This PR slighly adjusts qgis_run_algorithm() to make them also work from within R. I have already successfully tested this using the QGIS nightly build (3.17.0-Master). However, so far this only works if only one of the arguments is of type multipleinput. I am not sure if there are QGIS geoalgorithms which have two or more arguments of type multipleinput.

Pls note that when using the QGIS nightly version, the first line of qgis_run() returns again the current working directory under Windows, hence, it would be desirable to adjust qgis_configure() accordingly (see #32).

@paleolimbot
Copy link
Collaborator

I think the failures on the CMD check on linux are real (this is the only platform with a QGIS install that is tested). Could you also add a test with at least one algorithm (preferably a qgis:native one) that uses this input type? You can look here for one: https://github.com/paleolimbot/qgisprocess/blob/master/inst/algorithms/arguments.csv

I'll be a more active maintainer starting next week!

@jannes-m
Copy link
Collaborator Author

I wasn't aware that there are already so many tests, excellent work! Will run them from now on every time I do a commit (ok, that is a lie but I promise to run them frequently -:)).

@jannes-m
Copy link
Collaborator Author

R-CMD ubuntu-20.04 (release, ubuntu) still fails due to the multiple input test. The test will pass as soon as the next QGIS version is released.

@paleolimbot
Copy link
Collaborator

Awesome! For now you can add skip("Requires recent QGIS") and I'll find a way to skip_if_not() based on QGIS version later on.

@paleolimbot paleolimbot merged commit 6e37851 into r-spatial:master Dec 17, 2020
@loreabad6
Copy link
Contributor

loreabad6 commented May 18, 2021

Hi all and thank you for the package! Just started with it yesterday and I am really enjoying it.

I have some doubts about this particular pull request. I arrived here after looking for a solution for #25, which is still open. I thought this PR would close that issue, and I actually can indeed pass multiple inputs to qgis_run_algorithm().
However, the input passed seems to always be the first one, at least for me.
I can illustrate with the example from the test in this PR:

library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(qgisprocess)
#> Using 'qgis_process' at 'C://OSGeo4W64/bin/qgis_process-qgis.bat'.
#> Run `qgis_configure()` for details.

v_1 = sf::read_sf(
  system.file("longlake/longlake.gpkg", package = "qgisprocess"))
v_2 = v_3 = v_1
v_2$geom = v_2$geom + 1000
sf::st_crs(v_2) = sf::st_crs(v_1)
v_3$geom = v_3$geom - 1000
sf::st_crs(v_3) = sf::st_crs(v_1)

I change here to .quiet = FALSE to show that the temporary files created are named different, but actually contain the same info (v_1).

out = qgis_run_algorithm("native:mergevectorlayers",
                         LAYERS = v_1, LAYERS = v_2, LAYERS = v_3,
                         .quiet = FALSE)
#> Argument `CRS` is unspecified (using QGIS default value).
#> Using `OUTPUT = qgis_tmp_vector()`
#> Running cmd.exe /c call "C://OSGeo4W64/bin/qgis_process-qgis.bat" run \
#>   "native:mergevectorlayers" \
#>   "--LAYERS=C:\Users\Lore\AppData\Local\Temp\RtmpKyiYWk\file37444af761c\file374445ff536a.gpkg" \
#>   "--LAYERS=C:\Users\Lore\AppData\Local\Temp\RtmpKyiYWk\file37444af761c\file37446dbe32f0.gpkg" \
#>   "--LAYERS=C:\Users\Lore\AppData\Local\Temp\RtmpKyiYWk\file37444af761c\file37441f69966.gpkg" \
#>   "--OUTPUT=C:\Users\Lore\AppData\Local\Temp\RtmpKyiYWk\file37444af761c\file374446b97add.gpkg"
#> The system cannot find the file C:\rtools40\Version.txt.
#> Traceback (most recent call last):
#>   File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 335, in _startPlugin
#>     plugins[packageName] = package.classFactory(iface)
#>   File "C:/Users/Lore/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\latlontools\__init__.py", line 3, in classFactory
#>     return LatLonTools(iface)
#>   File "C:/Users/Lore/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\latlontools\latLonTools.py", line 27, in __init__
#>     self.canvas = iface.mapCanvas()
#> AttributeError: 'NoneType' object has no attribute 'mapCanvas'
#> 
#> error starting plugin: latlontools
#> 
#> ----------------
#> Inputs
#> ----------------
#> 
#> LAYERS:  
#> OUTPUT:  C:\Users\Lore\AppData\Local\Temp\RtmpKyiYWk\file37444af761c\file374446b97add.gpkg
#> 
#> 
#> Taking destination CRS EPSG:26920 from layer
#> Setting output type to PolygonZ
#> Packaging layer 1/3: file374445ff536a
#> 0...10...20...30.Packaging layer 2/3: file37446dbe32f0
#> ..40...50...60..Packaging layer 3/3: file37441f69966
#> .70...80...90...100 - done.
#> 
#> ----------------
#> Results
#> ----------------
#> 
#> OUTPUT:  C:\Users\Lore\AppData\Local\Temp\RtmpKyiYWk\file37444af761c\file374446b97add.gpkg

The test does indeed pass because the tmp file has 3 rows, but they are the same feature.

tmp = sf::read_sf(qgis_output(out, "OUTPUT"))
testthat::expect_equal(nrow(tmp), 3)

If we draw it:

par(mfrow = c(1,3))
plot(v_1$geom, lwd = 2)
plot(v_2$geom, add = TRUE, lwd = 2)
plot(v_3$geom, add = TRUE, lwd = 2)

plot(tmp$geom, col = 'red')

plot(st_combine(rbind(v_1, v_2, v_3)), col = "blue")

I wonder if this was also caught in #31 where multiple inputs are tested here.

Thanks again for the great work!

Session Info
qgis_version()
#> [1] "3.18.3-Zürich"
sessionInfo()
#> R version 4.0.4 (2021-02-15)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19042)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.1252 
#> [2] LC_CTYPE=English_United States.1252   
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.1252    
#> 
#> attached base packages:
#>   [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>   [1] qgisprocess_0.0.0.9000 sf_0.9-8              
#> 
#> loaded via a namespace (and not attached):
#>   [1] Rcpp_1.0.6         pillar_1.5.1       compiler_4.0.4     highr_0.8         
#> [5] class_7.3-18       tools_4.0.4        testthat_3.0.2     digest_0.6.27     
#> [9] evaluate_0.14      lifecycle_1.0.0    tibble_3.1.0       debugme_1.1.0     
#> [13] pkgconfig_2.0.3    rlang_0.4.11       reprex_1.0.0       cli_2.3.1         
#> [17] DBI_1.1.1          rstudioapi_0.13    yaml_2.2.1         xfun_0.21         
#> [21] e1071_1.7-6        stringr_1.4.0      withr_2.4.1        dplyr_1.0.5       
#> [25] styler_1.3.2       knitr_1.31         generics_0.1.0     fs_1.5.0          
#> [29] vctrs_0.3.7        tidyselect_1.1.0   grid_4.0.4         classInt_0.4-3    
#> [33] rprojroot_2.0.2    glue_1.4.2         here_1.0.1         R6_2.5.0          
#> [37] processx_3.4.5     fansi_0.4.2        rmarkdown_2.7      purrr_0.3.4       
#> [41] callr_3.5.1        clipr_0.7.1        magrittr_2.0.1     units_0.7-1       
#> [45] backports_1.2.1    ps_1.6.0           ellipsis_0.3.1     htmltools_0.5.1.1 
#> [49] assertthat_0.2.1   KernSmooth_2.23-18 utf8_1.2.1         stringi_1.5.3     
#> [53] proxy_0.4-25       crayon_1.4.1 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants