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

Package data #24

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Depends:
R (>= 2.10)
LazyData: true
11 changes: 11 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' CRiSp example data for Bucharest
#'
#' Data extracted from OpenStreetMap for examples used in the CRiSp package.
#'
#' @format A list with the following components:
#' \describe{
#' \item{boundary}{A sf object representing the administrative boundary of
#' Bucharest.}
#' }
#' @source OpenStreetMap
"bucharest"
44 changes: 44 additions & 0 deletions data-raw/bucharest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
library(CRiSp)
library(osmdata)
library(dplyr)
library(sf)

city_name <- "Bucharest"
river_name <- "Dâmbovița"
epsg_code <- 32635
bbox_buffer <- 2000

city_boundary <- get_osm_city_boundary(city_name) |>
st_transform(epsg_code)

bb <- getbb(city_name)
aoi <- define_aoi(bb, epsg_code, bbox_buffer)

river_centerline <- osmdata_as_sf("waterway", "river", bb)$osm_multilines |>
filter(name == river_name) |>
st_transform(epsg_code) |>
st_geometry() |>
st_intersection(st_buffer(aoi, bbox_buffer))

river_surface <- osmdata_as_sf("natural", "water", bb)
river_surface <- river_surface$osm_multipolygons |>
bind_rows(river_surface$osm_polygons) |>
st_transform(epsg_code) |>
st_filter(river_centerline, .predicate = st_intersects) |>
st_geometry() |>
st_union()

highway_values <- c("motorway", "primary", "secondary", "tertiary")
streets <- osmdata_as_sf("highway", highway_values, bb)
streets <- merge_streets(streets) |>
select("highway")

bucharest <- list(
bb = bb,
boundary = city_boundary,
river_centerline = river_centerline,
river_surface = river_surface,
streets = streets
)

usethis::use_data(bucharest, overwrite = TRUE)
Binary file added data/bucharest.rda
Binary file not shown.
23 changes: 23 additions & 0 deletions man/bucharest.Rd

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

Loading