Skip to content

Instantly share code, notes, and snippets.

View h-a-graham's full-sized avatar

Hugh Graham h-a-graham

View GitHub Profile
@h-a-graham
h-a-graham / MODIS_timeseries.R
Last active September 9, 2021 19:51
A script to create a simple time series using MODIS satellite data with R
library(gdalio)
library(rnaturalearth)
library(dplyr)
library(sf)
library(lubridate)
library(magick)
library(terra)
source(system.file("raster_format/raster_format.codeR",
package = "gdalio", mustWork = TRUE)) # helper functions
# So this is just a test to see the fastests way to go from a dataframe with
# two coordinates per row (split into 4 columns - 2 for x and 2 for y) to a
# linestring for each set of coordinates.
# minimal example.
library(sfheaders)
library(wk)
library(sf)
library(tidyverse)
library(rayshader)
library(sf)
library(ggmap)
library(EAlidaR)
# ------------ User Inputs ---------------------------------
# Googple maps API KEY
register_google(key = "[PUT YOUR API KEY HERE!!]") # Create your own key as shown in the ggmap documentation: https://github.com/dkahle/ggmap
# WGS84 lat Long centroid location for your scene...
@h-a-graham
h-a-graham / ggplot_RH_colour_facet.R
Created January 22, 2021 14:49
Add colours to right hand facets
# this adds colours to the right hand facets
colour_right_facets <- function(plot){
g <- ggplot_gtable(ggplot_build(plot))
stripr <- which(grepl('strip-r', g$layout$name))
fills <- c("grey90","grey70","grey50")
k <- 1
for (i in stripr) {
j <- which(grepl('rect', g$grobs[[i]]$grobs[[1]]$childrenOrder))
g$grobs[[i]]$grobs[[1]]$children[[j]]$gp$fill <- fills[k]
k <- k+1
@h-a-graham
h-a-graham / scrape_EA_LiDAR_URL_Tokens.py
Created December 21, 2020 09:38
A function to automate the scraping of EA lidar URL tokens for a list of zipped shp files.
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# from selenium.webdriver.firefox.options import Options
import pandas as pd
import math
@h-a-graham
h-a-graham / CityOfLondonRayshade.R
Created November 8, 2020 09:54
An R script showing how to create a 3D night-time scene of the 'City of London' borough with {EAlidaR } and {Rayshader}
# An R script showing how to create a 3D night-time scene of the 'City of London' borough with {EAlidaR } and {Rayshader}
# If you don't already have the {EAlidaR package} Run:
# devtools::install_github('h-a-graham/EAlidaR')
library(EAlidaR)
library(raster)
library(sf)
library(tidyverse)
library(here)