Closed cesarkero closed 2 years ago
I have this question too. I intend to use QNEAT3
It seems that the qgis_process
command (backend of R package qgisprocess
) currently doesn't yet support or recognize every plugin. I wonder how this is regarded by QGIS - seems to have relations with https://github.com/qgis/QGIS/issues/37989 and https://github.com/qgis/QGIS/issues/41218.
Having installed 'Visibility Analysis', just a limited subset of installed or active QGIS plugins are enlisted:
> cat(qgis_run("--help")$stdout)
QGIS Processing Executor - 3.22.3-Białowieża 'Białowieża' (3.22.3-Białowieża)
Usage: /usr/bin/qgis_process.bin [--help] [--version] [--json] [--verbose] [command] [algorithm id or path to model file] [parameters]
Options:
--help or -h Output the help
--version or -v Output all versions related to QGIS Process
--json Output results as JSON objects
--verbose Output verbose logs
Available commands:
plugins list available and active plugins
plugins enable enables an installed plugin. The plugin name must be specified, e.g. "plugins enable cartography_tools"
plugins disable disables an installed plugin. The plugin name must be specified, e.g. "plugins disable cartography_tools"
list list all available processing algorithms
help show help for an algorithm. The algorithm id or a path to a model file must be specified.
run runs an algorithm. The algorithm id or a path to a model file and parameter values must be specified. Parameter values are specified after -- with PARAMETER=VALUE syntax. Ordered list values for a parameter can be created by specifying the parameter multiple times, e.g. --LAYERS=layer1.shp --LAYERS=layer2.shp
If required, the ellipsoid to use for distance and area calculations can be specified via the "--ELLIPSOID=name" argument.
If required, an existing QGIS project to use during the algorithm execution can be specified via the "--PROJECT_PATH=path" argument.
> cat(qgis_run("plugins")$stdout)
Available plugins
(* indicates loaded plugins which implement Processing providers)
* grassprovider
* processing
* sagaprovider
otbprovider
> qgis_run("plugins enable 'Visibility Analysis'")
Error in processx::run(path, args, ...) :
System command 'qgis_process' failed, exit status: 1, stderr:
E> qt5ct: using qt5ct plugin
E> Command plugins enable 'Visibility Analysis' not known!
Type .Last.error.trace to see where the error occurred
> qgis_run("plugins enable visibility_analysis")
Error in processx::run(path, args, ...) :
System command 'qgis_process' failed, exit status: 1, stderr:
E> qt5ct: using qt5ct plugin
E> Command plugins enable visibility_analysis not known!
Type .Last.error.trace to see where the error occurred
It seems that qgis_process is only listing core plugins included in default QGIS install. Looks like it does not look in user profiles where installed plugins are located.
I'm unsure what's the specific condition for plugin uptake. In the qgis_process
help, cartography_tools
is cited as an example but on my PC it wasn't installed yet. In the GUI, the plugin is called 'Cartography Tools'. It turns out, after installing the plugin in QGIS GUI, this plugin is indeed seen by qgis_process
:
$ qgis_process plugins
qt5ct: using qt5ct plugin
Available plugins
(* indicates loaded plugins which implement Processing providers)
* cartography_tools
* grassprovider
* processing
* sagaprovider
otbprovider
The difference between cartography_tools
and Cartography Tools
is pretty much plugin id, as used by QGIS internally, and plugin name, which is seen by users. References to plugin is usually done by plugin id.
I will try to dig in to see what is the issue here.
The problem here is actually in the plugin itself. The way the author loads the algorithms in probably not compatible with qgis_process. I have raised an issue zoran-cuckovic/QGIS-visibility-analysis#59
References to plugin is usually done by plugin id.
Thanks!
In the QGIS Python console, it appears the ids can be retrieved as follows (from https://gis.stackexchange.com/a/126531):
>>> qgis.utils.available_plugins
['geopunt4Qgis', 'ViewshedAnalysis', 'cartography_tools', 'quick_map_services', 'grassprovider', 'processing', 'sagaprovider', 'db_manager', 'MetaSearch', 'otbprovider']
There is actually more then one issue with the plugin, fortunately all are fairly simple to solve. But all together cause that the the plugin can be loaded from QGIS GUI but not from qgis_process.
Thanks to the effort by @JanCaha (https://github.com/zoran-cuckovic/QGIS-visibility-analysis/issues/59) this has been solved quite some time ago in the plugin.
For now (but see #93), and at its current version (ViewshedAnalysis
1.8), the plugin can be loaded (if not yet loaded) and its algorithms accessed as follows:
library(qgisprocess)
#> Using 'qgis_process' in the system PATH.
#> QGIS version: 3.26.3-Buenos Aires
#> Configuration loaded from '~/.cache/R-qgisprocess/cache-0.0.0.9000.rds'
#> Run `qgis_configure(use_cached_data = TRUE)` to reload cache and get more details.
#> >>> If you need another installed QGIS version, run `qgis_configure()`;
#> see its documentation if you need to preset the path of qgis_process.
#> - Using JSON for input serialization.
#> - Using JSON for output serialization.
qgis_providers() # plugin is missing
#> provider provider_title
#> 1 3d QGIS (3D)
#> 2 cartographytools Cartography tools
#> 7 gdal GDAL
#> 63 grass7 GRASS
#> 367 native QGIS (native c++)
#> 609 otb OTB
#> 718 qgis QGIS
#> 768 saga SAGA
# is plugin available?
cat(qgis_run("plugins")$stdout)
#> Available plugins
#> (* indicates loaded plugins which implement Processing providers)
#>
#> ViewshedAnalysis
#> * cartography_tools
#> * grassprovider
#> * processing
#> * sagaprovider
#> * otbprovider
# enable plugin:
cat(qgis_run(c("plugins", "enable", "ViewshedAnalysis"))$stdout)
#> Enabling plugin: "ViewshedAnalysis"
#> Enabled ViewshedAnalysis (Visibility Analysis)
#>
#> Available plugins
#> (* indicates enabled plugins which implement Processing providers)
#>
#> * ViewshedAnalysis
#> * cartography_tools
#> * grassprovider
#> * processing
#> * sagaprovider
#> * otbprovider
qgis_providers() # this just list plugins known in qgisprocess's cache
#> provider provider_title
#> 1 3d QGIS (3D)
#> 2 cartographytools Cartography tools
#> 7 gdal GDAL
#> 63 grass7 GRASS
#> 367 native QGIS (native c++)
#> 609 otb OTB
#> 718 qgis QGIS
#> 768 saga SAGA
qgis_configure() # update the cache
#> getOption('qgisprocess.path') was not found.
#> Sys.getenv('R_QGISPROCESS_PATH') was not found.
#> Trying 'qgis_process' on PATH...
#> Success!
#> QGIS version: 3.26.3-Buenos Aires
#> Saving configuration to '~/.cache/R-qgisprocess/cache-0.0.0.9000.rds'
#> Metadata of 1137 algorithms queried and stored in cache.
#> Run `qgis_algorithms()` to see them.
#> - Using JSON for input serialization.
#> - Using JSON for output serialization.
qgis_providers()
#> # A tibble: 9 × 2
#> provider provider_title
#> <chr> <chr>
#> 1 3d QGIS (3D)
#> 2 cartographytools Cartography tools
#> 3 gdal GDAL
#> 4 grass7 GRASS
#> 5 native QGIS (native c++)
#> 6 otb OTB
#> 7 qgis QGIS
#> 8 saga SAGA
#> 9 visibility Visibility analysis
# available algorithms per provider:
table(qgis_algorithms()$provider_id) |> as.matrix()
#> [,1]
#> 3d 1
#> cartographytools 5
#> gdal 56
#> grass7 304
#> native 242
#> otb 109
#> qgis 50
#> saga 366
#> visibility 4
Created on 2022-10-20 by the reprex package (v2.0.1)
With relation to QNEAT3 (https://github.com/paleolimbot/qgisprocess/issues/73#issuecomment-1019114800), this plugin seems currently not supported by qgis_process
. For that to happen, it should be specified as a QGIS Processing provider IIUC.
After installing the plugin, the qgis_process
command cannot see it indeed:
> cat(qgis_run("plugins")$stdout)
Available plugins
(* indicates loaded plugins which implement Processing providers)
* ViewshedAnalysis
* cartography_tools
* grassprovider
* processing
* sagaprovider
* otbprovider
The plugin is not correctly initialized. The processing is setted up in initGui() of the plugin but it should be done in initProcessing() instead. That means that processing tools will only be available if Gui of QGIS exists ;)
In https://github.com/root676/QNEAT3/issues/57 this has been solved for QNEAT3 :rocket: ! After installing current master of QNEAT3 in QGIS and reconfiguring qgisprocess (qgis_configure()
), its algorithms are available to qgisprocess:
> qgis_configure()
getOption('qgisprocess.path') was not found.
Sys.getenv('R_QGISPROCESS_PATH') was not found.
Trying 'qgis_process' on PATH...
Success!
QGIS version: 3.26.3-Buenos Aires
Saving configuration to '~/.cache/R-qgisprocess/cache-0.0.0.9000.rds'
Metadata of 1151 algorithms queried and stored in cache.
Run `qgis_algorithms()` to see them.
- Using JSON for input serialization.
- Using JSON for output serialization.
>
> subset(qgis_algorithms(), provider == "qneat3")[,1:3]
# A tibble: 14 × 3
provider provider_title algorithm
<chr> <chr> <chr>
1 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:OdMatrixFromLayersAsLines
2 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:OdMatrixFromLayersAsTable
3 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:OdMatrixFromPointsAsCsv
4 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:OdMatrixFromPointsAsLines
5 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:OdMatrixFromPointsAsTable
6 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:isoareaascontoursfromlayer
7 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:isoareaascontoursfrompoint
8 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:isoareaasinterpolationfromlayer
9 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:isoareaasinterpolationfrompoint
10 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:isoareaaspointcloudfromlayer
11 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:isoareaaspointcloudfrompoint
12 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:isoareaaspolygonsfromlayer
13 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:isoareaaspolygonsfrompoint
14 qneat3 QNEAT3 - Qgis Network Analysis Toolbox qneat3:shortestpathpointtopoint
How can be added the plugins to the algorithm list ? Exactly this:
visibility:Viewshed
...