mbtyers / riverdist

River Network Distance Computation and Applications
23 stars 2 forks source link

round trip between SpatialLinesDataFrame and rivernetwork #6

Closed jsta closed 7 years ago

jsta commented 7 years ago

It would be great if you could make the round trip between SpatialLinesDataFrame and rivernetwork objects with a network2line function.

One thing that would be possible as a result is network QA with the mapview and mapedit packages.

jsta commented 7 years ago

I see that line2network(foo)$sp outputs a SpatialLinesDataFrame but it doesn't include any of the associated attributes in the other rivernetwork slots.

jsta commented 7 years ago

I got it with this sf code.

library(riverdist)
library(sf)

filepath <- system.file("extdata", package="riverdist")
Gulk_UTM5 <- line2network(path=filepath, layer="Gulk_UTM5")

res_geom <- st_cast(st_sfc(st_multilinestring(Gulk_UTM5$lines)), "LINESTRING")
res      <- st_sf(Gulk_UTM5$lineID, geom = res_geom)
plot(res)

rplot

as(res, "Spatial")

class : SpatialLinesDataFrame features : 14 extent : 839774.3, 895654.8, 6922087, 7010276 (xmin, xmax, ymin, ymax) coord. ref. : NA variables : 3 names : rivID, sp_line, sp_seg min values : 1, 1, 1 max values : 14, 1, 14