SpatialPosition
package from within QGISQuantum GIS or QGIS is a free desktop Geographic Information System software first released in 2002. In 2013 (release 2.0) the Sextante plugin was integrated in the QGIS default install as a processing toolbox with a set of geoalgorithms from several providers (QGIS itself, GRASS, R, etc.). The processing toolbox provides pre-implemented scripts but it is also possible to edit user-defined scripts. This tutorial details the steps to set up a R script and use the SpatialPosition
package from within QGIS.
Basic install and activation
install packages
and install the SpatialPosition
package (or use the install.packages()
function)Processing
and check the Toolbox
buttonProcessing > Options > Providers > R Scripts
and check activate
Two ways to add the script
Option 1 - Copying the rsx
file
.rsx
extension, for example SpatialPosition.Rsx
SpatialPosition.rsx
into the R scripts folder
(the path is given in Options > Providers > R Scripts
)Option 2 - Creating a new script
Toolbox
panel choose Advanced interface
Toolbox > R Scripts > Tools
and open Create a new R script
The new script appear in QGIS > Toolbox > R Scripts > Tools > User R scripts
. If you want to make it appear in an existing or a user-defined category (for example a category called “Spatial statistics”) you can add a line in the header such as ##Spatial statistics=group
.
The new script appear in QGIS > Toolbox > R Scripts > Tools > User R scripts
. If you want to make it appear in an existing or a user-defined category (for example a category called “Spatial statistics”) you can add a line in the header such as ##Spatial statistics=group
.
The main arguments of the stewart()
function are available. The function (exponential) and the beta parameter (3) are hard coded, you may edit the script if you want to change this default behavior.
##Layer=vector
##Mask=vector
##Field=Field Layer
##Resolution=number 500
##Span=number 2000
##Output=output raster
library("sp")
library("raster")
library("SpatialPosition")
proj4string(Layer) <- CRS("+init=epsg:2154")
proj4string(Mask) <- CRS("+init=epsg:2154")
resGrid <- CreateGrid(w = Mask, resolution = Resolution)
matDist <- CreateDistMatrix(knownpts = Layer, unknownpts = resGrid, bypassctrl = TRUE)
vecStewart <- stewart(knownpts = Layer, unknownpts = resGrid, matdist = matDist, varname = Field, span = Span, mask = Mask, resolution = Resolution, typefct = "exponential", beta = 3)
Output <- rasterStewart(x = vecStewart, mask = Mask)