You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due the api request limits, it needs another loop to make one request at a time per linestring.
So, for the full lisbon_road_segments dataset, we can do:
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 geometriesRoads_xyz=RoadsRoads_xyz$geom=NULLRoads_xyz$bbox=NULLRoads_xyz$geom=NA#get elevarion per point, and transform each line in a xyz linestring againfor (iin1:nrow(Roads)){
google= google_elevation(Roads_coords[Roads_coords$l==i,])
Roads_coords$elev[Roads_coords$l==i] =google$results$elevationRoads_coords$resol[Roads_coords$l==i] =google$results$resolutionline=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.
Activity
temospena commentedon Apr 25, 2021
Due the api request limits, it needs another loop to make one request at a time per linestring.
So, for the full
lisbon_road_segmentsdataset, we can do:Robinlovelace commentedon Apr 25, 2021
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.