Conditional Latin Hypercube Sampling (cLHS) R-Code to Sample Points From Raster Images

The conditional Latin Hypercube Sampling (cLHS) is a prominent model-based sampling method that employs a stratified random technique to optimize sample selection using continuous and/or categorical covariates as input. The cLHS is frequently utilized in digital soil mapping and soil property prediction applications. The use of Latin Hypercube Sampling had a significant and positive influence for all sampling techniques.

You can use the cLHS approach to select sample sizes from any input remote sensing image (raster variable). Below is the full R-code. If you use the code, please cite the paper below.

Citation: Salas EAL, Subburayalu SK, Slater B, Dave R, Parekh P, Zhao K, Bhattacharya B. 2021. Assessing the effectiveness of ground truth data to capture landscape variability from an agricultural region using Gaussian simulation and geostatistical techniques, Heliyon, 7(7), e07439, ISSN 2405-8440. https://doi.org/10.1016/j.heliyon.2021.e07439

library(rgdal)
library(clhs)
library(raster)

# Load the index image
rasterimage <- brick("C:/inputraster.tif")

# Optional: Use this if you need to stack various raster images as inputs for sampling
index_stack <- stack(raster1, raster2, raster3, raster4)

# Load raster stack into memory for faster sampling
index_stack <- readAll(rasterimage)

# Convert raster stack to a SpatialPointsDataFrame
newindexstack <- rasterToPoints(index_stack, spatial=TRUE)

# Run Conditioned Latin Hypercube Sampling, here 100 points were generated
samples.clhs100 <- clhs(newindexstack, size = 100, iter = 1000, progress = FALSE, simple = FALSE)

# Diagnosytic plots
plot(samples.clhs100)

# Extract samples
subset.idx <- samples.clhs100$index_samples

# check visually
par(mar=c(1,1,1,1))
plot(rasterimage, axes=FALSE)
plot(samples.clhs100$sampled_data, pch = 3, add=TRUE)

# Save cLHS points to shp and csv
write.csv(samples.clhs100$sampled_data, file = 'C:/clhspoints.csv')
writeOGR(samples.clhs100$sampled_data, dsn = 'C:/directory', layer='clhspoints', driver = 'ESRI Shapefile', overwrite_layer = TRUE)

Cite this paper:

Citation: Salas EAL, Subburayalu SK, Slater B, Dave R, Parekh P, Zhao K, Bhattacharya B. 2021. Assessing the effectiveness of ground truth data to capture landscape variability from an agricultural region using Gaussian simulation and geostatistical techniques, Heliyon, 7(7), e07439, ISSN 2405-8440. https://doi.org/10.1016/j.heliyon.2021.e07439

Leave a Reply

Your email address will not be published. Required fields are marked *

20 + eight =

This site uses Akismet to reduce spam. Learn how your comment data is processed.