qgisprocess icon indicating copy to clipboard operation
qgisprocess copied to clipboard

Feature request: function to write Qgis project

Open aloboa opened this issue 1 year ago • 5 comments

I often do raster and vector processing using package terra and alike. At some point, I need to visualize results in Qgis. As soon as the results imply multiple raster and vector layers, a function to write an ad-hoc Qgis project would be great advantage.

aloboa avatar Oct 30 '24 17:10 aloboa

This is exactly why I came here ☝🏼 (I literally just tooted this)

The ability to create a QGIS project XML from this package would be an awesome feature 💯

ratnanil avatar Nov 07 '24 08:11 ratnanil

Thanks for sharing the enthusiasm :slightly_smiling_face:. Several things are to be considered.

  • the focus of the package is on handling the qgis_process CLI utility, hence on geoprocessing algorithms that need input objects and generate output object(s), without the need for a QGIS project. This helps reproducibility at the R side of things. That will remain the core aim.
  • IMO it doesn't hurt to have a simple and restricted sidetool, e.g. qgis_launch(list(object_1, "filepath A", object_2)), that would call the qgis CLI utility (which is in the same directory as qgis_process), which accepts filepaths (it could perhaps be extended later with more arguments since that tool has more options). I understand this may come in handy for quick visual exploration in QGIS.
    • Not promising anything yet; it must remain manageable to implement it and it might be difficult to automatically test for various systems, so I would regard this as 'not guaranteed to work on every system'.
    • R objects could be handled by the internal as_qgis_argument() to derive file paths, as it does for qgis_run_algorithm().
    • Also it won't happen very soon if I'm to do it, but I'll keep it in mind. Of course contributions are also welcome.
  • I'm not inclined to generate full *.qgs project files with various options here, since this would take more effort from my side to get this robust. Also, it feels like 'very dedicated to the GUI' while the focus of this package is on the scripted approach, without a QGIS project. With qgis_launch() (above) the package would just defer further handling of files, CRS settings etc to QGIS; the user can then adjust things interactively in the GUI, and save as a project if needed. Directly creating or updating QGIS projects or interacting with them will better fit in another package.

florisvdh avatar Nov 07 '24 10:11 florisvdh

Thank you very much for your valuable thoughts on this! Quick question: I can't seem to find anything on the qgis CLI utility you mention, is this documented anywhere?

ratnanil avatar Nov 07 '24 13:11 ratnanil

I understand the confusion. I just mean the QGIS executable, which one can call from the command line, and from the command line it can take arguments (files in this case) and options. In a bash environment, its documentation is available with man qgis. I'm not sure whether this documentation is rendered somewhere on the web, but might be.

florisvdh avatar Nov 07 '24 13:11 florisvdh

As far as I can see, the qgis command line options let the user open the layers, which I have been able to do such as:

qcomm <- paste("qgis", file.path(dirdata, "DI17_2_labels_R.tif"), "./DI17autoseg12/DI17_2_autoseg12.shp", "&")
system(qcomm)

but styling would need to be done through xml "QGIS layer definition files (.qlr)"

aloboa avatar Nov 11 '24 10:11 aloboa