Description Usage Arguments Value Examples
View source: R/add_from_raster.R
Based on the extract
function.
1 | add_from_raster(sptsdf, rstr, varname = "new_data")
|
sptsdf |
A |
rstr |
A |
varname |
The name of the new variable. Defaults to "new_data". |
A SpatialPointsDataFrame
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | library(sp)
# download vietnam country administrative map in the internal library and in
# the working direction
vn <- sptools::gadm("vietnam", "sp", 0, intlib = TRUE, save = TRUE)
# With a SpatialPointsDataFrame
value <- spsample(vn, 100, "random")
value <- SpatialPointsDataFrame(value, data.frame(variable = 1:100))
value <- add_from_raster(value, srtmVN::getsrtm(), "elevation")
head(value@data)
# With a SpatialPoints
value <- spsample(vn, 100, "random")
value <- SpatialPoints(value, proj4string = vn@proj4string, bbox = vn@bbox)
value <- add_from_raster(value, srtmVN::getsrtm(), "elevation")
head(value@data)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.