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

https://github.com/openlandmap/GEDTM30?tab=readme-ov-file

gdalinfo /vsicurl/https://s3.opengeohub.org/global/edtm/legendtm_rf_30m_m_s_20000101_20231231_go_epsg.4326_v20250130.tif

Driver: GTiff/GeoTIFF
Files: /vsicurl/https://s3.opengeohub.org/global/edtm/legendtm_rf_30m_m_s_20000101_20231231_go_epsg.4326_v20250130.tif
Size is 1440010, 600010
Coordinate System is:
x_from_col <- function(dimension, bbox, col) {
  col[col < 1] <- NA
  col[col > dimension[1L]] <- NA
  xres <- diff(bbox[c(1, 3)]) / dimension[1]
  bbox[1] - xres/2 + col * xres
}
y_from_row <- function(dimension, bbox, row) {
  row[row < 1] <- NA
  row[row > dimension[2]] <- NA
@GMoncrieff
GMoncrieff / how_i_work.md
Last active January 22, 2025 13:26
How I do ML with geospatial data

How I do machine learning with geospatial data

I have a couple of AI/ML projects related to mapping things, often conservation related, with remote sensing data. Some details and packages will vary, but the process below describes how I generally approach these types of problems. Some of these tools I have only touched briefly, but I like them, and this is more an outline of how I would like to approach a new project than a retrospective look at my previous work.

We use AWS, so it makes sense to use datasets and services that are already hosted on AWS. The data discovery and loading part of this process would look somewhat different if we were using Azure and Planetary Computer, and very different if we were using GCP and Earth Engine.

Compute

All of my analysis will be done using python on an AWS VM in the same region as my data on S3, Probably using VSCode on Sagemaker or [JupyterLab](https://docs.aws.amazo

Here is some code to explore the variety available in calculating area across various packages.

x <- rnaturalearth::ne_countries(country = c("Greenland", "Spain"), returnclass = "sf")
as.numeric(sf::st_area(x))/1e6

## Greenland 2.166e6 km²  -41, 72
## Spain     505990 km²   -2, 40
@mikemahoney218
mikemahoney218 / tidy_geocomp.R
Last active August 31, 2022 07:21
Proof-of-concept replication of https://geocompr.robinlovelace.net/spatial-cv.html with tidymodels
# 12.5 Spatial CV (with spatialsample)
library(tidymodels)
library(spatialsample)
library(sf)
data("lsl", "study_mask", package = "spDataLarge")
lsl <- lsl |>
st_as_sf(coords = c("x", "y"), crs = "EPSG:32717")
ta <- terra::rast(system.file("raster/ta.tif", package = "spDataLarge"))
@anthonynorth
anthonynorth / data_pipeline.R
Last active March 21, 2022 22:44
gb rivers
library(dplyr)
library(sf)
if (!file.exists("rivers_gb.rds")) {
download.file(
"https://beaver-net-app.s3.eu-west-2.amazonaws.com/gb_rivers/rivers_gb.rds",
"rivers_gb.rds"
)
}
@ctesta01
ctesta01 / weekday_effect_on_reported_COVID_deaths.R
Last active February 14, 2022 19:00
Plot the weekday variation in reported COVID-19 deaths in the United States
library(readr)
library(ggdist)
library(tidyverse)
library(magrittr)
library(cowplot)
library(ISOweek)
df <- readr::read_csv("https://github.com/nytimes/covid-19-data/raw/master/rolling-averages/us.csv")
df %<>% mutate(wday = lubridate::wday(lubridate::ymd(date)))
weekdays <- c('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
@mdsumner
mdsumner / reprojecting-geotiff-zoom.md
Created December 7, 2021 12:45
py rasterio from an R user perspective
  library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1
edge0 <- function(x, y, ndiscr = 18) {
  dx <- if(length(x) > 1) diff(x) else diff(y)
  sf::st_set_crs(sf::st_segmentize(sf::st_sfc(sf::st_linestring(cbind(x, y))), dx/ndiscr), 
               "OGC:CRS84")
}
north <- function(x = c(-180, 180), y = 90, ndiscr = 18) {
 edge0(x, y, ndiscr)  
@tylermorganwall
tylermorganwall / submarine_cable_map.R
Last active May 5, 2025 22:17
Submarine Cable Map Dataviz
library(geojsonsf)
library(sf)
library(rayrender)
#Data source: https://github.com/telegeography/www.submarinecablemap.com
cables = geojson_sf("cable-geo.json")
cablescene = list()
counter = 1
for(i in 1:length(cables$geometry)) {