Skip to content

Commit 01dac02

Browse files
committed
Added contributions from Michael, Hugh, and flotsam
1 parent 80b0dc4 commit 01dac02

File tree

6 files changed

+83
-8
lines changed

6 files changed

+83
-8
lines changed

R/get_elev_raster.R

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ get_elev_raster <- function(locations, z, prj = NULL,
121121
that the OpenTopography API Limit will likely be exceeded."))
122122
}
123123

124+
124125
# Pass of locations to APIs to get data as raster
125126
if(src == "aws") {
126127
raster_elev <- get_aws_terrain(locations, z, prj = prj, expand = expand, ...)
@@ -193,6 +194,7 @@ get_aws_terrain <- function(locations, z, prj, expand=NULL,
193194

194195
base_url <- "https://s3.amazonaws.com/elevation-tiles-prod/geotiff"
195196

197+
#tiles <- get_tilexy_coords(locations, z)
196198
tiles <- get_tilexy(bbx,z)
197199

198200
urls <- sprintf("%s/%s/%s/%s.tif", base_url, z, tiles[,1], tiles[,2])

R/internal.R

+41-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#' rounding to tile occurs in \code{get_tilexy}
33
#' @keywords internal
44
latlong_to_tilexy <- function(lon_deg, lat_deg, zoom){
5+
# Code assumes lon is 180 to 180, so converts to that
6+
lon_deg <- ifelse(lon_deg > 180, lon_deg - 360, lon_deg)
57
#Code from https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Coordinates_to_tile_numbers_2
68
lat_rad <- lat_deg * pi /180
79
n <- 2.0 ^ zoom
@@ -13,6 +15,7 @@ latlong_to_tilexy <- function(lon_deg, lat_deg, zoom){
1315
#' function to get a data.frame of all xyz tiles to download
1416
#' @keywords internal
1517
get_tilexy <- function(bbx,z){
18+
1619
min_tile <- latlong_to_tilexy(bbx[1,1],bbx[2,1],z)
1720
max_tile <- latlong_to_tilexy(bbx[1,2],bbx[2,2],z)
1821
x_all <- seq(from = floor(min_tile[1]), to = floor(max_tile[1]))
@@ -26,9 +29,25 @@ get_tilexy <- function(bbx,z){
2629
y_all <- y_all[y_all<1]
2730
}
2831

32+
2933
return(expand.grid(x_all,y_all))
3034
}
3135

36+
#' function to get a data.frame of all xyz tiles to download
37+
#' @keywords internal
38+
get_tilexy_coords <- function(locations,z){
39+
coords <- sp::coordinates(locations)
40+
41+
tiles <- latlong_to_tilexy(coords[,1],coords[,2],z)
42+
tiles <- matrix(tiles, nrow = nrow(coords), ncol = 2)
43+
tiles <- floor(tiles)
44+
tiles <- unique(tiles)
45+
46+
tiles
47+
}
48+
49+
50+
3251
#' function to check input type and projection. All input types convert to a
3352
#' SpatialPointsDataFrame for point elevation and bbx for raster.
3453
#' @importFrom sp wkt
@@ -149,6 +168,21 @@ loc_check <- function(locations, prj = NULL){
149168
sp::coordinates(locations)))))
150169
}
151170
}
171+
172+
#check for long>180
173+
lll <- any(grepl("GEOGCRS",st_crs(prj)) |
174+
grepl("GEODCRS", st_crs(prj)) |
175+
grepl("GEODETICCRS", st_crs(prj)) |
176+
grepl("GEOGRAPHICCRS", st_crs(prj)) |
177+
grepl("longlat", st_crs(prj)) |
178+
grepl("latlong", st_crs(prj)) |
179+
grepl("4326", st_crs(prj)))
180+
if(lll){
181+
if(any(sp::coordinates(locations)[,1]>180)){
182+
stop("The elevatr package requires longitude in a range from -180 to 180.")
183+
}
184+
}
185+
152186
locations
153187
}
154188

