A function for sampling a DEM by cropping squares of a given size around xy coordinates.

dem_crop(data, x0, y0, L, plot = FALSE)

Arguments

data

A DEM in RasterLayer format.

x0

A value or vector of central x coordinate(s).

y0

A value or vector of central y coordinate(s).

L

Size of squares to cropped from the DEM.

plot

Logical. Plot the DEM and the cropped sections?

Value

A cropped RasterLayer or list of RasterLayers.

Examples

# around one point
dem_cropped <- dem_crop(horseshoe, -468, 1266, L = 2)
raster::plot(dem_cropped)
points(-468, 1266)


# around multiple points
points <- data.frame(x = c(-467, -465, -466), y = c(1270, 1265, 1268))
dem_list <- dem_crop(horseshoe, points$x, points$y, L = 1, plot = TRUE)


# plot the first element
raster::plot(dem_list[[1]])