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

peter van horssen peter.vanhorssen at wxs.nl
Thu Dec 22 13:20:02 CET 2016


Thanks for solution, it works.

after :
x = st_line_sample(mls, mls$n)
x
#Geometry set for 3 features
#geometry type:  MULTIPOINT
#dimension:      XY
#bbox:           xmin: 0.05 ymin: 0 xmax: 2.9975 ymax: 1
#epsg (SRID):    NA
#proj4string:    NA
#MULTIPOINT(0.05 0, 0.15 0, 0.25 0, 0.35 0, 0.45...
#MULTIPOINT(1.005 0.005, 1.015 0.015, 1.025 0.02...
#MULTIPOINT(2.0025 1, 2.0075 1, 2.0125 1, 2.0175...

I get a multipoint object and of course I want a 'plain' point object !
So I end up in this https://github.com/edzer/sfr/issues/114 How to go 
from MULTIPOINT to just point?  but thats oke. Lots of development is 
going on there.

BTW the postgis command to 'un multi' a geometry is st_dump, all though 
it is not a very a attractive name, this might be used also in r::sf ?

greetings, Peter

Op 20-12-2016 om 22:41 schreef Edzer Pebesma:
>
> 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)
>
>
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list