Calling the `SpatialPosition` package from within QGIS

The QGIS Toolbox

Quantum 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.

Install and set up instructions

Basic install and activation

Two ways to add the script

Option 1 - Copying the rsx file

Option 2 - Creating a new script

Using the 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.

SpatialPosition QGIS-R script


##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)


Try the SpatialPosition package in your browser

Any scripts or data that you put into this service are public.

SpatialPosition documentation built on Sept. 6, 2017, 5:04 p.m.