# Example 1: Geospatial raster
if (requireNamespace("terra", quietly = TRUE) && terra_is_working()) {
# Load example multi-band image (Sentinel-2 subset) and downsample
tiff_dir <- system.file("demo-geotiff",
package = "snic",
mustWork = TRUE
)
files <- file.path(tiff_dir, c(
"S2_20LMR_B02_20220630.tif",
"S2_20LMR_B04_20220630.tif",
"S2_20LMR_B08_20220630.tif",
"S2_20LMR_B12_20220630.tif"
))
s2 <- terra::aggregate(terra::rast(files), fact = 8)
# Compare grid types visually using snic_plot for immediate feedback
types <- c("rectangular", "diamond", "hexagonal", "random")
op <- par(mfrow = c(2, 2), mar = c(2, 2, 2, 2))
for (tp in types) {
seeds <- snic_grid(s2, type = tp, spacing = 12L, padding = 18L)
snic_plot(
s2,
r = 4, g = 3, b = 1, stretch = "lin",
seeds = seeds,
main = paste("Grid:", tp)
)
}
par(mfrow = c(1, 1))
# Estimate seed counts for planning
snic_count_seeds(s2, spacing = 12L, padding = 18L)
par(op)
}
# Example 2: In-memory image (JPEG)
if (requireNamespace("jpeg", quietly = TRUE)) {
img_path <- system.file(
"demo-jpeg/clownfish.jpeg",
package = "snic",
mustWork = TRUE
)
rgb <- jpeg::readJPEG(img_path)
# Compare grid types visually using snic_plot for immediate feedback
types <- c("rectangular", "diamond", "hexagonal", "random")
op <- par(mfrow = c(2, 2), mar = c(2, 2, 2, 2))
for (tp in types) {
seeds <- snic_grid(rgb, type = tp, spacing = 12L, padding = 18L)
snic_plot(
rgb,
r = 1, g = 2, b = 3,
seeds = seeds,
main = paste("Grid:", tp)
)
}
par(mfrow = c(1, 1))
par(op)
}
Run the code above in your browser using DataLab