r-spatial / RQGIS3

GNU Lesser General Public License v3.0
69 stars 19 forks source link

unable to call grass7:v.generalize #7

Closed BastienFR closed 5 years ago

BastienFR commented 5 years ago

I was a user of RQGIS but just started using RQGIS3. I've been having problem using the GRASS process. In this example, I use grass7:v.generalize but I also tried grass7:v.buffer with the same error.

RE:

library("RQGIS3")
library("raster")
library("rgdal")

# download German administrative areas 
ger = getData(name = "GADM", country = "DEU", level = 1) 
ger = spTransform(ger, CRS("+proj=cass +lat_0=52.41864827777778 +lon_0=13.62720366666667 +x_0=40000 +y_0=10000 +ellps=bessel +datum=potsdam +units=m +no_defs "))

set_env("C:/OSGeo4W64")

out = run_qgis(alg = "grass7:v.generalize",
               input=ger,
               output = "d:/temp/test_simple_grass.shp",
               error = "d:/temp/test_simple_grass_error.shp",
               threshold = "1",
               load_output = TRUE)

gives me:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  QgsProcessingException: There were errors executing the algorithm. 

I can run grass7:v.generalize no problem directly in QGIS. Is it a bug or it's only on my side?

I just updated my OSGEO4W, however I'm confuse which version of QGIS it's using on my computer. I have: 2.18.16, 2.18.23, 3.4.6, 3.6.1, 3.7.0.

my sessioninfo:

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 14393)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] here_0.1          RQGIS3_1.0.1.9000 reticulate_1.12   rgdal_1.4-3       raster_2.8-19     sp_1.3-1         

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1            pillar_1.3.1          compiler_3.5.1        later_0.8.0           base64enc_0.1-3       class_7.3-14         
 [7] tools_3.5.1           digest_0.6.18         tibble_2.1.1          satellite_1.0.1       jsonlite_1.6          lattice_0.20-35      
[13] viridisLite_0.3.0     pkgconfig_2.0.2       rlang_0.3.4           png_0.1-7             Matrix_1.2-14         rstudioapi_0.8.0.9000
[19] shiny_1.1.0           DBI_1.0.0             crosstalk_1.0.0       parallel_3.5.1        e1071_1.7-1           stringr_1.4.0        
[25] rgeos_0.4-2           hms_0.4.2             htmlwidgets_1.3       rprojroot_1.3-2       stats4_3.5.1          classInt_0.3-1       
[31] leaflet_2.0.2         grid_3.5.1            webshot_0.5.1         sf_0.7-3              R6_2.4.0              readr_1.3.1          
[37] magrittr_1.5          backports_1.1.2       scales_1.0.0          codetools_0.2-15      promises_1.0.1        htmltools_0.3.6      
[43] units_0.6-2           mime_0.6              xtable_1.8-3          colorspace_1.4-1      httpuv_1.5.1          mapview_2.6.0        
[49] stringi_1.4.3         munsell_0.5.0         crayon_1.3.4         
jannes-m commented 5 years ago

Running the grass7:v.generalize geoalgorithm in the QGIS GUI also tells me that there is no output, so I guess this might be the problem. However, the buffer function works for me:

library("sf")
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library("RQGIS3")
#> Loading required package: reticulate
qgis_session_info()
#> Trying to find QGIS in C:/OSGEO4~1
#> $gdal
#> [1] "2.4.1"
#> 
#> $grass7
#> [1] FALSE
#> 
#> $qgis_version
#> [1] "3.4.7-Madeira"
#> 
#> $saga
#> [1] "2.3.2"
data("random_points")
params = get_args_man("grass7:v.buffer")
#> Choosing default values for following parameters:
#> type: 0
#> GRASS_OUTPUT_TYPE_PARAMETER: 0
#> See get_options('grass7:v.buffer') for all available options.
params$input = random_points
params$distance = 100
params$output = file.path(tempdir(), "buf.shp")
out = run_qgis("grass7:v.buffer", params = params, load_output = TRUE)
#> $output
#> [1] "C:/Users/janne/AppData/Local/Temp/Rtmp2VWOH7/buf.shp"
plot(st_geometry(out))

Created on 2019-04-23 by the reprex package (v0.2.1)

BastienFR commented 5 years ago

Hello, sorry to reopenned that but I really think it's a bug. Trying your v.buffer example and playing around I've found to that the only way to get my code to work is to add a qgis_session_info() call before it:

So, lets start with the fail example. The basic v.generalise, alone fails:

#Restarting R session...

library("RQGIS3")
library("raster")
library("rgdal")

# download German administrative areas 
ger = getData(name = "GADM", country = "DEU", level = 1) 
ger = spTransform(ger, CRS("+proj=cass +lat_0=52.41864827777778 +lon_0=13.62720366666667 +x_0=40000 +y_0=10000 +ellps=bessel +datum=potsdam +units=m +no_defs "))

set_env("C:/OSGeo4W64")
#$`root`
#[1] "C:/OSGeo4W64"

#$qgis_prefix_path
#[1] "C:/OSGeo4W64/apps/qgis-ltr"

#$python_plugins
#[1] "C:/OSGeo4W64/apps/qgis-ltr/python/plugins"

#get_usage(alg = "grass7:v.generalize")
#get_args_man(alg = "grass7:v.generalize")

out = run_qgis(alg = "grass7:v.generalize",
                input=ger,
                output = "d:/temp/test_simple_grass.shp",
                error = "d:/temp/test_simple_grass_error.shp",
                threshold = "1",
                load_output = TRUE)
 Error in py_call_impl(callable, dots$args, dots$keywords) : 
  QgsProcessingException: There were errors executing the algorithm. 

However, if I add the qgis_session_info() before my v.generalize, it work:

qgis_session_info()
#$`gdal`
#[1] "2.4.1"

#$grass7
#[1] FALSE

#$qgis_version
#[1] "3.4.6-Madeira"

#$saga
#[1] "2.3.2"

out = run_qgis(alg = "grass7:v.generalize",
                input=ger,
                output = "d:/temp/test_simple_grass.shp",
                error = "d:/temp/test_simple_grass_error.shp",
                threshold = "1",
                load_output = TRUE)

#$`error`
#[1] "d:/temp/test_simple_grass_error.shp"

#$output
#[1] "d:/temp/test_simple_grass.shp"

I thought that the set_env("C:/OSGeo4W64") was the one preparing the session and that qgis_session_info() was only used to get information on that session, but it seems qgis_session_info() is actually starting something useful for the code. Is it normal? If it's the case, it should be stated in your tutorial.