ropensci / stplanr

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

add-angle-calculation-to-prevent-sideroad-getting-value-from-mainroad #525

Closed wangzhao0217 closed 1 year ago

Robinlovelace commented 1 year ago

Do you have results to share @wangzhao0217 ? Ideally with reference to the sideroad shown here: https://github.com/nptscot/networkmerge/issues/54

wangzhao0217 commented 1 year ago

Do you have results to share @wangzhao0217 ? Ideally with reference to the sideroad shown here: nptscot/networkmerge#54

yes , image

Robinlovelace commented 1 year ago

Fantastic. Will clone, test, and hopefully merge asap.

Robinlovelace commented 1 year ago

OK, taking a look now...

Robinlovelace commented 1 year ago

Checking out with

git checkout -b wangzhao0217-ZW-Angle-Cal master
git pull https://github.com/wangzhao0217/stplanr.git ZW-Angle-Cal
Robinlovelace commented 1 year ago

@wangzhao0217 I'm hitting error messages.

Can you try running the following on your computer and let me know what outputs you see:

rmarkdown::render('vignettes/merging-route-networks.Rmd')
Robinlovelace commented 1 year ago

The output on the master branch generates this in the first interactive map:

image

Robinlovelace commented 1 year ago

Results of reproducible example on master branch:

sf::sf_use_s2(FALSE)
#> Spherical geometry (s2) switched off
library(stplanr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tmap)
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#>      (status 2 uses the sf package in place of rgdal)
rnet_x = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_x_ed.geojson")
rnet_y = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_y_ed.geojson")
# dups = duplicated(rnet_x$geometry)
# summary(dups)
# rnet_x = rnet_x |>
#   filter(!dups)
# sf::write_sf(rnet_x, "~/github/ropensci/stplanr/rnet_x_ed.geojson", delete_dsn = TRUE)

tmap_mode("view")
#> tmap mode set to interactive viewing
# nrow(rnet_x)
# summary(sf::st_length(rnet_x))
plot(sf::st_geometry(rnet_x))

rnet_x = rnet_subset(rnet_x, rnet_y, dist = 20)
#> Linking to GEOS 3.11.1, GDAL 3.6.4, PROJ 9.1.1; sf_use_s2() is FALSE
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries
#> Warning in st_cast.sf(sf::st_cast(x, "MULTILINESTRING"), "LINESTRING"):
#> repeating attributes for all sub-geometries for which they may not be constant
#> Joining with `by = join_by(identifier)`
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
# nrow(rnet_x)
# plot(sf::st_geometry(rnet_x))
rnet_x = rnet_subset(rnet_x, rnet_y, dist = 20, min_length = 5)
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries

#> Warning: repeating attributes for all sub-geometries for which they may not be
#> constant
#> Joining with `by = join_by(identifier, length_original)`
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
# summary(sf::st_length(rnet_x))
# nrow(rnet_x)
# plot(sf::st_geometry(rnet_x))
rnet_x = rnet_subset(rnet_x, rnet_y, dist = 20, rm_disconnected = TRUE)
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries

#> Warning: repeating attributes for all sub-geometries for which they may not be
#> constant
#> Joining with `by = join_by(identifier, length_original)`
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
# nrow(rnet_x)
plot(sf::st_geometry(rnet_x))


funs = list(value = sum, Quietness = mean)
brks = c(0, 100, 500, 1000, 5000)
rnet_merged = rnet_merge(rnet_x, rnet_y, dist = 20, segment_length = 20, funs = funs)
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries

#> Warning: repeating attributes for all sub-geometries for which they may not be
#> constant
#> Joining with `by = join_by(identifier, length_original)`
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> although coordinates are longitude/latitude, st_contains assumes that they are
#> planar
#> Joining with `by = join_by(identifier)`
m1 = tm_shape(rnet_y) + tm_lines("value", palette = "viridis", lwd = 5, breaks = brks)  +
  tm_scale_bar()
m2 = tm_shape(rnet_merged) + tm_lines("value", palette = "viridis", lwd = 5, breaks = brks)
m2
#> Warning: Values have found that are higher than the highest break
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.

Created on 2023-09-07 with reprex v2.0.2

Robinlovelace commented 1 year ago

Output of same code on this branch:

