This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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(jsonlite);library(sf) | |
#lon = -123.1121 | |
#lat = 44.6390 | |
#state = 'OR' | |
watershed = function(state, lon, lat){ | |
p1 = 'https://streamstats.usgs.gov/streamstatsservices/watershed.geojson?rcode=' | |
p2 = '&xlocation=' | |
p3 = '&ylocation=' |
This file contains hidden or 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
import geopands as gpd | |
from shapely.geometry.polygon import Polygon | |
from shapely.geometry.multipolygon import MultiPolygon | |
def explode(indata): | |
indf = gpd.GeoDataFrame.from_file(indata) | |
outdf = gpd.GeoDataFrame(columns=indf.columns) | |
for idx, row in indf.iterrows(): | |
if type(row.geometry) == Polygon: | |
outdf = outdf.append(row,ignore_index=True) |
This file contains hidden or 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
import pysal as ps | |
import pandas as pd | |
''' | |
Arguments | |
--------- | |
dbfile : DBF file - Input to be imported | |
upper : Condition - If true, make column heads upper case | |
''' | |
def dbf2DF(dbfile, upper=True): #Reads in DBF files and returns Pandas DF | |
db = ps.open(dbfile) #Pysal to open DBF |