Skip to content

Instantly share code, notes, and snippets.

View jhollist's full-sized avatar

Jeffrey W Hollister jhollist

View GitHub Profile
@jhollist
jhollist / merge_linestrings.R
Created July 20, 2018 10:21
Combine multiple, sequential linestrings into one
library(sf)
#What I have
l1 <- st_linestring(matrix(c(1,1,2,2,3,1),ncol = 2, byrow = T))
l2 <- st_linestridng(matrix(c(3,1,3,2,4,2),ncol = 2, byrow = T))
l3 <- st_linestring(matrix(c(4,2,5,1,6,1),ncol = 2, byrow = T))
all_lines <- st_sfc(l1,l2,l3)
all_lines
#What I want
library(USAboundaries)
library(sf)
library(dplyr)
library(elevatr)
library(raster)
# Get map of lower 48 states
usa_l48 <- us_boundaries() %>%
filter(state_abbr != "HI" &
state_abbr != "AK" &
@jhollist
jhollist / iterate_waters.R
Created October 25, 2021 15:14
Example code for using a dataframe to access USEPA WATERS API. Shows two iteration examples: purrr and for loop.
library(purrr)
library(jsonlite)
library(dplyr)
library(usethis)
# The Data.gov API requires a key and has a 1000 request/hour limit
# Get Key from https://api.data.gov/signup/
# Save key in r environ
usethis::edit_r_environ()
# Add DATAGOV_KEY=YOURKEYGOESHERE to the file. Save and restart R