Create a SpatialPolygonsDataFrame from a Raster

Share:

Description

This function creates a contour SpatialPolygonsDataFrame from a raster.

Usage

1
rasterToContourPoly(r, nclass = 8, breaks = NULL, mask = NULL)

Arguments

r

raster; the raster must contain only positive values.

nclass

numeric; a number of class.

breaks

numeric; a vector of break values.

mask

SpatialPolygonsDataFrame; mask used to clip contour shapes. The mask should have a smaller extent than r.

Details

This function uses the rgeos package.

Value

The ouput of the function is a SpatialPolygonsDataFrame. 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), center (central values of classes)

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
data("spatData")
## Not run: 
mystewart <- stewart(knownpts = spatPts, varname = "Capacite",
                     typefct = "exponential", span = 1000, beta = 3,
                     resolution = 50, mask = spatMask)
# Create a raster of potentials values
mystewartraster <- rasterStewart(x = mystewart)
# Create contour SpatialLinesDataFrame
contourpoly <- rasterToContourPoly(r = mystewartraster,
                                   nclass = 6,
                                   mask = spatMask)
# Created breaks
bks <- sort(unique(c(contourpoly$min, contourpoly$max)))
# Display the map
library(cartography)
opar <- par(mar = c(0,0,1.2,0))
choroLayer(spdf = contourpoly,
           df = contourpoly@data,
           var = "center", legend.pos = "topleft",
           breaks = bks, 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)

## End(Not run)