[R-sig-Geo] sample.Spatial question
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Thu Nov 12 10:48:53 CET 2009
This is not a full answer. To start of with, I'd suggest to use spsample
rather than sample.Spatial (maybe we should not make the latter
available to usage).
rand.points <- spsample(SPDF,n=23,type="hexagonal")
plot(rand.points, add=T,col='red')
The pattern you sketch below (nice ascii art!) might not fit in a square
area.
I'm afraid we overlooked this, and need to modify the documentation to
state that only for a limited number of sampling methods for square
regions the sample size is guaranteed the requested number. And exclude
the hexagonal...
--
Edzer
Chen, Shaofei wrote:
> Dear list members,
>
> Thanks to Dr. Bivand's quick reply on my last question about creating
> a specific polygon. My next question follows that one.
> After creating a polygon, I want to sample inside the polygon, I used
> sample.Spatial in sp library. I want to sample 23 points in a
> hexagonal structure.
>
> library(sp)
> crds <- cbind(x=c(0, 0, 400, 400, 0), y=c(0, 400, 400, 0, 0))
> Pl <- Polygon(crds)
> ID <- "400x400"
> Pls <- Polygons(list(Pl), ID=ID)
> SPls <- SpatialPolygons(list(Pls))
> df <- data.frame(value=1, row.names=ID)
> SPDF <- SpatialPolygonsDataFrame(SPls, df)
> plot(SPDF)
> rand.points <- sample.Spatial(SPDF,n=23,type="hexagonal")
> plot(rand.points, add=T)
>
>
> According to my imagination, the point pattern should look like this:
>
> + + + + +
> + + + +
> + + + + +
> + + + +
> + + + + +
>
> However, everytime, the results are not 23 points, they usually come
> up with 16 points.
> I changed to regular sampling structure with a specified offset
> c(0.5,0.5). It can give consistent results for 4x4=16 or 5x5=25...
> points. But for other number of points, for example, 20 points, it
> cannot give a 4x5 point pattern. Also offset option is not for other
> sampling type.
>
> I just wonder why this happens. I look at the source code, I think it
> may because that the it defines the first point randomly (of course,
> it uses "area = prod(apply(bb, 1, diff))/n" to define the stratum),
> and then construct the following samples. In this way, some points
> may be out of the boundary.
>
> Is it possible that I can get exactly number of points that I want for
> sampling? And also I want the offset for hexagon is available, so
> that I can make sure that the sampling points locating in the centroid
> of the hexagon. I checked the archives of the list, Dr. Bivand has
> provided codes that not utilize sample.Spatial for creating hexagons
> and centroids (I have done it with 23 points in 400 by 400 polygon),
> but it may not be easy in unregular polygon with defined number of
> points.
>
> Thank you in advance!
>
> Best,
> Shaofei
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de/
http://www.springer.com/978-0-387-78170-9 e.pebesma at wwu.de
More information about the R-sig-Geo
mailing list