Skip to content

Commit

Permalink
Merge pull request #3 from nptscot/1-add-authors-and-text-to-description
Browse files Browse the repository at this point in the history
1 add authors and text to description
  • Loading branch information
wangzhao0217 authored May 1, 2024
2 parents 9d206e8 + c9c1657 commit 5ecfc66
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
^docs$
^pkgdown$
^data-raw$
^Data$
zip
gpkg
^Doc$
27 changes: 17 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
Package: corenet
Title: What the Package Does (One Line, Title Case)
Title: Generate Core Transport Networks
Version: 0.0.1
Authors@R:
Authors@R: c(
person("Zhao", "Wang", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-4054-0533"))
Description: What the package does (one paragraph).
comment = c(ORCID = "0000-0002-4054-0533")),
person("Robin", "Lovelace", role = c("aut", "ctb"),
comment = c(ORCID = "0000-0001-5679-6536"))
)
Description: This package provides functions to generate 'core' transport networks from
'complete' transport network datasets. It can take a transport network from
'OpenStreetMap' and saved as an 'sf' object via 'osmextract' or other package
and generate a smaller network that represents key routes enabling most people
to get to within a certain distance of most places.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
sf
URL: https://nptscot.github.io/corenet/
Depends:
R (>= 2.10)
LazyData: true
Imports:
sf
Suggests:
tibble
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
25 changes: 12 additions & 13 deletions R/corenet.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#' Generate a core network from road network data
#'
#'
#' Description to go here...
#'
#'
#' @param net A road network object, of class sf
#' @param tbc An object to be determined
#' @return A core network object, of class sf
#' @export
#' @examples
#' corenet()
corenet = function(net, tbc) {
data.frame(x = 1, y = 2) |>
utils::head()
data.frame(x = 1, y = 2) |>
utils::head()
}

#' Get the Edinburgh road network, within radius of 6 km of the center
#'
#'
#' @export
#' @examples
#' get_edinburgh_6km()
get_edinburgh_6km = function() {
sf::read_sf("https://github.com/nptscot/corenet/releases/download/v0.0.1/open_roads_edinburgh_6km.gpkg")
sf::read_sf("https://github.com/nptscot/corenet/releases/download/v0.0.1/open_roads_edinburgh_6km.gpkg")
}


Expand All @@ -30,11 +30,10 @@ get_edinburgh_6km = function() {
#' @keywords datasets
#' @name os_edinburgh_demo
#' @format An sf data frame
#' @examples
#' @examples
#' library(sf)
#' # TODO: fix this
#' # data(os_edinburgh_demo)
#' # names(os_edinburgh_demo)
#' os_edinburgh = get_edinburgh_6km()
#' head(os_edinburgh)
NULL
#' names(os_edinburgh_demo)
#' plot(os_edinburgh_demo)
#' # Larger example:
#' # os_edinburgh = get_edinburgh_6km()
NULL
41 changes: 31 additions & 10 deletions data-raw/osm_edinburgh_demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ edinburgh = zonebuilder::zb_zone("Edinburgh")
edinburgh_3km = edinburgh |>
# Change number in next line to change zone size:
filter(circle_id <= 2) |>
sf::st_union()

sf::st_union() |>
sf::st_transform(27700)
edinburgh_6km = edinburgh |>
# Change number in next line to change zone size:
filter(circle_id <= 3) |>
sf::st_union() |>
sf::st_transform(27700)
if (!file.exists("srn.gpkg")) {
message("Missing the SRN dataset locally, download it from the DfT or releases")
u = "https://api.os.uk/downloads/v1/products/OpenRoads/downloads?area=GB&format=GeoPackage&redirect"
Expand All @@ -35,24 +40,40 @@ if (!file.exists("srn.gpkg")) {
# [21] "geometry"
table(open_roads_national$trunk_road)
open_roads_cleaned = open_roads_national |>
filter(trunk_road) |>
# filter(trunk_road) |>
transmute(
name = name_1,
road_function = road_function,
form_of_way = form_of_way,
road_classification = road_classification
)

sf::write_sf(srn, "srn.gpkg", delete_dsn = TRUE)
open_roads_edinburgh = open_roads_cleaned[edinburgh_3km, , op = sf::st_within]
# Check the size of the dataset:
nrow(open_roads_edinburgh) / nrow(open_roads_national)
object.size(open_roads_edinburgh) |>
# Format in MB:
format(units = "MB")
sf::write_sf(open_roads_edinburgh, "open_roads_edinburgh.gpkg", delete_dsn = TRUE)
# Release data:
if (FASLE) {
system("gh release upload v1.0 srn.gpkg --clobber")
if (FALSE) {
usethis::use_github_release()
system("gh release upload v0.0.1 open_roads_edinburgh.gpkg --clobber")
}
# Same for 6km:
open_roads_edinburgh_6km = open_roads_cleaned[edinburgh_6km, , op = sf::st_within]
sf::write_sf(open_roads_edinburgh_6km, "open_roads_edinburgh_6km.gpkg", delete_dsn = TRUE)
# Release data:
if (FALSE) {
system("gh release upload v0.0.1 open_roads_edinburgh_6km.gpkg --clobber")
}
}
srn = sf::read_sf("srn.gpkg")



os_edinburgh_demo = sf::read_sf("open_roads_edinburgh.gpkg")
# Remove CRS info to avoid warning with non ascii characters:
sf::st_crs(os_edinburgh_demo) = NA
usethis::use_data(os_edinburgh_demo, overwrite = TRUE)
# Let's see how big the file is:
fs::file_size("data/os_edinburgh_demo.rda")


# Get OSM data (for future reference)
Expand Down
Binary file modified data/os_edinburgh_demo.rda
Binary file not shown.
9 changes: 4 additions & 5 deletions man/os_edinburgh_demo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ecfc66

Please sign in to comment.