Open paleolimbot opened 2 years ago
Any progress on this issue? I've been making some corrections that might be useful, do you want to test them before doing the PR? Please check my gavg712/qgisprocess/tree/project_path branch
Since a solution was applied to #75, this also seems to have solved this issue but only when no JSON input is used, as above. But for QGIS >= 3.23 JSON input is used as the default, and that gives an error (maybe related cause, maybe another problem).
oldopt <- options(qgisprocess.use_json_input = FALSE)
library(qgisprocess)
#> Using 'qgis_process' in the system PATH.
#> QGIS version: 3.26.1-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 output serialization.
curl::curl_download(
"https://gist.githubusercontent.com/paleolimbot/f2fa6f409c48c3d18fe5462fb29f8996/raw/3c1e14b7834c2175acbb6cb1b6f646906f9f89ed/test.qgs",
"test.qgs"
)
qgis_run_algorithm(
"native:printlayouttopdf",
LAYOUT = "Layout 1",
OUTPUT = "output.pdf",
PROJECT_PATH = "test.qgs"
)
#> Argument `LAYERS` is unspecified (using QGIS default value).
#> Argument `DPI` is unspecified (using QGIS default value).
#> Argument `FORCE_VECTOR` is unspecified (using QGIS default value).
#> Argument `GEOREFERENCE` is unspecified (using QGIS default value).
#> Argument `INCLUDE_METADATA` is unspecified (using QGIS default value).
#> Argument `DISABLE_TILED` is unspecified (using QGIS default value).
#> Argument `SIMPLIFY` is unspecified (using QGIS default value).
#> Using `TEXT_FORMAT = "Always Export Text as Paths (Recommended)"`
#> Argument `SEPARATE_LAYERS` is unspecified (using QGIS default value).
#> Running qgis_process --json run 'native:printlayouttopdf' '--LAYOUT=Layout 1' \
#> '--TEXT_FORMAT=0' '--OUTPUT=output.pdf' '--PROJECT_PATH=test.qgs'
#> qt5ct: using qt5ct plugin
#> Problem with OTB installation: OTB folder is not set.
#> <Result of `qgis_run_algorithm("native:printlayouttopdf", ...)`>
#> List of 1
#> $ OUTPUT: 'qgis_outputFile' chr "output.pdf"
file.exists("output.pdf")
#> [1] TRUE
options(oldopt)
qgis_run_algorithm(
"native:printlayouttopdf",
LAYOUT = "Layout 1",
OUTPUT = "output.pdf",
PROJECT_PATH = "test.qgs"
)
#> Argument `LAYERS` is unspecified (using QGIS default value).
#> Argument `DPI` is unspecified (using QGIS default value).
#> Argument `FORCE_VECTOR` is unspecified (using QGIS default value).
#> Argument `GEOREFERENCE` is unspecified (using QGIS default value).
#> Argument `INCLUDE_METADATA` is unspecified (using QGIS default value).
#> Argument `DISABLE_TILED` is unspecified (using QGIS default value).
#> Argument `SIMPLIFY` is unspecified (using QGIS default value).
#> Using `TEXT_FORMAT = "Always Export Text as Paths (Recommended)"`
#> Argument `SEPARATE_LAYERS` is unspecified (using QGIS default value).
#> JSON input ----
#> {
#> "inputs": {
#> "LAYOUT": "Layout 1",
#> "TEXT_FORMAT": 0,
#> "OUTPUT": "output.pdf",
#> "PROJECT_PATH": "test.qgs"
#> }
#> }
#>
#> Running qgis_process --json run 'native:printlayouttopdf' -
#> qt5ct: using qt5ct plugin
#> Problem with OTB installation: OTB folder is not set.
#> Cannot find layout with name "Layout 1"
#> Cannot find layout with name "Layout 1"
#> Error in "processx::run(path, args, ...)": ! System command 'qgis_process' failed
Created on 2022-08-24 by the reprex package (v2.0.1)
To be continued!
In the JSON string, the project_path
element has to be passed differently (outside inputs
and lowercase). That's the reason of the latest error. This also needs a fix at QGIS, since this element is not exported either from the processing dialog (GUI) when copying the JSON string, while it is needed for this type of algorithms. Will be reported.
library(qgisprocess)
#> Using 'qgis_process' in the system PATH.
#> QGIS version: 3.26.1-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.
curl::curl_download(
"https://gist.githubusercontent.com/paleolimbot/f2fa6f409c48c3d18fe5462fb29f8996/raw/3c1e14b7834c2175acbb6cb1b6f646906f9f89ed/test.qgs",
"test.qgs"
)
json_input <- '{
"inputs": {
"LAYOUT": "Layout 1",
"TEXT_FORMAT": 0,
"OUTPUT": "output.pdf"
},
"project_path": "test.qgs"
}'
qgis_run_algorithm("native:printlayouttopdf", .raw_json_input = json_input)
#> JSON input ----
#> {
#> "inputs": {
#> "LAYOUT": "Layout 1",
#> "TEXT_FORMAT": 0,
#> "OUTPUT": "output.pdf"
#> },
#> "project_path": "test.qgs"
#> }
#>
#> Running qgis_process --json run 'native:printlayouttopdf' -
#> qt5ct: using qt5ct plugin
#> Problem with OTB installation: OTB folder is not set.
#> <Result of `qgis_run_algorithm("native:printlayouttopdf", ...)`>
#> List of 1
#> $ OUTPUT: 'qgis_outputFile' chr "output.pdf"
file.exists("output.pdf")
#> [1] TRUE
Created on 2022-08-24 by the reprex package (v2.0.1)
The above problem has been fixed for non-MacOS systems by #111.
However, the problem on MacOS is still present as shown in https://github.com/paleolimbot/qgisprocess/pull/111#issuecomment-1234278953.
Awaiting further localisation of the problem in MacOS (QGIS or R?); meanwhile refining this issue's title.
My colleague @peterdesmet uses macOS and found that the qgis_process
command does this job fine, both with and without JSON input!
The output file is created in both cases.
This means that the problem is not on the QGIS-on-macOS side, but on the R-on-macOS side.
If someone wants to get this algorithm running with R on macOS, then debugging is needed in R on macOS in order to find the cause. For example with following R code derived from the corresponding test:
library(qgisprocess)
tmp_pdf <- qgis_tmp_file(".pdf")
result <- qgis_run_algorithm(
"native:printlayouttopdf",
LAYOUT = "Layout 1",
OUTPUT = tmp_pdf,
PROJECT_PATH = system.file("extdata/longlake.qgs", package = "qgisprocess")
)
file.exists(tmp_pdf)
identical(tmp_pdf, as.character(result$OUTPUT))
unlink(tmp_pdf)
Thanks to the r-spatial panel question at FOSS4G!
Created on 2021-09-30 by the reprex package (v2.0.1)