Here I am showing how smart sampling can be done in freely available statistical programming language R:
#First Libraries
library(raster)
## Loading required package: sp
library(rgdal)
## rgdal: version: 1.5-17, (SVN revision 1070)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
## Path to GDAL shared files: C:/Users/Gulshan/Documents/R/win-library/4.0/rgdal/gdal
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
## Path to PROJ shared files: C:/Users/Gulshan/Documents/R/win-library/4.0/rgdal/proj
## Linking to sp version:1.4-4
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
# read the NDVI data
ndvi <- raster("path_for_NDVI_image.tif")
gp <- readOGR("path_of_directory_whereyour_gp_locationis_stored", "shapefilename")
## OGR data source with driver: ESRI Shapefile
## Source: "path shapefile will appear here", layer: "name of shapefile will appear here"
## with ## features
## It has ## fields
## Integer64 fields read as strings: Tabulat_sh Tabulat__1
#If you NDVI image doesnot have the same projection as your shapefile, make them into one projection system.
# Reproject the NDVI image - one time process.
#newproj <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
#ndvi_repro <- projectRaster(ndvi, crs = newproj)
# Once the data is prepared loop the data through a for loop as below and it should work.
for(i in 1:dim(gp)[1]){
a <- crop(ndvi_repro, extent(gp[i,]))
b <- rasterize(gp[i,], a)
a <- mask(x = a, mask = b)
#here I am reclassifying the NDVI.
class_diff <- (max(getValues(a), na.rm = TRUE) - min(getValues(a), na.rm = TRUE))/5
z <- c(min(getValues(a), na.rm = TRUE), (min(getValues(a), na.rm = TRUE) + class_diff), 1,
(min(getValues(a), na.rm = TRUE) + class_diff), (min(getValues(a), na.rm = TRUE) + 2 * class_diff), 2,
(min(getValues(a), na.rm = TRUE) + 2 * class_diff), (min(getValues(a), na.rm = TRUE) + 3 * class_diff), 3,
(min(getValues(a), na.rm = TRUE) + 3 * class_diff), (min(getValues(a), na.rm = TRUE) + 4 * class_diff), 4,
(min(getValues(a), na.rm = TRUE) + 4 * class_diff), (max(getValues(a), na.rm = TRUE)), 5)
reclass_z <- matrix(z, ncol = 3, byrow = TRUE)
a <- reclassify(a, reclass_z, right = NA)
x11() # this will pop up a new plotting window.
plot(a)
# if you wish to save the classified NDVI image; just remove # and give appropriate path.
#writeRaster(a, filename = "givepathnameofclassifiedndvi", overwrite = TRUE)
sampleSp <- sampleStratified(x = a, size = 1, xy = TRUE, sp = TRUE, na.rm=TRUE)
sampleSp@data$area_per <- round((sampleSp@data$cell/sum(sampleSp@data$cell)) * 100, 1)
plot(sampleSp, add = TRUE, pch = 18, col = 'red')
title(i)
# if you wish to save the ss points; just remove # and give appropriate path.
#writeOGR(obj = sampleSp, dsn = "givedirectorypath_for_points_to_be_stored", layer = nameofthesamplepoints[i], driver="ESRI Shapefile", overwrite_layer = TRUE)
}
The points (selected smartly ;-)) will appear in red colour. Your output should look like the view in the video.
References:
Murthy, C. S.; Thiruvengadachari, S.; Jonna, S.; Raju, P. V. Design of Crop Cutting Experiments with Satellite Data for Crop Yield Estimation in Irrigated Command Areas. Geocarto International, 1997, 12 (2), 5–11.