Skip to content
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: osmdata
Title: Import 'OpenStreetMap' Data as Simple Features or Spatial Objects
Version: 0.4.0.9002
Version: 0.4.0.9003
Authors@R: c(
person("Joan", "Maspons", , "joanmaspons@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2286-8727")),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- Fix `osmdata_sf()` for points without metadata (#426).
- Add user agent in requests to servers (#430).
- Update death links (#433).


# osmdata 0.4.0
Expand Down
18 changes: 8 additions & 10 deletions R/elevation.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#' osm_elevation
#'
#' Add elevation data to a previously-extracted OSM data set, using a
#' pre-downloaded global elevation file from
#' \url{https://srtm.csi.cgiar.org/srtmdata/}. Currently only works for
#' `SC`-class objects returned from [osmdata_sc()].
#' pre-downloaded elevation file (see Details). Currently only works for `SC`-class objects returned
#' from [osmdata_sc()].
#'
#' @param dat An `SC` object produced by [osmdata_sc()].
#' @param elev_file A vector of one or more character strings specifying paths
#' to `.tif` files (or anything that \pkg{terra} can read) containing global
#' elevation data. `.zip` files will be uncompressed.
#'
#' @details Elevation data can be downloaded from
#' \url{https://portal.opentopography.org/raster?opentopoID=OTSRTM.082015.4326.1},
#' \url{https://www.earthdata.nasa.gov/data/catalog/lpcloud-srtmgl1-003} or similar.
#'
#'
#' @return A modified version of the input `dat` with an additional `z_` column
#' appended to the vertices.
#' @family transform
Expand All @@ -22,20 +26,14 @@
#' dat <- osmdata_sc (query)
#' dat$vertex
#' # The vertex table will have columns ("x_", "y_", "vertex_"). Then
#' # download elevation data from \url{https://srtm.csi.cgiar.org/srtmdata/}
#' # (or elsewhere), and add elevation column, "z_" with:
#' # download elevation data, and add elevation column, "z_" with:
#' dat <- osm_elevation (dat, elev_file = "/path/to/elevation/data.tiff")
#' }
#' @export
osm_elevation <- function (dat, elev_file) {

requireNamespace ("terra", quietly = TRUE)

message (
"Elevation data from Consortium for Spatial Information; ",
"see http://srtm.csi.cgiar.org/srtmdata/"
)

elev_file <- check_elev_file (elev_file)
if (length (elev_file) > 1) {
stop ("not yet")
Expand Down
13 changes: 8 additions & 5 deletions man/osm_elevation.Rd

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

16 changes: 6 additions & 10 deletions vignettes/osmdata-sc.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ networks that accounts for elevation changes.

Incorporating elevation data with OSM data currently requires local storage of
desired elevation data. These must be downloaded for the desired region from
[http://srtm.csi.cgiar.org/srtmdata](https://srtm.csi.cgiar.org/srtmdata/) in Geo
TIFF format. Elevation data may then be incorporated with
[`silicate`](https://github.com/hypertidy/silicate)-format data generated by
[https://portal.opentopography.org/raster?opentopoID=OTSRTM.082015.4326.1],
[https://www.earthdata.nasa.gov/data/catalog/lpcloud-srtmgl1-003] or other sites in Geo
TIFF format or any other compatible with \pkg{terra}. Elevation data may then be
incorporated with [`silicate`](https://github.com/hypertidy/silicate)-format data
generated by
[`x <- osmdata_sc()`](https://docs.ropensci.org/osmdata/reference/osmdata_sc.html)
through the `osm_elevation()` function. The entire procedure is demonstrated
with the following lines:
Expand Down Expand Up @@ -102,13 +104,7 @@ Incorporating elevation data is then as simple as
```{r osm_elevation, eval = FALSE}
dat <- osm_elevation (dat, elev_file = "/path/to/elevation/data/filename.tiff")
```
```{r osm_elevation2, echo = FALSE}
message (
"Loading required namespace: raster\n",
"Elevation data from Consortium for Spatial Information; see ",
"https://srtm.csi.cgiar.org/srtmdata/"
)
```

This function then simply appends the elevation values to the `vertex_` table,
so that it now looks like this:
```{r dat_vertex2, eval = FALSE}
Expand Down
Loading