I have a workflow where my R script produces csv's and shapefiles. Those csv's and shapefiles then serve as layers in a QGIS project. Every time the R script is run, it overwrites the previous data, and the QGIS project is "dynamically" updated. The QGIS project is all set up such that it never needs to be updated or modified, since it dynamically loads the layers output by the R script.
My current workflow:
- Run R script
- Open QGIS project file
- Open Print composer manager
- Select and Open existing print composer layout
- Export (print) as PDF
- Quit qGIS
- View PDF
Desired workflow:
- Run R script
- View PDF
I can get part of the way there in R by opening the QGIS file in QGIS, by calling
# if on Windows:
shell.exec("my_qGIS_file.qgs")
# or if on MAC OS X:
system(paste("open", "my_qGIS_file.qgs"))
but then I can't figure out how to programmatically (from R) produce the pdf and quit qGIS. I've read and reread the PyQgis cookbook section on the print composer, as well as the other examples on the internet (including this one), but those are both beyond my python comprehension, and seem to be way more complicated than I need. It seems like all the examples are programmatically redefining all the print composer every time the script is run. In this workflow, I already have a print composer layout stored in the project that I had created through the GUI, and have no desire or ability to recreate it with code.
If this can't be done directly in R, I think it's possible to invoke a python script from R via a system call, something like: source("my_python_script_that_exports_my_PDF.py")
, where the python script is self-standing.
Also, I have some QGIS plugins installed that bypass having to open the print composer and just export existing composer layouts cut down the workflow by a few clicks. One of the plugins is "Maps Printer", another is "multiPrint" Perhaps a python or R script can invoke commands from these plugins?
Most critically I would like any proposed solution to run on windows, but bonus points if the suggested solution:
works on both windows and mac
does NOT actually load the full QGIS GUI (i.e., the person running the script does not see the QGIS loading splash screen or anything QGIS related; they just see the PDF magically show up in a specific directory, perhaps with a file name that is "file_name_" + timestamp.PDF).
I am running QGIS 2.8
No comments:
Post a Comment