Detects bodies of water (of a user-defined minimum size) within an elevation matrix.
detect_water(heightmap, zscale = 1, cutoff = 0.999, min_area = length(heightmap)/400, max_height = NULL, normalvectors = NULL, keep_groups = FALSE, progbar = FALSE)
A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All grid points are assumed to be evenly spaced.
Default `1`. The ratio between the x and y spacing (which are assumed to be equal) and the z axis. For example, if the elevation levels are in units of 1 meter and the grid values are separated by 10 meters, `zscale` would be 10.
Default `0.999`. The lower limit of the z-component of the unit normal vector to be classified as water.
Default length(heightmap)/400. Minimum area (in units of the height matrix x and y spacing) to be considered a body of water.
Default `NULL`. If passed, this number will specify the maximum height a point can be considered to be water.
Default `NULL`. Pre-computed array of normal vectors from the `calculate_normal` function. Supplying this will speed up water detection.
Default `FALSE`. If `TRUE`, the matrix returned will retain the numbered grouping information.
Default `FALSE`. If `TRUE`, turns on progress bar.
Matrix indicating whether water was detected at that point. 1 indicates water, 0 indicates no water.
library(magrittr) #Here we even out a portion of the volcano dataset to simulate water: island_volcano = volcano island_volcano[island_volcano < mean(island_volcano)] = mean(island_volcano) #Setting a minimum area avoids classifying small flat areas as water: island_volcano %>% sphere_shade(texture="imhof3") %>% add_water(detect_water(island_volcano, min_area = 400),color="imhof3") %>% plot_map()