Learn R Programming

SpatialPosition (version 1.1)

quickStewart: Create a SpatialPolygonsDataFrame of Potentials Contours

Description

This function is a wrapper around stewart, rasterStewart and rasterToContourPoly functions. Providing only the main parameters of these functions, it simplifies a lot the computation of potentials. This function creates a SpatialPolygonsDataFrame of potential values. It also allows to compute directly the ratio between the potentials of two variables.

Usage

quickStewart(spdf, df, spdfid = NULL, dfid = NULL, var, var2 = NULL,
  typefct = "exponential", span, beta, resolution = NULL, mask = NULL,
  nclass = 8, breaks = NULL)

Arguments

spdf
a SpatialPolygonsDataFrame.
df
a data frame that contains the values to compute
spdfid
name of the identifier field in spdf, default to the first column of the spdf data frame. (optional)
dfid
name of the identifier field in df, default to the first column of df. (optional)
var
name of the numeric field in df used to compute potentials.
var2
name of the numeric field in df used to compute potentials. This field is used for ratio computation (see Details).
typefct
character; spatial interaction function. Options are "pareto" (means power law) or "exponential". If "pareto" the interaction is defined as: (1 + alpha * mDistance) ^ (-beta). If "exponential" the interaction is defined as: exp(- alpha * mDistance ^ bet
span
numeric; distance where the density of probability of the spatial interaction function equals 0.5.
beta
numeric; impedance factor for the spatial interaction function.
resolution
numeric; resolution of the output SpatialPointsDataFrame (in map units).
mask
SpatialPolygonsDataFrame; mask used to clip contours of potentials.
nclass
numeric; a targeted number of classes (default to 8). Not used if breaks is set.
breaks
numeric; a vector of values used to discretize the potentials.

Value

Details

If var2 is provided the ratio between the potentials of var (numerator) and var2 (denominator) is computed.

See Also

stewart, rasterStewart, plotStewart, rasterToContourPoly, CreateGrid, CreateDistMatrix.

Examples

Run this code
# load data
data("spatData")
# Compute a SpatialPolygonsDataFrame of potentials
pot.spdf <- quickStewart(spdf = spatPts, 
                         df = spatPts@data, 
                         var = "Capacite", 
                         span = 1000, 
                         beta = 2, mask = spatMask)
plot(pot.spdf)
# cartography
if(require("cartography")){
  breaks <- c(unique(pot.spdf$min), max(pot.spdf$max))
  cartography::choroLayer(spdf = pot.spdf, df = pot.spdf@data,
                          var = "center", breaks = breaks, 
                          legend.pos = "topleft",
                          legend.title.txt = "Nb. of Beds")
}
pot.spdf@data


# Compute a SpatialPolygonsDataFrame of a ratio of potentials
spatPts$dummy <- spatPts$Capacite + round(runif(n = nrow(spatPts), 
                                                min = -6, max = 6), 0)
pot2.spdf <- quickStewart(spdf = spatPts, 
                          df = spatPts@data, 
                          var = "Capacite", 
                          var2 = "dummy",
                          span = 1000, 
                          beta = 2, mask = spatMask)
# cartography
if(require("cartography")){
  breaks <- c(unique(pot2.spdf$min), max(pot2.spdf$max))
  cartography::choroLayer(spdf = pot2.spdf, df = pot2.spdf@data,
                          var = "center", breaks = breaks, 
                          legend.pos = "topleft",legend.values.rnd = 3,
                          legend.title.txt = "Nb. of Beds")
}

Run the code above in your browser using DataLab