ropensci / stplanr

Sustainable transport planning with R
https://docs.ropensci.org/stplanr
Other
417 stars 66 forks source link

Implement line_segment for sf objects #482

Closed Robinlovelace closed 2 years ago

Robinlovelace commented 2 years ago

Implemented in sp here: https://github.com/ropensci/stplanr/blob/v0.8.5/R/linefuns.R

agila5 commented 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.

Robinlovelace commented 2 years ago

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.

Robinlovelace commented 2 years ago

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!

agila5 commented 2 years ago

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.

agila5 commented 2 years ago

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 😅

Robinlovelace commented 2 years ago

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.

agila5 commented 2 years ago

Sure but only on the weekend 😅