A function for sampling a DEM by cropping squares based on xy cooridnates.

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

Arguments

data

A DEM in RasterLayer format.

x0

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

y0

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

L

Size of square to cut out of DEM.

plot

Logical. Plot the DEM and the cropped sections?

Value

A cropped RasterLayer or a list of RasterLayers.

Examples

# around one point
dem_cropped <- crop_dem(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 <- crop_dem(horseshoe, points$x, points$y, L = 1, plot = TRUE)


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