Skip to content

Commit

Permalink
Update data docs for #32
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Sep 10, 2021
1 parent ee86530 commit 4506845
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 34 deletions.
38 changes: 30 additions & 8 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#'
#' A dataset containing elevation in and around Lisbon
#' with a geographic resolution of 10m.
#' The dataset is 200 pixels wide by 133 pixels high, covering
#' 2.7 square kilometres of central Lisbon.
#'
#' The dataset orginates from This DEM was acquired by Instituto Superior
#' Técnico (University of Lisbon) by 2012, covers all the Northern
#' The dataset was acquired by Instituto Superior
#' Técnico (University of Lisbon) in 2012, covers all the Northern
#' Metropolitan Area of Lisbon, and has a 10m cell resolution,
#' when projected at the official Portuguese EPSG: 3763 - TM06/ETRS89.
#' The dataset was released as an open access dataset with permission from the
Expand All @@ -17,6 +19,8 @@
#' @examples
#' library(sf)
#' library(raster)
#' dim(dem_lisbon_raster)
#' res(dem_lisbon_raster)
#' names(dem_lisbon_raster)
#' plot(dem_lisbon_raster)
#' plot(lisbon_road_network["Avg_Slope"], add = TRUE)
Expand All @@ -27,11 +31,26 @@
#' A dataset representing road segments in Lisbon,
#' with X, Y and Z (elevation) dimensions for each coordinate.
#'
#' @format An object of class `sf`
#' The dataset covers 32 km of roads in central Lisbon, overlapping with the
#' area covered by the `dem_lisbon_raster` dataset.
#'
#' @format An object of class `sf`, key variables of which include
#' \describe{
#' \item{OBJECTID}{ID of the object}
#' \item{Z_Min}{The minimum elevation on the linear feature from ArcMAP}
#' \item{Z_Max}{The max elevation on the linear feature from ArcMAP}
#' \item{Z_Mean}{The mean elevation on the linear feature from ArcMAP}
#' \item{Slope_Min}{The minimum slope on the linear feature from ArcMAP}
#' \item{Slope_Max}{The max slope on the linear feature from ArcMAP}
#' \item{Slope_Mean}{The mean slope on the linear feature from ArcMAP}
#' \item{geom}{The geometry defining the LINESTRING component of the segment}
#' }
#' @source Produced by ESRI's
#' [3D Analyst extension](https://pro.arcgis.com/en/pro-app/help/analysis/)
#' @examples
#' library(sf)
#' names(lisbon_road_network)
#' sum(st_length(lisbon_road_network))
#' plot(lisbon_road_network["Avg_Slope"])
"lisbon_road_network"

Expand All @@ -43,14 +62,14 @@
#'
#' Different versions of this dataset are provided.
#'
#' The `lisbon_route` object has 1 row and 4 columns.
#' The `lisbon_route` object has 1 row and 4 columns: geometry, ID,
#' length and whether or not a path was found.
#'
#' The `lisbon_route_xyz_mapbox` was created with:
#' `lisbon_route_xyz_mapbox = elevation_add(lisbon_route)`.
#'
#' @format An object of class `sf`
#' @source Produced by ESRI's
#' [3D Analyst extension](https://pro.arcgis.com/en/pro-app/help/analysis/)
#' @source See the `lisbon_route.R` script in `data-raw`
#' @aliases lisbon_route_3d lisbon_route_xyz_mapbox
#' @examples
#' lisbon_route
Expand Down Expand Up @@ -85,14 +104,17 @@
#'
#' Simple feature collection with 30 features and 32 fields
#'
#' See `data-raw` folder in the package's github repo for details.
#' See `data-raw/cyclestreets_route.R` in the package's github repo for details.
#'
#' @format An object of class `sf`
#' @format An object of class `sf` with 18 rows and 14 columns on route
#' characteristics. See https://rpackage.cyclestreets.net/reference/journey.html
#' for details.
#' @source CycleStreets.net
#' @examples
#' library(sf)
#' class(cyclestreets_route)
#' plot(cyclestreets_route$geometry)
#' cyclestreets_route
"cyclestreets_route"

