[R-sig-Geo] Selecting Random Polygons
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Fri Mar 21 16:12:02 CET 2014
require(sp)
# select 20 random polygons:
nysample = nylakes[sample(4466,20),]
plot(nysample)
# sample a single random point inside each polygon:
pts = do.call(rbind,
lapply(nysample at polygons, spsample, n=1, type="random"))
plot(p, add=TRUE, col='red')
hth,
On 03/21/2014 02:30 PM, Robin Sleith wrote:
> Hello,
> I have a set of spatial polygons (nylakes) and I would like to randomly
> select a number of polygons from nylakes. I do not need an output file of
> polygons necessarily, just a set of points would do. I have tried spsample,
> but it places multiple points per polygon, even when stratified is
> selected. Any thoughts? Info below.
>
> Thank you
> Robin
>
>> nylakes
> class : SpatialPolygons
> features : 4466
> extent : -80, -71.88637, 40.29375, 45.48771 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
>
> twenty <- spsample(nylakes, 20, type='random')
> twenty <- spsample(nylakes, 20, type='stratified')
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140321/697eefce/attachment.bin>
More information about the R-sig-Geo
mailing list