Closed Robinlovelace closed 2 years ago
Hi Robin! A few years ago I answered a question on SE that asked more or less the same question: https://gis.stackexchange.com/questions/379107/how-to-split-network-in-equal-piece-line-segments-in-r/379271#379271 Check the code there if you want.
Great answer. Looking at https://r-spatial.github.io/lwgeom/reference/st_linesubstring.html st_linestring()
seems ideal and sad to say I didn't know the function existed! I think the reason I put it on the backburner is because the GRASS implementation, described at https://github.com/paleolimbot/qgisprocess/issues/26 but, also, need to prioritise #481. One question Andrea: I'm thinking of splitting out general purpose functions, e.g. into a pkg called {sfextras} or {linefunctions} but that would be extra work so default is probably to refactor {stplanr} and describe the various use cases. Will be great to reduce the number of dependencies and functions, making it an easier pkg to maintain.
Heads-up @agila5 thanks to your code sharing I've implemented a solution already. Not sure how fast it is, but should work! Pls take a look, any follow on comments/suggestions/or thumbs up welcome!
LGTM. The only problem I see is that lwgeom::st_linesubstring
may return a warning for lat/long data. If you want, I will propose a fix in the afternoon.
Just kidding. I think you cannot remove the warning from lwgeom::st_linesubstring
if you run it with non-projected coordinates and I'm not sure how to replicate the same behaviour with S2 😅
Great comments, thanks Andrea!! P.s. are you happy to review other stplanr
code changes? Should be a LOT easier to maintain after mega PR #481 is reviewed/merged.
Sure but only on the weekend 😅
Implemented in sp here: https://github.com/ropensci/stplanr/blob/v0.8.5/R/linefuns.R