This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(readr) # for read_csv() | |
require(dplyr) # for mutate() | |
require(tidyr) # for unnest() | |
require(purrr) # for map(), reduce() | |
data_path <- 'c:/user/myname' # put your file path here | |
# find all file names ending in .csv | |
files <- dir(data_path, pattern = "*.csv") | |
data <- files %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(mapview) | |
# read identifiers for Colorado River and Colorado River (TX) into simple features | |
colorado_river <- sf::read_sf("https://geoconnex.us/ref/mainstems/29559") | |
colorado_river_tx <- sf::read_sf("https://geoconnex.us/ref/mainstems/2639515") | |
## Function that constructs query to retrive the latest discharge observation from the USGS |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import requests | |
url = "https://gaftp.epa.gov/epadatacommons/ORD/NHDPlusLandscapeAttributes/StreamCat/HydroRegions" | |
ext = 'zip' | |
def listFD(url, ext=''): | |
page = requests.get(url, verify=False).text | |
print(page) | |
soup = BeautifulSoup(page, 'html.parser') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mapview) | |
library(tidyr) | |
library(sf) | |
library(leaflet) | |
points <- tribble(~name, ~lat, ~lon, | |
'Point A',44.564568,-123.262047, ) | |
points_sf <- st_as_sf(points, coords = c("lon", "lat"), crs = 4269) | |
m <- mapview(points_sf, legend=FALSE) | |
m@map <- m@map %>% addWMSTiles(group = 'NHDPlus', | |
"https://watersgeo.epa.gov/arcgis/services/NHDPlus_NP21/NHDSnapshot_NP21/MapServer/WmsServer?", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Sep 9 16:46:15 2020 | |
@author: mweber | |
""" | |
# Combine hydro-region tables if desired | |
import pandas as pd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create linestring | |
line <- st_as_sfc(c("LINESTRING(0 0 , 0.5 1 , 1 1 , 1 0.3)")) %>% | |
st_sf(ID = "poly1") | |
#Convert each vertex to point | |
pt <- st_cast(line, "POINT") | |
# Grab start or end point: | |
start <- pt[1,] | |
end <- pt[nrow(pt),] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(sf) | |
library(dplyr) | |
library(mapview) | |
library(leaflet) | |
m <- mapview() | |
m@map = m@map %>% addWMSTiles(group = 'NHDPlus', | |
"https://watersgeo.epa.gov/arcgis/services/NHDPlus_NP21/NHDSnapshot_NP21/MapServer/WmsServer?", | |
layers = 4, | |
options = WMSTileOptions(format = "image/png", transparent = TRUE), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
raster_2d = 2-dimensional array imported with gdal | |
nodata = nodata value from gdal import for 2-d array | |
geotransform = geotrasform from gdal import of 2-d array | |
def raster_to_point(raster_2d, nodata, geotransform): | |
raster_2d = raster_2d.flatten() | |
locs = np.where(raster_2d <> nodata)[0] #Get locs in array w/ data | |
raster_2d = raster_2d[locs] #Reduce data to those locs | |
geo = list(geotransform) #Make geotransform from raster a list | |
x = locs % xsize #Convert flattened locations to x coord |
NewerOlder