Random point generation?

625
1
02-14-2013 12:09 PM
EmmaYoung
New Contributor
Hi-

I have a raster that is classified into 5 different pixel values, and I want to generate 30 random points within each of those pixel classes (for a total of 150 points). I know there is a random point generation tool, but I don't think you can use it to generate points by pixel value? Does anyone know if there is a way to do this in ArcGIS? I've been trying to use IDL, but I've run into problems and so I'm looking for alternatives. Thanks so much.

Cheers,
Emma
0 Kudos
1 Reply
JeffreyEvans
Occasional Contributor III
Here is a simple R solution.

require(raster)
require(sp)
require(rgdal)

n=30 # NUMBER OF RANDOM SAMPLES PER CLASS

# READ RASTER (NOT RUN) 
#r <- raster("C:/mydata/myraster.img")

# CREATE EXAMPLE DATA WITH 5 CLASSES
r <- raster(ncol=100,nrow=100)
  r[] <- round(runif(100*100, 1,5),digits=0)

# CREATE STRATIFIED RANDOM SAMPLE WITH n SAMPLES PER STRATA (CLASS)  
rs <- sampleStratified(r, size=n, na.rm=TRUE, sp=TRUE) 

# PLOT AND COLOR POINTS BASED ON CLASS
plot(r)
  points(rs, col=rs$layer, pch=19)

# WRITE SHAPEFILE WITH RANDOM POINTS 
writeOGR(rs, "C:/mydata", "RandSamp", driver="ESRI Shapefile") 
0 Kudos