luukvdmeer / sfnetworks

Tidy Geospatial Networks in R
https://luukvdmeer.github.io/sfnetworks/
Other
347 stars 20 forks source link

To local neighborhood #110

Closed agila5 closed 3 years ago

agila5 commented 3 years ago

Examples:

# packages
library(tidygraph)
library(sfnetworks)

# data
roxel_sfn <- as_sfnetwork(roxel, directed = FALSE)

# plot with no weights
par(mar = rep(0, 4))
plot(roxel_sfn)
plot(convert(roxel_sfn, to_spatial_local_neighborhood, 1, 1000), col = "orange", add = TRUE)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
plot(convert(roxel_sfn, to_spatial_local_neighborhood, 1, 200), col = "red", add = TRUE)
plot(convert(roxel_sfn, to_spatial_local_neighborhood, 1, 1), col = "darkgreen", add = TRUE, cex = 2)


# random weights:
roxel_sfn <- roxel_sfn %>% 
  activate(edges) %>% 
  mutate(weight = rgamma(n(), shape = 3, scale = 40))

plot(roxel_sfn)
plot(convert(roxel_sfn, to_spatial_local_neighborhood, 1, 1000), col = "orange", add = TRUE)
plot(convert(roxel_sfn, to_spatial_local_neighborhood, 1, 200), col = "red", add = TRUE)
plot(convert(roxel_sfn, to_spatial_local_neighborhood, 1, 1), col = "darkgreen", add = TRUE, cex = 2)

Created on 2021-01-23 by the reprex package (v0.3.0)

If you agree with the implementation, I will add tests and update the vignette.

luukvdmeer commented 3 years ago

Thanks a lot @agila5 for moving this forward! I have been working a lot on other morphers locally so will rather include your code in my branch than merging the PR (which will probably have quite some conflicts to solve).

Some modifications I have in mind:

To stay with the tidygraph morphing design, we should also return the result as a named argument in a list.

What do you think about these modifications. I can include them in my local branch that I merge soon.

Finally, about the name of the function: do you think to_spatial_neighborhood is clear enough to be used? to_spatial_local_neighborhood is quite a long name. But not sure if it is confusing in any way to use the shorter name.

agila5 commented 3 years ago

Hi @luukvdmeer, and thanks for your comments.

What do you think about these modifications. I can include them in my local branch that I merge soon.

I agree with all suggestions and, if you want, I can work on the existing PR tomorrow in the afternoon/evening. Feel free to ignore the PR if you plan to merge your local branch sooner.

Finally, about the name of the function: do you think to_spatial_neighborhood is clear enough to be used?

Yes, I would use to_spatial_neighborhood