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

peter van horssen peter.vanhorssen at wxs.nl
Tue Dec 20 21:29:26 CET 2016


Hi All,

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 ?

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 ?

thanks in advance,
Peter


	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list