#' Road segments in Magnolia, Seattle
Expand Down
9 changes: 8 additions & 1 deletion data-raw/dem_lisbon.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ lisbon_road_network_esri = sf::read_sf("~/wip/pctLisbon-data/Shapefiles/route_se
lisbon_1km_projected = sf::st_transform(lisbon_1km, sf::st_crs(lisbon_road_network_esri))
lisbon_road_network = sf::st_intersection(lisbon_road_network_esri, lisbon_1km_projected)
plot(lisbon_road_network["Avg_Slope"])
usethis::use_data(lisbon_road_network)
library(dplyr)
lisbon_road_network = lisbon_road_network %>%
dplyr::select(matches("OB|Z|Slope", ignore.case = FALSE))
usethis::use_data(lisbon_road_network, overwrite = TRUE)
lisbon_road_segment = lisbon_road_network %>%
filter(OBJECTID == 2997)
usethis::use_data(lisbon_road_segment, overwrite = TRUE)
lisbon_road_segment_3d =

download.file("https://github.com/geocompr/d/releases/download/1/r1.zip", "r1.zip")
unzip("r1.zip")dem_lisbon_raster = raster::raster("r1")
Expand Down
14 changes: 14 additions & 0 deletions data-raw/lisbon_route.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sln = stplanr::SpatialLinesNetwork(lisbon_road_network)
points = sf::st_as_sf(crs = 4326, coords = c("X1", "X2"), data.frame(rbind(
stplanr::geo_code("Santa Catarina, Lisbon"),
stplanr::geo_code("Castelo, Lisbon")
)))
points_proj = sf::st_transform(points, sf::st_crs(lisbon_road_network))
coords = sf::st_coordinates(points_proj)
nodes = stplanr::find_network_nodes(sln, coords[, 1], coords[, 2])
lisbon_route = stplanr::sum_network_routes(sln = sln, start = nodes[1], end = nodes[2])
mapview::mapview(lisbon_route) +
mapview::mapview(lisbon_road_network["Avg_Slope"])
lisbon_route_3d = elevation_add(lisbon_route, dem_lisbon_raster)
usethis::use_data(lisbon_route, overwrite = TRUE)
usethis::use_data(lisbon_route_3d, overwrite = TRUE)
Binary file modified data/lisbon_road_network.rda
Binary file not shown.
Binary file modified data/lisbon_road_segment.rda
Binary file not shown.
Binary file modified data/lisbon_road_segment_3d.rda
Binary file not shown.
Binary file modified data/lisbon_road_segment_xyz_mapbox.rda
Binary file not shown.
Binary file modified data/lisbon_route.rda
Binary file not shown.
Binary file modified data/lisbon_route_3d.rda
Binary file not shown.
7 changes: 5 additions & 2 deletions man/cyclestreets_route.Rd

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

8 changes: 6 additions & 2 deletions man/dem_lisbon_raster.Rd

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

18 changes: 17 additions & 1 deletion man/lisbon_road_network.Rd

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

6 changes: 3 additions & 3 deletions man/lisbon_route.Rd

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

17 changes: 0 additions & 17 deletions vignettes/slopes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -356,23 +356,6 @@ mapview::mapview(lisbon_route)

We can convert the `lisbon_route` object into a 3d linestring object with X, Y and Z coordinates, using the elevation values stored in the DEM, as follows:

```{r, warning=FALSE, echo=FALSE, eval=FALSE}
sln = stplanr::SpatialLinesNetwork(lisbon_road_network)
points = sf::st_as_sf(crs = 4326, coords = c("X1", "X2"), data.frame(rbind(
stplanr::geo_code("Santa Catarina, Lisbon"),
stplanr::geo_code("Castelo, Lisbon")
)))
points_proj = sf::st_transform(points, sf::st_crs(lisbon_road_network))
coords = sf::st_coordinates(points_proj)
nodes = stplanr::find_network_nodes(sln, coords[, 1], coords[, 2])
lisbon_route = stplanr::sum_network_routes(sln = sln, start = nodes[1], end = nodes[2])
mapview::mapview(lisbon_route) +
mapview::mapview(lisbon_road_network["slope"])
lisbon_route_3d = elevation_add(lisbon_route, dem_lisbon_raster)
usethis::use_data(lisbon_route, overwrite = TRUE)
usethis::use_data(lisbon_route_3d, overwrite = TRUE)
```

```{r, eval=TRUE}
lisbon_route_xyz = elevation_add(lisbon_route, dem_lisbon_raster)
```
Expand Down

0 comments on commit 4506845

Please sign in to comment.