-
Notifications
You must be signed in to change notification settings - Fork 6
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
add google elevation source? #28
Comments
Due the api request limits, it needs another loop to make one request at a time per linestring. So, for the full library(tidyverse)
library(sf)
library(slopes)
library(googleway)
set_key(Sys.getenv("GOOGLE_KEY"))
Roads = st_transform(lisbon_road_segments, 4326)
# mapview::mapview(Roads)
#a df with only corddinates in WGS84 (google does not like others)
Roads_coords = data.frame(st_coordinates(Roads$geom))
names(Roads_coords) = c("lon", "lat", "l")
#a df without geometries
Roads_xyz = Roads
Roads_xyz$geom= NULL
Roads_xyz$bbox= NULL
Roads_xyz$geom= NA
#get elevarion per point, and transform each line in a xyz linestring again
for (i in 1:nrow(Roads)){
google = google_elevation(Roads_coords[Roads_coords$l == i,])
Roads_coords$elev[Roads_coords$l == i] = google$results$elevation
Roads_coords$resol[Roads_coords$l == i] = google$results$resolution
line = Roads_coords[Roads_coords$l == i,]
Roads_xyz$geom[i] = st_as_sf(line, coords = c("lon","lat","elev")) %>% st_combine() %>% st_cast("LINESTRING")
}
Roads_xyz = st_as_sf(Roads_xyz, dim = "XYZ", crs=st_crs(Roads))
Roads$slope = slope_xyz(Roads_xyz) #to store the values in the original dataset
summary(Roads$slope)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.0004856 0.0064922 0.0279617 0.0455289 0.0780702 0.1995000
summary(Roads_coords$resol) #check average resolution
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 1.193 1.193 1.193 1.193 1.193 1.193
mapview::mapview(Roads["slope"]) |
Fantastic, I think that could be the basis of a new function to get slopes from Google's API. Hypothesis: will be faster and more accurate than the current approach that downloads raster DEMs covering the entire area. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe to add as an alternative to ceramic/mapbox?
It has a very good resolution depending on the place on earth.
Using googleway to retrieve google elevation:
The text was updated successfully, but these errors were encountered: