[R-sig-Geo] problem with csr {splancs}
Roger Bivand
Roger.Bivand at nhh.no
Wed May 4 18:43:17 CEST 2011
On Wed, 4 May 2011, António M. Rodrigues wrote:
> Hi,
>
>
> I need to create a number of random points inside a polygon using car
> {splancs}.
>
>
> Let's say I have a SpatialPolygonsDataFrame with only one polygon, and I
> want to throw 100 points inside randomly.
>
>
> If the object is called poly1, I thought this would work:
>
>
>> csr(poly1,100)
?csr perhaps? "poly: A polygon data set", not a SpatialPolygons object. If
you do:
data(bodmin)
str(bodmin$poly)
you see that splancs, which is effectively unchanged since written almost
20 years ago, needs a two-column matrix. In your case, if poly1 is a
SpatialPolygons object with a single Polygons object, which in turn has a
single member Polygon object, the polygon for splancs would be:
poly1pl <- slot(slot(slot(poly1, "polygons")[[1]], "Polygons")[[1]],
"coords")
Perhaps we should start planning for a birthday party for splancs, one of
the real achievements in S/R and spatial statistics!
Roger
>
>
> But I get the error:
>
>
> Error in `[.data.frame`(x at data, i, j, ..., drop = FALSE) :
>
> undefined columns selected
>
>
> I thought this might have to do with the class, so I did:
>
>
>> teste <- slot(poly1,"polygons")
>
>
> And tried
>
>> csr(teste,100)
>
>
> Now I get:
>
> Error in poly[, 1] : incorrect number of dimensions
>
>
> I apologise if this is a very simple question.
>
> Thanks in advance,
>
> Ant?nio
>
> [[alternative HTML version deleted]]
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list