Stratified Random Sampling Tool

It is possible if you convert your raster to a vector layer.

Quick example, starting from this classification raster:

enter image description here

Use Raster > Conversion > Polygonize to convert it to a vector layer:

enter image description here

If you want to create points over a whole class (and not over each separate "patch"), use the Vector > Geometry Tools > Singleparts to Multiparts tool.

Then go to Vector > Research Tools > Random Points, select the previous vector layer in Input Boundary Layer and check the Use this number of points option if you want to create the same number of points in each class:

enter image description here

If you want to change the number of points depending on the class, add a column to the attribute table of the polygon layer in which you will specify the number of points for each class, then check the Use value from input field option (instead of Use this number of points) in the Random Points tool.

enter image description here enter image description here


As I wrote: With large raster transforming the raster into a vector and then dissolve singlepart to multiparts does not work. There is an easier way to get the sample directly on the raster using R.

library(raster)
library(rgdal)

# read a raster, GeoTiff or something
forSampling <- raster(someRaster.tif)

# make stratified random sampling
# set sp = TRUE to get a spatialPointsDataframe
# that one can easily be converted into a shapefile
sampleSp <- sampleStratified(x = forSampling, size = 50, xy = TRUE, sp = TRUE)

# write it out to a shapefile for further processing
writeOGR(obj = sampleSp, dsn = "aa", layer = "sampleSp", driver="ESRI Shapefile") # this is in geographical projection