remotes::install_github("wangzhao0217/stplanr@ZW-Angle-Cal")
#> Using github PAT from envvar GITHUB_PAT
#> Skipping install of 'stplanr' from a github remote, the SHA1 (6199111e) has not changed since last install.
#>   Use `force = TRUE` to force installation
sf::sf_use_s2(FALSE)
#> Spherical geometry (s2) switched off
library(stplanr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tmap)
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#>      (status 2 uses the sf package in place of rgdal)
rnet_x = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_x_ed.geojson")
rnet_y = sf::read_sf("https://github.com/ropensci/stplanr/releases/download/v1.0.2/rnet_y_ed.geojson")
# dups = duplicated(rnet_x$geometry)
# summary(dups)
# rnet_x = rnet_x |>
#   filter(!dups)
# sf::write_sf(rnet_x, "~/github/ropensci/stplanr/rnet_x_ed.geojson", delete_dsn = TRUE)

tmap_mode("view")
#> tmap mode set to interactive viewing
# nrow(rnet_x)
# summary(sf::st_length(rnet_x))
plot(sf::st_geometry(rnet_x))

rnet_x = rnet_subset(rnet_x, rnet_y, dist = 20)
#> Linking to GEOS 3.11.1, GDAL 3.6.4, PROJ 9.1.1; sf_use_s2() is FALSE
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries
#> Warning in st_cast.sf(sf::st_cast(x, "MULTILINESTRING"), "LINESTRING"):
#> repeating attributes for all sub-geometries for which they may not be constant
#> Joining with `by = join_by(identifier)`
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
# nrow(rnet_x)
# plot(sf::st_geometry(rnet_x))
rnet_x = rnet_subset(rnet_x, rnet_y, dist = 20, min_length = 5)
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries

#> Warning: repeating attributes for all sub-geometries for which they may not be
#> constant
#> Joining with `by = join_by(identifier, length_original)`
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
# summary(sf::st_length(rnet_x))
# nrow(rnet_x)
# plot(sf::st_geometry(rnet_x))
rnet_x = rnet_subset(rnet_x, rnet_y, dist = 20, rm_disconnected = TRUE)
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries

#> Warning: repeating attributes for all sub-geometries for which they may not be
#> constant
#> Joining with `by = join_by(identifier, length_original)`
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
# nrow(rnet_x)
plot(sf::st_geometry(rnet_x))


funs = list(value = sum, Quietness = mean)
brks = c(0, 100, 500, 1000, 5000)
rnet_merged = rnet_merge(rnet_x, rnet_y, dist = 20, segment_length = 20, funs = funs)
#> although coordinates are longitude/latitude, st_union assumes that they are
#> planar
#> although coordinates are longitude/latitude, st_intersection assumes that they
#> are planar
#> Warning: attribute variables are assumed to be spatially constant throughout
#> all geometries

#> Warning: repeating attributes for all sub-geometries for which they may not be
#> constant
#> Joining with `by = join_by(identifier, length_original)`
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Warning: st_centroid assumes attributes are constant over geometries
#> Warning in st_centroid.sfc(st_geometry(x), of_largest_polygon =
#> of_largest_polygon): st_centroid does not give correct centroids for
#> longitude/latitude data
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> New names:
#> Joining with `by = join_by(identifier)`
#> • `corr_line_geometry` -> `corr_line_geometry...3`
#> • `angle` -> `angle...4`
#> • `corr_line_geometry` -> `corr_line_geometry...6`
#> • `angle` -> `angle...7`
m1 = tm_shape(rnet_y) + tm_lines("value", palette = "viridis", lwd = 5, breaks = brks)  +
  tm_scale_bar()
m2 = tm_shape(rnet_merged) + tm_lines("value", palette = "viridis", lwd = 5, breaks = brks)
m2
#> Warning: Values have found that are higher than the highest break
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.

Created on 2023-09-07 with reprex v2.0.2

wangzhao0217 commented 1 year ago

@Robinlovelace please set dist = 10, segment_length = 10

Robinlovelace commented 1 year ago

@wangzhao0217 can you try rebasing to the latest version?

Robinlovelace commented 1 year ago

@wangzhao0217 can you try rebasing to the latest version?

See here for instructions on this: https://medium.com/@topspinj/how-to-git-rebase-into-a-forked-repo-c9f05e821c8a

wangzhao0217 commented 1 year ago

problem solved