ropensci / slopes

Package to calculate slopes of roads, rivers and trajectories
https://docs.ropensci.org/slopes/
GNU General Public License v3.0
70 stars 6 forks source link

support for MULTILINESTRING #16

Open temospena opened 3 years ago

temospena commented 3 years ago

slope_raster()works only with LINESTRING. Sometimes we don't want to break a street network in all the intersections (e.g. bridges, tunnels).

network = st_cast(network, "LINESTRING", do_split=F) does not quite do the trick.

Robinlovelace commented 3 years ago

Does the breakup_vertices() function fix it? Will be good to test on an example dataset that has linestrings, e.g. a smaller version of the dataset tested in #12,

temospena commented 3 years ago

I tried the stplanr::rnet_breakup_vertices() and it worked. It kept the bridges and tunnels intact and split where it should.

before breakup vertices SplitLines_nodes

after rnet_breakup_vertices() SplitLines_nodes_stplanr A highway under the bridge SplitLines_nodes_stplanrBridge A freeway node SplitLines_nodes_stplanrBridge2

Robinlovelace commented 3 years ago

Interesting. How about updating the error message

https://github.com/ITSLeeds/slopes/blob/3f71fa5b38af52e586fae4b67b1893159116f3d8/R/slopes.R#L257

So it says:

    "Only works with LINESTRINGs. Try converting with sf::st_cast(object, 'LINESTRING'), e.g. with the `stplanr::rnet_breakup_vertices()` function, first"

?

Great to see a function useful for things beyond what it was originally developed for!

temospena commented 3 years ago

Actually, I applied rnet_breakup_vertices() to the original osm network (as LINESTRINGS).

The previous error message sounds good in any case, it warns that it won't work with MULTILINESTRING and suggest to use st_cast.

We can add the tip to use stplanrin a vignette to use slopes_raster() with open data from OSM & NASA - and in that case, we won't need MULTILINESTRING. But maybe that's a too particular application?

Robinlovelace commented 3 years ago

OK, yes I think the tip could also go in the help file associated with slope_raster(). I've just put in a PR that I think does that: https://github.com/ITSLeeds/slopes/pull/17/commits/f4b186be9aa0e26643ab37e9b07fc78b184f40d7#diff-c740135a485a4e9106eb0498a31506a4fab102277b04319fe00947772303e70aR108-R110