Learn R Programming

SpatialPosition (version 1.1)

contourStewart: Create a SpatialPolygonsDataFrame or a SpatialLinesDataFrame from a Stewart Raster

Description

contourStewart is deprecated. To obtain contour lines use rasterToContour from raster package. To obtain contour polygons use rasterToContourPoly from SpatialPosition package. This function creates a SpatialPolygonsDataFrame or SpatialLinesDataFrame contour from the Stewart raster.

Usage

contourStewart(x, breaks, mask, type = "line")

Arguments

x
raster; output of the rasterStewart function. The raster must contain only positive values.
breaks
numeric; a vector of break values.
mask
SpatialPolygonsDataFrame; mask used to clip contour shapes.
type
character; "poly" or "line". WARNING: the poly option is experimental (see details). It needs the rgeos package.

Value

  • The ouput of the function is a SpatialPolygonsDataFrame (type = "poly") or a SpatialLinesDataFrame (type = "line"). The data frame of the outputed SpatialPolygonsDataFrame contains four fields: id (id of each polygon), min and max (minimum and maximum breaks of the polygon), mean (center value of the class)

Details

To obtain a correct SpatialPolygonsDataFrame of potentials follow theses steps:
  • Step 1: Create a SpatialPointsDataFrame of potentials with the stewart function. Do not enter an unknownpts layer, set a resolution, and set a SpatialPolygonsDataFrame (spmask) as mask.
Step 2: Create a raster from the SpatialPointsDataFrame of potentials with the rasterStewart function without using a mask. Step 3: Create the SpatialPolygonsDataFrame of potentials with the contourStewart function and use the same spmask SpatialPolygonsDataFrame (Step1) as mask.

See Also

stewart, rasterStewart, plotStewart, quickStewart, CreateGrid, CreateDistMatrix.

Examples

Run this code
data("spatData")
#### Example with type = "line"
mystewart <- stewart(knownpts = spatPts, varname = "Capacite",
                     typefct = "exponential", span = 1000, beta = 3,
                     resolution = 50, longlat = FALSE,
                     mask = spatMask)
# Create a raster of potentials values
mystewartraster <- rasterStewart(x = mystewart, mask = spatMask)
# Display the raster and get break values
break.values <- plotStewart(x = mystewartraster)
# Create contour SpatialLinesDataFrame
mystewartcontourpoly <- contourStewart(x = mystewartraster,
                                       breaks = break.values,
                                       type = "line")
# Display the Map
plot(spatMask, add=TRUE)
plot(mystewartcontourpoly, border = "grey40",add = TRUE)
plot(spatPts, cex = 0.8, pch = 20, col  = "black", add = TRUE)



#### Example with type = "poly"
mystewart <- stewart(knownpts = spatPts, varname = "Capacite",
                     typefct = "exponential", span = 1000, beta = 3,
                     resolution = 50, longlat = FALSE,
                     mask = spatMask)
# Create a raster of potentials valuesn, no mask
mystewartraster <- rasterStewart(x = mystewart)
# Display the raster and get break values
break.values <- plotStewart(x = mystewartraster)
# Create contour SpatialLinesDataFrame
mystewartcontourpoly <- contourStewart(x = mystewartraster,
                                       breaks = break.values,
                                       mask = spatMask,
                                       type = "poly")
# Display the map
library(cartography)
opar <- par(mar = c(0,0,1.1,0))
choroLayer(spdf = mystewartcontourpoly, 
           df = mystewartcontourpoly@data, 
           var = "mean", legend.pos = "topleft",
           breaks = break.values, border = "grey90", 
           lwd = 0.2, 
           legend.title.txt = "Potential number\nof beds in the\nneighbourhood", 
           legend.values.rnd = 0)
plot(spatMask, add = TRUE)
propSymbolsLayer(spdf = spatPts, df = spatPts@data, var = "Capacite",
                 legend.title.txt = "Number of beds", 
                 col = "#ff000020")
layoutLayer(title = "Global Accessibility to Public Hospitals", 
            south = TRUE, sources = "", author = "")
par(opar)

Run the code above in your browser using DataLab