@@ -158,12 +192,13 @@ locations
158192
#' @keywords internal
159193
proj_expand <- function(locations,prj,expand){
160194

161-
lll <- grepl("GEOGCRS",prj) |
162-
grepl("GEODCRS",prj) |
163-
grepl("GEODETICCRS",prj) |
164-
grepl("GEOGRAPHICCRS",prj) |
165-
grepl("longlat", prj) |
166-
grepl("latlong", prj)
195+
lll <- any(grepl("GEOGCRS",sf::st_crs(prj)) |
196+
grepl("GEODCRS", sf::st_crs(prj)) |
197+
grepl("GEODETICCRS", sf::st_crs(prj)) |
198+
grepl("GEOGRAPHICCRS", sf::st_crs(prj)) |
199+
grepl("longlat", sf::st_crs(prj)) |
200+
grepl("latlong", sf::st_crs(prj)) |
201+
grepl("4326", sf::st_crs(prj)))
167202

168203
if(is.null(nrow(locations))){
169204
nfeature <- length(locations)

README.Rmd

+8
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ library(devtools)
3232
install_github("jhollist/elevatr")
3333
```
3434

35+
## Contributions
36+
37+
As `elevatr` is getting more widely used, there have been some great contributions, use cases, and additional packages that have come from the user community. If you have one you'd like to share, let me know and I will gladly add it! Here are some of the ones that I have seen. Thank you all!
38+
39+
- [Michaela Mulhearn's `rayshader` and `elevatr` cheatsheet](contributions/mulhearn_rayshader_elevatr_cheatsheet.pdf)
40+
- [[@researchremora on twitter](https://mobile.twitter.com/researchremora) has created some amazing elevation maps](https://mobile.twitter.com/researchremora/status/1415119197441564672)
41+
- [Hugh Graham's `rayvista` package uses `rayshader`, `maptiles`, and `elevatr` to create some cool visualizations](https://github.com/h-a-graham/rayvista)
3542

3643
## Attribution
44+
3745
Mapzen terrain tiles (which supply the AWS source) contain 3DEP, SRTM, and GMTED2010 content courtesy of the U.S. Geological Survey and ETOPO1 content courtesy of U.S. National Oceanic and Atmospheric Administration. The Open Topography API provide access to the SRTM and the ALOS World 3D datasets. See <https://opentopography.org/> for details.
3846

3947
## Repositories

README.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ sources may be added as they come available.
2525
Currently this package includes just two primary functions to access
2626
elevation web services:
2727

28-
- `get_elev_point()`: Get point elevations using the USGS Elevation
28+
- `get_elev_point()`: Get point elevations using the USGS Elevation
2929
Point Query Service (for the US Only) or using the AWS Terrian Tiles
3030
(global). This will accept a data frame of x (long) and y (lat), a
3131
SpatialPoints/SpatialPointsDataFame, or a Simple Features object as
3232
input. A SpatialPointsDataFrame or Simple Features object is
3333
returned, depending on the class of the input locations.
34-
- `get_elev_raster()`: Get elevation data as a raster (e.g. a Digital
34+
- `get_elev_raster()`: Get elevation data as a raster (e.g. a Digital
3535
Elevation Model) from the AWS Open Data Terrain Tiles. Other sources
3636
may be added later. This will accept a data frame of of x (long) and
3737
y (lat) or any `sp` or `raster` object as input and will return a
@@ -54,6 +54,24 @@ library(devtools)
5454
install_github("jhollist/elevatr")
5555
```
5656

57+
## Contributions
58+
59+
As `elevatr` is getting more widely used, there have been some great
60+
contributions, use cases, and additional packages that have come from
61+
the user community. If you have one you’d like to share, let me know and
62+
I will gladly add it! Here are some of the ones that I have seen. Thank
63+
you all!
64+
65+
- [Michaela Mulhearn’s `rayshader` and `elevatr`
66+
cheatsheet](contributions/mulhearn_rayshader_elevatr_cheatsheet.pdf)
67+
- [\[@researchremora on
68+
twitter\](https://mobile.twitter.com/researchremora) has created
69+
some amazing elevation
70+
maps](https://mobile.twitter.com/researchremora/status/1415119197441564672)
71+
- [Hugh Graham’s `rayvista` package uses `rayshader`, `maptiles`, and
72+
`elevatr` to create some cool
73+
visualizations](https://github.com/h-a-graham/rayvista)
74+
5775
## Attribution
5876

5977
Mapzen terrain tiles (which supply the AWS source) contain 3DEP, SRTM,
Binary file not shown.

man/get_tilexy_coords.Rd

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)