Skip to content

Instantly share code, notes, and snippets.

View mstrimas's full-sized avatar

Matt Strimas-Mackey mstrimas

View GitHub Profile
@mstrimas
mstrimas / aos-bc-2022_examples.R
Last active June 27, 2022 20:13
Examples from the Advanced eBird Status Data Products in R workshop
library(raster)
library(sf)
library(exactextractr)
library(rnaturalearth)
library(tidyverse)
library(lubridate)
library(ebirdst)
# averaging and subsetting ----
@mstrimas
mstrimas / recenter-sf
Created May 15, 2020 09:01
Project geometries to CRS centered on longitudes other than 0
library(sf)
library(rnaturalearth)
# transform an sf object, moving the dateline seam to edge of projection
#
# x: sf containing spatial features
# crs: character; proj4 string for new projection
#
# return:
# sf containing spatial features in new projection
@mstrimas
mstrimas / ebirdst-data.R
Last active March 17, 2020 12:07
eBird Status & Trends - Tompkins County
library(rasterVis)
library(ebirdst)
library(sf)
library(tigris)
library(dplyr)
# download data from aws
species <- "Swainson's Thrush"
dl_path <- ebirdst_download(species)
@mstrimas
mstrimas / ebp-setup-test.R
Last active June 10, 2019 03:36
eBird Best Practices Setup Test
library(auk)
library(tidyverse)
tf <- tempfile()
system.file("extdata/ebd-sample.txt", package = "auk") %>%
auk_ebd() %>%
auk_species(species = c("Canada Jay", "Blue Jay")) %>%
auk_country(country = c("US", "Canada")) %>%
auk_bbox(bbox = c(-100, 37, -80, 52)) %>%
auk_date(date = c("2012-01-01", "2012-12-31")) %>%
@mstrimas
mstrimas / chaikin-smoothing.r
Created March 8, 2018 20:27
Chaikin's corner cutting algorithm
library(tidyverse)
library(gganimate)
library(hrbrthemes)
# generate a jagged polygon
set.seed(1)
n <- 60
theta <- (runif(n) + 1:n - 1) * 2 * pi / n
radius <- rgamma(n, shape = 3)
radius <- radius / max(radius)
@mstrimas
mstrimas / rgeos-scale-slivers.r
Created November 6, 2015 02:10
Importance of Scale and Slivers in RGEOS
library(sp)
library(raster)
library(rgeos)
set_RGEOS_polyThreshold(0)
set_RGEOS_warnSlivers(TRUE)
set_RGEOS_dropSlivers(FALSE)
# function to rigidly shift polygon
# only works for simple polygon objects with a single polygon
shift_poly <- function(p, x, y) {