[R-sig-Geo] A Qgis Map Graphics Device for R
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Wed Aug 17 09:40:26 CEST 2016
Time to announce my little summer side project...
`pqgisr` is a *highly* experimental package to provide an easy way for
R programmers to use the cartographic features of Qgis without the
hassle of exporting objects, loading them into Qgis, and then having
to style them.
The package provides functions for adding map data from SP-class
objects, OGR, and GDAL data sources as well as basemap tile layers to
a Qgis map canvas window. Note that a full Qgis application is not
running - just a map canvas launched from R via python code. The
canvas is embedded in a small application with a little functionality
for layer styling, ordering, zooming etc. This gives you an
interactive map for exploring spatial data.
In this way I also hope to have a solution for reproducible map
graphics from R using the Qgis graphics engine. An R script, possibly
running in a knitr document, can add map data to the canvas, style it
either via simple R calls or using Qgis XML styling files created
elsewhere, then save as an image and include in a reproducible
document. Yes you could do all this via R graphics commands but the
Qgis map canvas has some features that are not available on R graphics
devices.
I started this project when I noticed the RQGIS project could have
been implemented using `rPython`, which embeds a python interpreter
instance in the R process, instead of launching separate python
processes every time. As I considered reimplementing RQGIS using
rPython I realised my time would be better spent doing something that
couldn't be easily done using the process approach, and worked on
embedding a Qgis application in R via rPython. This also fit well with
my usual workflow which is to do all my GIS analysis in R (using rgeos
etc) but then exporting to Qgis for mapping. That export/import step
really jarred.
I appreciate the work the RQGIS developers are doing and see `pqgisr`
as complementary to their approach. Running Qgis `processing`
algorithms is not on my TODO list for now, I'm concentrating on the
interactive graphics aspects.
The problem with my dependence on rPython is that there seems to be no
Windows version at the moment. Oh well.
The code is on gitlab:
https://gitlab.com/b-rowlingson/pqgisr
You'll need some dev skills to get it running, and I'd be interested
to hear success stories (failure stories less so, I *expect* it to
fail at this stage!). Documentation is almost non-existent, the README
is a bit out of date (there's more implemented functionality now), and
it will crash R if you try initialising Qgis twice. I'm also
considering changing the API, and a lot of the internals which might
simplify things and clear out some of the cruft from the earliest
versions which were mostly hacking at it to make something work.
Suggestions welcome via the project gitlab tracker please!
https://gitlab.com/b-rowlingson/pqgisr/issues
Barry
More information about the R-sig-Geo
mailing list