[R-sig-Geo] different samples size for each polygon and raster question

Michael Denslow mwdenslow at yahoo.com
Wed Apr 8 21:33:52 CEST 2009


Dear r-sig-geo,

I would like to generate random points within each of several polygons. I would like for the sample size of each point sample to be different for each polygon. I would then like to overlay a grid or raster to visualize these point over the entire study area. In other words have the cell value be based on the number of points that fall into each of the grid cells. I have included a reproducible example below to illustrate my problem.

library(sp)
Sr1 = Polygon(cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)))
Sr2 = Polygon(cbind(c(5, 4, 2, 5), c(2, 3, 2, 2)))
Srs1 = Polygons(list(Sr1), "s1")
Srs2 = Polygons(list(Sr2), "s2")
SpP = SpatialPolygons(list(Srs1, Srs2), 1:2)

attr = data.frame(a = 1:2, b = 2:1, row.names = c("s1",
	 "s2"))
SrDf = SpatialPolygonsDataFrame(SpP, attr)

plot(SpP)
## try to get same number in each polygon
# this seems to generate 10 total not 10 for each
# the help file says 'use subsetting to vary sampling intensity'
# I am not sure how to do this
points(spsample(SrDf,n=10,type="random"), pch=3, cex=.5)

## 3 try to get unique sample size for each based on attribute data
# this does not work
points(spsample(SrDf,n=SrDf[[2]],type="random"), pch=3, cex=.5)

## generate a grid file?
## use overlay to combine grid with points?


Thanks in advance for any help you can provide,
Michael

Michael Denslow

Graduate Student
I.W. Carpenter Jr. Herbarium [BOON]
Department of Biology
Appalachian State University
Boone, North Carolina U.S.A.

-- AND --

Communications Manager
Southeast Regional Network of Expertise and Collections
sernec.org



More information about the R-sig-Geo mailing list