[R-sig-Geo] Building a vector of random sf st_points
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Wed Dec 21 17:36:17 CET 2016
On 21/12/16 17:25, Pierre Racine wrote:
> Hi,
Hi Pierre!
>
> Very new to spatial R. I'm trying to find the best way to build a sf dataframe of random points inside an extent. I built a matrix of random coordinates and now I try to convert this matrix to a vector of st_point.
>
> I was expecting that something like:
>
> PTS <- matrix(seq(1,6), 3, 2)
> st_sfc(lapply(seq_len(nrow(PTS)), function(i) st_point(PTS[i,])))
Geometry set for 3 features
geometry type: POINT
dimension: XY
bbox: xmin: 1 ymin: 4 xmax: 3 ymax: 6
epsg (SRID): NA
proj4string: NA
POINT(1 4)
POINT(2 5)
POINT(3 6)
> ptsdf <- apply(PTS, 1, st_point)
>
> would work but it doesn't. Why?
apply wants to to mold the output into a matrix; it can, and so it does.
We want a list of POINT objects, so need to use lapply.
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software: http://www.jstatsoft.org/
Computers & Geosciences: http://elsevier.com/locate/cageo/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20161221/8d2aef38/attachment.bin>
More information about the R-sig-Geo
mailing list