[R-sig-Geo] simple features : st_segmentize question

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Dec 20 22:41:43 CET 2016



On 20/12/16 21:29, peter van horssen wrote:
> Hi All,

Hi!

> 
> st_segmentize in sf gives us the possibility to split line element in 
> equal parts
> I have a multilinestring object with 3 lines en split these in equal 
> parts (1/10 of the line)
> 
> # example
> pts = rbind(c(0,0),c(1,0),c(2,1),c(3,1))
> 
> ls1=st_linestring(pts[1:2,])
> ls2=st_linestring(pts[2:3,])
> ls3=st_linestring(pts[3:4,])
> 
> mls <- st_sf(n=4:6,st_sfc(ls1,ls2,ls3))
> 
> class(mls)
> str(mls)
> 
> line.seg <- st_segmentize(mls,1/10)
> # this works fine
> plot(line.seg)
> points(line.seg[[1]])
> points(line.seg[[2]])
> points(line.seg[[3]])
> 
> #by the way : how can I plot all these points in one go ?

Good question! Maybe add to https://github.com/edzer/sfr/issues/110 ?

> 
> The question is how to make a _different_ number of segments for each 
> line ( and use the value in column 'n')
> I tried:
> st_segmentize(mls,1/mls$n)
> but this throws an error:
> "Error in CPL_gdal_segmentize(st_geometry(x), dfMaxLength) :
>    expecting a single value"
> 
> Is there any way to achieve this ?

x = st_line_sample(mls, mls$n)
plot(x, col = 2, add = TRUE)


-- 
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/20161220/71f53d58/attachment.bin>


More information about the R-sig-Geo mailing list