[R-sig-Geo] spsample and small sample size
Patrick Giraudoux
patrick.giraudoux at univ-fcomte.fr
Mon Oct 20 11:38:28 CEST 2008
Dear listers,
I met a trouble with spsample which has been solved by Roger Bivand off
list. I though it was general enough to be of interest for other users.
In brief I needed to get 50 random points on a SpatialLinesDataFrame
called "hydntline" and got:
spsample(hydntline,50,type="random")
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "coordinates", for
signature "numeric"
Roger's response is the following:
The reason is that some lines are assigned no sample points, and the
function tries to create a SpatialPoints object with no points. The
workaround is to increase n, then reduce the output by sampling back down.
z <- spsample(hydntline,4000,type="random")
zz <- z[sample(nrow(coordinates(z)), 50)]
plot(hydntline, axes=TRUE)
points(zz, pch=3)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patrick_giraudoux.vcf
Type: text/x-vcard
Size: 399 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20081020/51209072/attachment.vcf>
More information about the R-sig-Geo
mailing list