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

Support PROJECT_PATH and ELLIPSOID arguments when using JSON input #111

Merged
merged 6 commits into from
Oct 4, 2022

Conversation

florisvdh
Copy link
Member

@florisvdh florisvdh commented Aug 26, 2022

Fixes a partial problem of #68. This should solve the problem with PROJECT_PATH and ELLIPSOID arguments when using JSON input (which is default for QGIS >= 3.23) (#68 (comment)). They must go into separate keys in the JSON string, not in the inputs key .

Related to qgis/QGIS#49972.

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"
)

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.
#> <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-26 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.1 (2022-06-23)
#>  os       Linux Mint 20
#>  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     2022-08-26
#>  pandoc   2.18 @ /usr/lib/rstudio/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  cli           3.3.0      2022-04-25 [1] CRAN (R 4.2.0)
#>  curl          4.3.2      2021-06-23 [1] CRAN (R 4.2.0)
#>  digest        0.6.29     2021-12-01 [1] CRAN (R 4.2.0)
#>  evaluate      0.16       2022-08-09 [1] CRAN (R 4.2.1)
#>  fansi         1.0.3      2022-03-24 [1] CRAN (R 4.2.0)
#>  fastmap       1.1.0      2021-01-25 [1] CRAN (R 4.2.0)
#>  fs            1.5.2      2021-12-08 [1] CRAN (R 4.2.0)
#>  glue          1.6.2      2022-02-24 [1] CRAN (R 4.2.0)
#>  highr         0.9        2021-04-16 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.3      2022-07-18 [1] RSPM (R 4.2.1)
#>  jsonlite      1.8.0      2022-02-22 [1] CRAN (R 4.2.0)
#>  knitr         1.39       2022-04-26 [1] CRAN (R 4.2.0)
#>  lifecycle     1.0.1      2021-09-24 [1] CRAN (R 4.2.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.2.0)
#>  pillar        1.8.0      2022-07-18 [1] RSPM (R 4.2.1)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.2.0)
#>  processx      3.7.0      2022-07-07 [1] RSPM (R 4.2.1)
#>  ps            1.7.1      2022-06-18 [1] RSPM (R 4.2.1)
#>  qgisprocess * 0.0.0.9000 2022-08-26 [1] local
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.2.0)
#>  rappdirs      0.3.3      2021-01-31 [1] CRAN (R 4.2.0)
#>  reprex        2.0.1      2021-08-05 [1] CRAN (R 4.2.0)
#>  rlang         1.0.4      2022-07-12 [1] RSPM (R 4.2.1)
#>  rmarkdown     2.14       2022-04-25 [1] CRAN (R 4.2.0)
#>  rstudioapi    0.13       2020-11-12 [1] CRAN (R 4.2.0)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi       1.7.8      2022-07-11 [1] RSPM (R 4.2.1)
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 4.2.0)
#>  tibble        3.1.8      2022-07-22 [1] RSPM (R 4.2.1)
#>  utf8          1.2.2      2021-07-24 [1] CRAN (R 4.2.0)
#>  vctrs         0.4.1      2022-04-13 [1] CRAN (R 4.2.0)
#>  withr         2.5.0      2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.32       2022-08-10 [1] CRAN (R 4.2.1)
#>  yaml          2.3.5      2022-02-21 [1] CRAN (R 4.2.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
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Copy link
Collaborator

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Should there also be a test with an algorithm that requires it? You could add a test.qgs to the folder where the other test data lives. (But don't feel that you have to if this is hard!)

tests/testthat/test-qgis-arguments.R Outdated Show resolved Hide resolved
@florisvdh
Copy link
Member Author

Should there also be a test with an algorithm that requires it?

Is 982fe46 OK for you? I added a new project that uses some longlake layers from the package, in order to not depend on the external WFS used in test.qgs (from the reprex).

@paleolimbot
Copy link
Collaborator

That's awesome! You can skip_on_os("mac") at the top of that test if you don't feel like debugging the MacOS failure...the point is that those parameters are getting through and passing on linux is good enough for me.

@florisvdh
Copy link
Member Author

the point is that those parameters are getting through and passing on linux is good enough for me.

Well, OK for me to look into it a bit, but currently I don't see what causes this. It says Error in basename(filename) : a character vector argument expected; I presume this has to do with PROJECT_PATH = system.file("extdata/longlake.qgs", package = "qgisprocess")? Strange, since the latter returns a character vector.

@paleolimbot
Copy link
Collaborator

When I run this locally I get a segfault:

Running /Applications/QGIS.app/Contents/MacOS/bin/qgis_process --json run 'native:printlayouttopdf' -
Logged warning: Loading a file that was saved with a newer version of qgis (saved in 3.26.2-Buenos Aires, loaded in 3.26.1-Buenos Aires). Problems may occur.
/Applications/QGIS.app/Contents/MacOS/bin/qgis_process: line 6:  1946 Segmentation fault: 11  $THISDIR/../qgis_process.app/Contents/MacOS/qgis_process "$@"
Error in `processx::run(path, args, ...)`:
! System command 'qgis_process' failed
---
Exit status: 139
Stderr:
Logged warning: Loading a file that was saved with a newer version of qgis (saved in 3.26.2-Buenos Aires, loaded in 3.26.1-Buenos Aires). Problems may occur.
/Applications/QGIS.app/Contents/MacOS/bin/qgis_process: line 6:  1946 Segmentation fault: 11  $THISDIR/../qgis_process.app/Contents/MacOS/qgis_process "$@"
---

I think you're safe to skip this on MacOS for now (perhaps keeping the segfault issue open).

@florisvdh
Copy link
Member Author

florisvdh commented Sep 1, 2022

Thanks for checking in MacOS. Still quite obscure, and something which should work anyway. I cannot debug in MacOS interactively since I have no access to such installation. It would be good to know whether qgis_process can handle this fine in the shell, i.e. to determine whether the problem is in QGIS (in that case we must place an issue there) or in the package.

Can you try something like below in a shell:

$ wget -O test.qgs https://gist.githubusercontent.com/paleolimbot/f2fa6f409c48c3d18fe5462fb29f8996/raw/3c1e14b7834c2175acbb6cb1b6f646906f9f89ed/test.qgs
$
$ myJSON=$(</dev/stdin)
{
  "inputs": {
    "LAYOUT": "Layout 1",
    "TEXT_FORMAT": 0,
    "OUTPUT": "output.pdf"
  },
  "project_path": "test.qgs"
}
$
$ echo $myJSON | qgis_process run native:printlayouttopdf -
$
$ ls output.pdf # check that it exists

@florisvdh
Copy link
Member Author

I hope to come back to the MacOS problem later in #68. For now, skipping on MacOS since no immediate solution comes up.

@florisvdh florisvdh merged commit f3aa232 into master Oct 4, 2022
@florisvdh florisvdh deleted the json_specialargs branch October 4, 2022 15:25
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.

None yet

2 participants