Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update attributes after subdivision #158

Open
agila5 opened this issue May 21, 2021 · 0 comments
Open

Update attributes after subdivision #158

agila5 opened this issue May 21, 2021 · 0 comments
Labels
feature 🎁 Request a new feature to_spatial_subdivision All issues related to function `to_spatial_subdivision()`

Comments

@agila5
Copy link
Collaborator

agila5 commented May 21, 2021

Is your feature request related to a problem? Please describe.
The to_spatial_subdivison morpher is used to construct a subdivision of a network by subdividing edges at some interior points. The "new" edges have exactly the same characteristics as the old edges (and there is also a warning message related to this behaviour). I would like to modify the existing approach and apply a function to (some or all) numerical field such that, for example, the new values are equal to the old values times the length of the new edge divided by the length of the old edge. Something like: x_new = x_old * length_new / length_old (where length_new / length_old is like the proportion of the new edge wrt the old edge).

Describe the solution you'd like
For example:

# packaages
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(sfnetworks)
library(tmap)

my_sf <- st_sf(
  data.frame(x = c(1, 1)), 
  geometry = st_sfc(
    st_linestring(rbind(c(-1, 0), c(0, 0), c(1, 0))), 
    st_linestring(rbind(c(0, -0.2), c(0, 0), c(0, 1))), 
    crs = 4326
  )
)

my_sfn <- as_sfnetwork(my_sf, directed = FALSE)

# Before subdivision
tm_shape(st_as_sf(my_sfn, "edges")) + 
  tm_lines(col = "x", palette = "Set1", lwd = 2)

# After subdivision
tm_shape(st_as_sf(my_sfn %>% convert(to_spatial_subdivision), "edges")) + 
  tm_lines(col = "x", palette = "Set1", lwd = 2)
#> Warning: to_spatial_subdivision assumes attributes are constant over geometries

# Suggested result
my_sf2 <- st_sf(
  data.frame(x = c(0.5, 0.5, 0.167, 0.83)), 
  geometry = st_sfc(
    st_linestring(rbind(c(-1, 0), c(0, 0))), 
    st_linestring(rbind(c( 1, 0), c(0, 0))),
    st_linestring(rbind(c(0, -0.2), c(0, 0))), 
    st_linestring(rbind(c(0, 0), c(0, 1))),
    crs = 4326
  )
)
tm_shape(my_sf2) + 
  tm_lines(col = "x", palette = "Set1", lwd = 2)

Created on 2021-05-21 by the reprex package (v2.0.0)

I'm not sure about the API, but I was thinking of one or two extra parameters into to_spatial_subdivison.

Describe alternatives you've considered
Again, not sure 😅

(btw: feel free to suggest a better title)

@luukvdmeer luukvdmeer added the feature 🎁 Request a new feature label Oct 7, 2021
@luukvdmeer luukvdmeer added the to_spatial_subdivision All issues related to function `to_spatial_subdivision()` label Nov 26, 2021
@luukvdmeer luukvdmeer changed the title Change the values of some fields when applying to_spatial_subdivison morpher Update attributes after subdivision Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🎁 Request a new feature to_spatial_subdivision All issues related to function `to_spatial_subdivision()`
Projects
None yet
Development

No branches or pull requests

2 participants