Wednesday 7 September 2016

rpostgis and RQGIS: two useful statistical tools for archaeologists


Hi all.
Just a short post to spread the announcement of the recent release of two R packages: rpostgis (see also here) and RQGIS (see also here and here). The first facilitates transfer between PostGIS "Geometry" objects (stored in PostgreSQL databases) and R spatial objects; the latter establishes an interface between R and QGIS and allows the user to access the many QGIS geoalgorithms from within R.
I tested them briefly and I think they are very useful tools to perform and simplify statistical and geo-statistical analyses in archaeological contexts. Here I present a quick example of usage. 
Firstly I imported a set of archaeological site-points stored in a PostgreSQL/PostGIS database. That is very simple with rpostgis package: it's enough to create a database connection (like in RpostgreSQL package) and launch the "pgGetGeom" function.

Then I used RQGIS package to run (within R) the QGIS geoalgorithm that builds a polygon from layer extent. After setting the same parameters required by QGIS, the function "run_qgis" creates a red polygon around the outermost points of my dataset.


Actually, must be careful to the version of QGIS we are using. With 2.14 there's no problem, but if you're using 2.16.1 or 2.16.2 (like me) you must modify the QGIS file "AlgorithmExecutor.py" (path for linux users should be: "/usr/share/qgis/python/plugins/processing/AlgorithmExecutor.py") as described in the web page. In the next future this problem should be correct by QGIS core team.
At the end I performed a specific point pattern analysis with the data imported and created by our two packages: in this example I calculated the Ripley's K function (for an archaeological example see here) in order to identify the distribution model (random, regular or clustered) of my archaeological sites.


In my opinion these two new R packages make easier and faster the traditional spatial analyses in R and facilitate a more virtuous integration between GIS, geo-database and statistics.
Bye.

Denis Francisci

No comments:

Post a Comment

BlogItalia - La directory italiana dei blog Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.