bcgov / bcgov-r-geo-workshop

Some lessons & resources supporting an R geospatial workshop & hackathon
Other
26 stars 10 forks source link

Animate a time lapse of satellite imagery over a 3d elevation model #10

Closed bevingtona closed 4 years ago

bevingtona commented 4 years ago

Create a function that animates a time lapse of satellite imagery over a 3d elevation model...

use elevatr to download a dem use getSpatialData to download imagery use rayshader to plot in 3d get a result similar to this: https://twitter.com/i/status/1183195082909990912

Satelanimate3d = function(aoi = polygon, start_date = '2018-01-01', end_date = '2019-01-01', cloud_cover_max = 20) { }
boshek commented 4 years ago

I took a fairly coarse stab at a portion of this sometime in the past. That code (used here for the Nechako). It's a start at least:

library(elevatr)
library(rayshader)
library(ggplot2)
library(bcmaps)
#> Loading required package: sf
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(sf)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

##Use bcmaps to find a polygon
nechako <- wsc_drainages() %>% 
  filter(SUB_SUB_DRAINAGE_AREA_NAME == "Nechako Reservoir") %>% 
  as("Spatial")

## This step will take a while
elevation <- get_elev_raster(nechako, z = 9, src = "aws")
#> Merging DEMs
#> Reprojecting DEM to original projection
#> Note: Elevation units are in meters.
#> Note: The coordinate reference system is:
#>  +proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs

#And convert it to a matrix:
elmat = matrix(raster::extract(elevation,raster::extent(elevation),buffer=1000),
               nrow=ncol(elevation),ncol=nrow(elevation))

## Plot in 2D
elmat %>%
  sphere_shade(texture = "imhof1") %>%
  add_water(detect_water(elmat), color="desert") %>%
  plot_map()

Created on 2019-10-29 by the reprex package (v0.3.0)