├── .DS_Store ├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── HydroData.Rproj ├── LICENSE ├── NAMESPACE ├── R ├── .DS_Store ├── HydroData.R ├── color.palletes.R ├── explore.R ├── findAirports.R ├── findCDL.R ├── findGAGESII.R ├── findNED.R ├── findNHD.R ├── findNID.R ├── findNLCD.R ├── findNLDI.R ├── findNWIS.R ├── findNearestAirports.R ├── findNearestCOMID.R ├── findNearestHUC12.R ├── findNearestUSGS.R ├── findNearestWaterbodies.R ├── findRoads.R ├── findSSURGO.R ├── findSnotel.R ├── findWBD.R ├── findWaterPoly.R ├── findWaterbodies.R ├── findWatershed.R ├── meta.data.R ├── pipe.R ├── query_cida_12718.R ├── to_sf.R ├── utilitiy_mosaic.R ├── utility_data.R ├── utility_download_url.R ├── utility_return_what.R ├── utility_save.file.R ├── utility_unzipCrop.R └── utility_writeHD.R ├── README.md ├── _pkgdown.yml ├── data ├── .DS_Store ├── .Rapp.history ├── airports.rda ├── snotelStations.rda └── usgsStations.rda ├── docs ├── LICENSE-text.html ├── articles │ ├── img │ │ └── sources.png │ ├── index.html │ └── sources.html ├── authors.html ├── docsearch.css ├── docsearch.js ├── favicon.ico ├── index.html ├── link.svg ├── logo.png ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── HydroData.html │ ├── ap.html │ ├── col_elev.html │ ├── daymet_tiles.html │ ├── download.url.html │ ├── download_shp.html │ ├── explore.html │ ├── figures │ ├── explore_ex.png │ ├── logo.png │ ├── plot_ex.png │ ├── rayshade_ex.png │ └── sources.png │ ├── findACIS.html │ ├── findASOS.html │ ├── findAirports.html │ ├── findCDL.html │ ├── findGAGESII.html │ ├── findGHCN.html │ ├── findHUC.html │ ├── findNED.html │ ├── findNHD.html │ ├── findNID.html │ ├── findNLCD.html │ ├── findNLDI.html │ ├── findNOAAnorms.html │ ├── findNWIS.html │ ├── findNearestAirports.html │ ├── findNearestCOMID.html │ ├── findNearestGHCN.html │ ├── findNearestHUC12.html │ ├── findNearestNWIS.html │ ├── findNearestWaterbodies.html │ ├── findRoads.html │ ├── findSSURGO.html │ ├── findSnotel.html │ ├── findUSCRN.html │ ├── findWBD.html │ ├── findWaterPoly.html │ ├── findWaterbodies.html │ ├── getBoundingBox.html │ ├── getNLDI.html │ ├── ghcn_stations.html │ ├── index.html │ ├── meta.data.html │ ├── meta.html │ ├── mosaic.hd.html │ ├── pipe.html │ ├── query_cida.html │ ├── return.what.html │ ├── saveHD.html │ ├── snotel.html │ ├── to_sf.html │ ├── usgsStations.html │ └── writeHD.html ├── man ├── .DS_Store ├── .Rapp.history ├── HydroData.Rd ├── ap.Rd ├── col_elev.Rd ├── download.url.Rd ├── explore.Rd ├── figures │ ├── explore_ex.png │ ├── logo.png │ ├── plot_ex.png │ ├── rayshade_ex.png │ └── sources.png ├── findAirports.Rd ├── findCDL.Rd ├── findGAGESII.Rd ├── findNED.Rd ├── findNHD.Rd ├── findNID.Rd ├── findNLCD.Rd ├── findNLDI.Rd ├── findNWIS.Rd ├── findNearestAirports.Rd ├── findNearestCOMID.Rd ├── findNearestHUC12.Rd ├── findNearestNWIS.Rd ├── findNearestWaterbodies.Rd ├── findRoads.Rd ├── findSSURGO.Rd ├── findSnotel.Rd ├── findWBD.Rd ├── findWaterPoly.Rd ├── findWaterbodies.Rd ├── meta.data.Rd ├── mosaic.hd.Rd ├── pipe.Rd ├── query_cida.Rd ├── return.what.Rd ├── saveHD.Rd ├── snotel.Rd ├── to_sf.Rd ├── usgsStations.Rd └── writeHD.Rd └── tests ├── .DS_Store ├── testthat.R └── testthat ├── .DS_Store ├── test_airports.R ├── test_ghcn.R ├── test_nhd.R ├── test_usgs.R └── test_utilities.R /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/.DS_Store -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | .travis.yml 4 | _pkgdown.yml 5 | docs 6 | tests 7 | help 8 | inProgress 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | .Rhistory 4 | .RData 5 | .Ruserdata 6 | .DS_Store 7 | tests 8 | help 9 | .DS_Store 10 | .Rproj.user 11 | .Rproj.user/5EFA356D/console06/INDEX001 12 | .Rproj.user/5EFA356D/pcs/files-pane.pper 13 | .Rproj.user/5EFA356D/pcs/source-pane.pper 14 | .Rproj.user/5EFA356D/pcs/windowlayoutstate.pper 15 | .Rproj.user/5EFA356D/pcs/workbench-pane.pper 16 | .Rproj.user/5EFA356D/persistent-state 17 | .Rproj.user/5EFA356D/sources/prop/INDEX 18 | .Rproj.user/shared/notebooks/paths 19 | inProgress 20 | nwm_comp.gif 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | 3 | cache: 4 | - packages 5 | - ccache 6 | 7 | sudo: required 8 | dist: trusty 9 | latex: false 10 | 11 | r: 12 | - release 13 | 14 | addons: 15 | apt: 16 | sources: 17 | - sourceline: 'ppa:ubuntugis/ubuntugis-unstable' 18 | packages: 19 | - libudunits2-dev 20 | - libproj-dev 21 | - libgeos-dev 22 | - libgdal-dev 23 | 24 | env: 25 | global: 26 | - R_BUILD_ARGS="--no-vignettes --no-manual" 27 | - R_CHECK_ARGS="--no-vignettes --no-manual --as-cran" 28 | - NOT_CRAN="true" 29 | - _R_CHECK_FORCE_SUGGESTS_=false 30 | - R_CODECOV=true 31 | 32 | warnings_are_errors: false 33 | 34 | r_github_packages: 35 | - mikejohnson51/AOI 36 | - jimhester/covr 37 | - r-spatial/lwgeom 38 | 39 | script: 40 | - | 41 | R CMD build . 42 | travis_wait 20 R CMD check HydroData*tar.gz 43 | 44 | after_success: 45 | - if [[ "${R_CODECOV}" ]]; then travis_wait 20 R -e 'covr::coveralls()'; fi s 46 | 47 | notifications: 48 | email: 49 | on_success: change 50 | on_failure: change 51 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: HydroData 2 | Type: Package 3 | Title: HydroData 4 | Description: A set of functions to find, process, export and visualize land surface, infrastructural and station based datasets relevant to geography, hydrology, and earth system science. 5 | Version: 0.0.7 6 | Authors@R: person(given = "Mike", family = "Johnson", role = c("aut", "cre"), email = "jmj00ucsb.edu", comment = c(ORCID = "0000-0002-5288-8350")) 7 | Maintainer: Mike Johnson 8 | BugReports: https://github.com/mikejohnson51/HydroData/issues 9 | URL: https://github.com/mikejohnson51/HydroData 10 | Depends: 11 | R(>= 3.3.0), 12 | AOI, 13 | leaflet 14 | Imports: 15 | crayon, 16 | dams, 17 | foreach, 18 | htmlwidgets, 19 | httr, 20 | jsonlite, 21 | magrittr, 22 | sf, 23 | sp, 24 | utils, 25 | raster, 26 | xml2 27 | Remotes: mikejohnson51/AOI 28 | License: MIT + file LICENSE 29 | Encoding: UTF-8 30 | LazyData: true 31 | RoxygenNote: 6.1.0 32 | Suggests: testthat 33 | -------------------------------------------------------------------------------- /HydroData.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Mike Johnson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("%>%") 4 | export(download.url) 5 | export(explore) 6 | export(findAirports) 7 | export(findCDL) 8 | export(findGAGESII) 9 | export(findNED) 10 | export(findNHD) 11 | export(findNID) 12 | export(findNLCD) 13 | export(findNLDI) 14 | export(findNWIS) 15 | export(findNearestAirports) 16 | export(findNearestCOMID) 17 | export(findNearestHUC12) 18 | export(findNearestNWIS) 19 | export(findNearestWaterbodies) 20 | export(findRoads) 21 | export(findSSURGO) 22 | export(findSnotel) 23 | export(findWBD) 24 | export(findWaterPoly) 25 | export(findWaterbodies) 26 | export(meta.data) 27 | export(mosaic.hd) 28 | export(query_cida) 29 | export(return.what) 30 | export(saveHD) 31 | export(to_sf) 32 | export(writeHD) 33 | import(AOI) 34 | import(leaflet) 35 | importFrom(crayon,"%+%") 36 | importFrom(crayon,blue) 37 | importFrom(crayon,cyan) 38 | importFrom(crayon,white) 39 | importFrom(crayon,yellow) 40 | importFrom(htmlwidgets,saveWidget) 41 | importFrom(httr,GET) 42 | importFrom(httr,progress) 43 | importFrom(httr,write_disk) 44 | importFrom(jsonlite,fromJSON) 45 | importFrom(magrittr,"%>%") 46 | importFrom(raster,crop) 47 | importFrom(raster,extent) 48 | importFrom(raster,intersect) 49 | importFrom(raster,mosaic) 50 | importFrom(raster,raster) 51 | importFrom(raster,stack) 52 | importFrom(raster,stackApply) 53 | importFrom(raster,writeRaster) 54 | importFrom(sf,as_Spatial) 55 | importFrom(sf,read_sf) 56 | importFrom(sf,st_as_sf) 57 | importFrom(sf,st_buffer) 58 | importFrom(sf,st_coordinates) 59 | importFrom(sf,st_crs) 60 | importFrom(sf,st_intersection) 61 | importFrom(sf,st_transform) 62 | importFrom(sf,st_write) 63 | importFrom(sf,st_zm) 64 | importFrom(sp,CRS) 65 | importFrom(sp,SpatialPoints) 66 | importFrom(sp,SpatialPointsDataFrame) 67 | importFrom(sp,spTransform) 68 | importFrom(utils,flush.console) 69 | importFrom(utils,head) 70 | importFrom(utils,read.csv) 71 | importFrom(utils,read.delim) 72 | importFrom(utils,read.table) 73 | importFrom(utils,tail) 74 | importFrom(utils,unzip) 75 | importFrom(utils,write.csv) 76 | importFrom(xml2,read_xml) 77 | importFrom(xml2,xml_attr) 78 | importFrom(xml2,xml_children) 79 | importFrom(xml2,xml_root) 80 | -------------------------------------------------------------------------------- /R/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/R/.DS_Store -------------------------------------------------------------------------------- /R/HydroData.R: -------------------------------------------------------------------------------- 1 | #' HydroData 2 | #' 3 | #' \code{HydroData} package 4 | #' 5 | #' Access earth systems geospatial and observation data programatically 6 | #' 7 | #' See the README on 8 | #' 9 | #' @docType package 10 | #' @name HydroData 11 | #' 12 | #' @import AOI 13 | #' @import leaflet 14 | #' @importFrom crayon %+% blue yellow cyan white 15 | #' @importFrom raster writeRaster raster mosaic extent intersect crop stack stackApply 16 | #' @importFrom httr progress GET write_disk 17 | #' @importFrom jsonlite fromJSON 18 | #' @importFrom sf st_zm read_sf as_Spatial st_as_sf st_coordinates st_write st_transform st_intersection st_buffer st_crs 19 | #' @importFrom sp SpatialPoints SpatialPointsDataFrame CRS spTransform 20 | #' @importFrom utils head tail write.csv unzip flush.console read.table read.delim read.csv 21 | #' @importFrom htmlwidgets saveWidget 22 | #' @importFrom xml2 read_xml xml_root xml_children xml_attr 23 | 24 | NULL 25 | -------------------------------------------------------------------------------- /R/findAirports.R: -------------------------------------------------------------------------------- 1 | #' @title Find Airport Data 2 | #' @description \code{findAirports} returns a \code{SpatialPointsDataframe} of all airports within an AOI. 3 | #' Data comes from the \href{https://openflights.org/data.html}{Openflights} database and includes the following attributes: 4 | #' \itemize{ 5 | #' \item 'name' : \code{character} Name of airport. May or may not contain the City name. 6 | #' \item 'city' : \code{character} Main city served by airport. May be spelled differently from Name. 7 | #' \item 'country': \code{character} Country or territory where airport is located. 8 | #' \item 'IATA' : \code{character} 3-letter IATA code 9 | #' \item 'ICAO' : \code{numeric} 4-letter ICAO code 10 | #' \item 'lat' : \code{numeric} Latitude of airport 11 | #' \item 'lon' : \code{numeric} Longitude of airport 12 | #' } 13 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 14 | #' @param ids If TRUE, a vector of airport ICAO codes is added to retuned list (default = \code{FALSE}) 15 | #' @return a list of minimum length 2: AOI and ap 16 | #' @examples 17 | #' \dontrun{ 18 | #' ap = getAOI(state = "CO", county = "El Paso") %>% findAirports() 19 | #' } 20 | #' @author Mike Johnson 21 | #' @export 22 | 23 | findAirports = function(AOI = NULL, ids = FALSE) { 24 | 25 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 26 | if(any(class(AOI) == "sf")){ AOI = as_Spatial(AOI) } 27 | 28 | air = sf::st_as_sf(x = HydroData::ap, coords = c('lon', 'lat'), crs = 4269 ) %>% sf::as_Spatial() 29 | 30 | sp = air[AOI$AOI,] 31 | 32 | if (dim(sp)[1] == 0) { cat(crayon::red("0 airports found in AOI")) } else { 33 | 34 | AOI[["ap"]] = sp 35 | if(ids){ AOI[["ICAO"]] = sp$ICAO} 36 | 37 | report = paste(length(sp), "Airport(s)") 38 | 39 | AOI = return.what(AOI, type = 'ap', report, vals = if(ids){"ICAO"}else{NULL}) 40 | } 41 | 42 | return(AOI) 43 | 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /R/findCDL.R: -------------------------------------------------------------------------------- 1 | #' @title Find Cropland Land Cover Data from the Cropand Data Layer 2 | #' @description \code{findCLD} returns \code{Raster} land cover data from the USDA Cropland Data Layer Dataset (\href{https://nassgeodata.gmu.edu/CropScape/}{Cropscape}) for an AOI. 3 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 4 | #' @param year the year(s) to download. Options include 2008-2017 for most locations. Default = 2017 5 | #' @return a list() of minimum length 2: AOI and cld 6 | #' @examples 7 | #' \dontrun{ 8 | #' dt = getAOI(clip = list("Devil Tower")) %>% findCDL() 9 | #' dt = getAOI(clip = list("Devil Tower")) %>% findCDL(2011:2016) 10 | #' } 11 | #' @author Mike Johnson 12 | #' @export 13 | 14 | findCDL = function(AOI, year = 2017){ 15 | 16 | `%+%` = crayon::`%+%` 17 | 18 | if(!(class(AOI) %in% c("list", "HydroData"))){AOI = list(AOI = AOI)} 19 | 20 | if(year > 2017 || year < 2008){stop("USDA CropScape Data only avaiable between 2008 and 2017. Please select a year within this range.")} 21 | 22 | cld.proj = "+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" 23 | 24 | shp.p = sf::st_transform(sf::st_as_sf(AOI$AOI), cld.proj) %>% AOI::bbox_st() 25 | 26 | bb = paste(shp.p$xmin,shp.p$ymin, shp.p$xmax,shp.p$ymax, sep = ',') 27 | 28 | urls = paste0("https://nassgeodata.gmu.edu/axis2/services/CDLService/GetCDLFile?year=",year,"&bbox=", bb) 29 | 30 | for(j in seq_along(urls)){ 31 | cat(crayon::white(paste0("Downloading (", j, "/", length(urls), "): ")) %+% crayon::yellow(year[j]), "\n") 32 | file = gsub(".*|.*", "", readLines(urls[j], warn = F)) 33 | check = download.url(url = file) 34 | tmp = raster::raster(check$destfile) 35 | tmp = raster::projectRaster(tmp, crs = AOI::aoiProj, method = 'ngb') 36 | tmp = raster::crop(tmp, AOI$AOI) 37 | raster::colortable(tmp) <- col_crops$color 38 | AOI[[paste0("cld", year[j])]] = tmp 39 | } 40 | 41 | cat(crayon::white("Returned object contains: ") %+% crayon::green("cropped crop lands raster for" , paste(year, collapse = ", "),"\n")) 42 | 43 | class(AOI) = "HydroData" 44 | return(AOI) 45 | } 46 | 47 | -------------------------------------------------------------------------------- /R/findGAGESII.R: -------------------------------------------------------------------------------- 1 | #' @title Find GAGESII points and basins 2 | #' @description The 'Geospatial Attributes of Gages for Evaluating Streamflow, version II' 3 | #' (\href{https://water.usgs.gov/GIS/metadata/usgswrd/XML/gagesII_Sept2011.xml#Entity_and_Attribute_Information}{GAGESII}) 4 | #' provides geospatial data and classifications for 9,322 stream gages maintained by the U.S. Geological Survey (USGS). \code{findGAGESII} 5 | #' returns a \code{SpatialPointsDataFrame*} of GAGESII outlets within an AOI. Data comes from the USGS CIDA server and contains the following attributes: 6 | #' \itemize{ 7 | #' \item 'id' : \code{character} Internal feature number 8 | #' \item 'STAID' : \code{character} USGS NWIS Station ID 9 | #' \item 'STANAME': \code{character} USGS NWIS Station Name 10 | #' \item 'CLASS' : \code{character} Classification (Ref or Non-ref) 11 | #' \item 'AGGECOREGION' : \code{numeric} Aggregated ecoregion 12 | #' \item 'DRAIN_SQKM' : \code{numeric} Drainage area, sq km 13 | #' \item 'HUC02' : \code{numeric} Hydrologic Unit Code, 2-digit 14 | #' \item 'LAT_GAGE' : \code{character} %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% 15 | #' \item 'LNG_GAGE' : \code{character} Longitude, decimal degrees 16 | #' \item 'STATE': \code{character} State at gage location 17 | #' \item 'HCDN_2009' : \code{character} If gage is part of HCDN-2009 18 | #' \item 'ACTIVE09' : \code{numeric} If gage active in water year 2009 19 | #' \item 'FLYRS1990' : \code{numeric} Number of complete years of flow data between 1900 and 2009 20 | #' \item 'FLYRS1950' : \code{numeric} Number of complete years of flow data between 1950 and 2009 21 | #' \item 'FLYRS1990' : \code{numeric} Number of complete years of flow data between 1990 and 2009 22 | #' } 23 | #' If \code{basins = TRUE} a \code{SpatialPolygonsDataFrame} of the gage drainage basin will also be appended 24 | #' to the returned list and contain the following attributes: 25 | #' \itemize{ 26 | #' \item 'id' : \code{character} Internal feature number and data identifier 27 | #' \item 'ogr_fid' : \code{character} Internal feature number 28 | #' \item 'area': \code{character} Basin Area 29 | #' \item 'perimeter' : \code{character} Basein Parameters 30 | #' \item 'gage_id' : \code{numeric} USGS NWIS Station ID 31 | #' } 32 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 33 | #' @param basins If TRUE, returns a list of GAGESII basin in addition 34 | #' @param ids If TRUE, a vector of gage IDs is added to retuned list (default = \code{FALSE}) 35 | #' @return a list() of minimum length 2: AOI and gagesII 36 | #' @examples 37 | #' \dontrun{ 38 | #' #Get GAGESII outlets for AOI 39 | #' bas = getAOI(clip = list("UCSB", 10, 10)) %>% findGAGESII() 40 | #' 41 | #' #Get GAGESII outlets and basins for AOI 42 | #' bas = getAOI(clip = list("UCSB", 10, 10)) %>% findGAGESII(basins = TRUE) 43 | #' } 44 | #' @author Mike Johnson 45 | #' @export 46 | 47 | 48 | findGAGESII = function(AOI = NULL, 49 | basins = FALSE, 50 | ids = FALSE) { 51 | 52 | if (!(class(AOI) %in% c("list", "HydroData"))) { 53 | AOI = list(AOI = AOI) 54 | } 55 | 56 | if(any(class(AOI$AOI) == "sf")){ AOI$AOI = as_Spatial(AOI$AOI) } 57 | 58 | sl = query_cida(AOI$AOI, type = 'gagesII', spatial = T) 59 | 60 | 61 | if (!is.null(sl)) { 62 | AOI[["gagesII"]] = sl 63 | 64 | if (basins) { 65 | AOI[["gagesII_basin"]] = query_cida(AOI$AOI, type = 'gagesii_basins', spatial = T) 66 | } 67 | 68 | report = paste0(length(sl), " gagesII stations", if (basins) { 69 | " and basins" } else {NULL}) 70 | 71 | AOI = return.what(AOI, type = 'gagesII', report, vals = if (ids){"STAID"} else {NULL}) 72 | } 73 | 74 | return(AOI) 75 | } 76 | -------------------------------------------------------------------------------- /R/findNED.R: -------------------------------------------------------------------------------- 1 | #' @title Find National Elevation Data (NED) 2 | #' @description \code{findNED} returns \code{Raster} elevation data from the National Elevation Dataset (\href{https://nationalmap.gov/elevation.html}{NED}) for an AOI. 3 | #' Data comes the the USA National Map. 4 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 5 | #' @param res resolution of NED data. 1 equals 1 arc second, 13 equals 1/3 arc second. 6 | #' @return a list() of minimum length 2: AOI and NED 7 | #' @examples 8 | #' \dontrun{ 9 | #' el.paso.elev = getAOI(state = "CO", county = "El Paso") %>% findNED(res = 1) 10 | #' } 11 | #' @author Mike Johnson 12 | #' @export 13 | #' 14 | 15 | findNED = function(AOI = NULL, res = 1){ 16 | 17 | `%+%` = crayon::`%+%` 18 | 19 | if(!(class(AOI) %in% c("list", "HydroData"))){AOI = list(AOI = AOI)} 20 | 21 | if(!(res %in% c(1,13))){stop("Resoultion must be either 1 (1 arc second) or 13 (1/3 arc second).")} 22 | 23 | bb = AOI$AOI@bbox 24 | 25 | lon = head(sprintf("%03d", abs(seq(floor(bb[1,1]), ceiling(bb[1,2]), by = 1))), -1) 26 | lat = head(seq(ceiling(bb[2,2]), floor(bb[2,1]), by = -1), -1) 27 | mat = expand.grid(lat,lon) 28 | 29 | urls = vector() 30 | urls.bu = vector() 31 | 32 | for(i in 1:dim(mat)[1]){ 33 | urls[i] = paste0('https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/', 34 | res, 35 | '/IMG/USGS_NED_', 36 | res, 37 | '_n', 38 | mat[i,1], 39 | "w", 40 | mat[i,2], 41 | "_IMG.zip") 42 | } 43 | 44 | for(i in 1:dim(mat)[1]){ 45 | urls.bu[i] = paste0('https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/', 46 | res, 47 | '/IMG/USGS_NED_',res, "_n", 48 | mat[i,1], 49 | "w", 50 | mat[i,2], 51 | ".zip") 52 | } 53 | 54 | if(length(urls) > 1){ 55 | verb = 'are' 56 | noun = 'rasters' 57 | } else { 58 | verb = 'is' 59 | noun = 'raster' 60 | } 61 | 62 | #message(paste("There", verb, length(urls), "NED", noun, "in this AOI.")) 63 | all.rast = list() 64 | 65 | for(i in seq_along(urls)){ 66 | cat(crayon::white(paste0("Downloading (", i, "/", length(urls), "): ")) %+% crayon::yellow(basename(urls[i])), "\n") 67 | check <- download.url(url = urls.bu[i]) 68 | if(check$code != 200){ 69 | check = download.url(url = urls[i]) 70 | } 71 | rast = unzip_crop(AOI = AOI$AOI, path = check$destfile) 72 | all.rast[[i]] = rast 73 | } 74 | 75 | fin = mosaic.hd(all.rast) 76 | 77 | AOI[["NED"]] = fin[[1]] 78 | 79 | cat(crayon::white("Returned object contains: ") %+% crayon::green("cropped", res, "arc sec elevation raster\n")) 80 | 81 | class(AOI) = "HydroData" 82 | return(AOI) 83 | } 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /R/findNHD.R: -------------------------------------------------------------------------------- 1 | #' @title Find National Hydrography River Networks 2 | #' @description 3 | #' \code{findNHD} returns a \code{SpatialLinesDataframe} of all NHDFlowlines reaches within an AOI. 4 | #' Data comes from the USGS CIDA server and contain 90 attributes, perhaps most notably: 5 | #' \itemize{ 6 | #' \item 'comid' : \code{integer} Integer value that uniquely identifies the occurrence of each feature in the NHD 7 | #' \item 'reachcode' : \code{character} Unique identifier for a ‘reach’. The first eight numbers are the WBD_HUC8 8 | #' \item 'fdate': \code{POSITct} Date of last feature modification 9 | #' \item 'gnis_id' : \code{character} Unique identifier assigned by GNIS 10 | #' \item 'gnis_name' : \code{character} Proper name, term, or expression by which a particular geographic entity is known 11 | #' \item 'lengthkm' : \code{numeric} Length of linear feature based on Albers Equal Area 12 | #' \item 'areasqkm' : \code{numeric} Area of areal feature based on Albers Equal Area, 13 | #' \item 'flowdir' : \code{character} Direction of flow relative to coordinate order. 14 | #' \item 'wbareacomi' : \code{integer} The COMID of the waterbody through which the flowline flows. 15 | #' \item 'ftype': \code{character} unique identifier of a feature type 16 | #' } 17 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 18 | #' @param ids If TRUE, a vector of NHD COMIDs is added to retuned list (default = \code{FALSE}) 19 | #' @return a list() of minimum length 2: AOI and nhd 20 | #' @examples 21 | #' \dontrun{ 22 | #' nhd = getAOI(clip = list("Tuscaloosa, AL", 10, 10)) %>% findNHD() 23 | #' } 24 | #' @author Mike Johnson 25 | #' @export 26 | 27 | findNHD = function(AOI = NULL, comid = NULL, nwis = NULL, streamorder = NULL, crop = T) { 28 | 29 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 30 | 31 | substrRight <- function(x, n){ 32 | substr(x, nchar(x)-n+1, nchar(x)) 33 | } 34 | 35 | f = NULL 36 | df = NULL 37 | 38 | if(!is.null(nwis)){ 39 | url = paste0( "https://cida.usgs.gov/nldi/nwissite/", 'USGS-', nwis) 40 | mat = NULL 41 | for(i in 1:length(url)){ 42 | c <- rawToChar(httr::RETRY("GET", url[i], times = 10, pause_cap = 240)$content) 43 | f.comid = jsonlite::fromJSON(c, simplifyVector = TRUE) 44 | comid = f.comid$features$properties$comid 45 | mat = rbind(mat, c(substrRight(url[i], 8), comid)) 46 | } 47 | 48 | df = data.frame(nwis = mat[,1], comid = mat[,2], stringsAsFactors = FALSE) 49 | comid = df$comid 50 | } 51 | 52 | 53 | if(!is.null(streamorder)){ 54 | 55 | f = paste0('', 56 | '', 57 | 'streamorde', 58 | '',streamorder - 1,'', 59 | '' 60 | ) 61 | } 62 | 63 | 64 | if(!is.null(comid)){ 65 | siteText <- "" 66 | 67 | for(i in comid){ 68 | siteText <- paste0(siteText,'', 69 | 'comid', 70 | '',i,'', 71 | '') 72 | } 73 | 74 | f = paste0('', 75 | siteText, 76 | '') 77 | } 78 | 79 | sl = query_cida(AOI = AOI$AOI, type = 'nhd', filter = f, spatial = F) 80 | 81 | if(!is.null(df)) { sl = merge(sl, df, "comid")} 82 | 83 | if(!is.null(sl)){ 84 | 85 | if(!is.null(AOI$AOI)){sl = sf::st_transform(sl, as.character(AOI::aoiProj)) %>% 86 | cropHUC(AOI = AOI$AOI, crop = crop) 87 | } 88 | 89 | AOI[["nhd"]] <- if(any(class(sl) %in% "sf")){ sf::as_Spatial(sl) } else { sl } 90 | 91 | report = paste(length(AOI$nhd), "nhd flowlines") 92 | 93 | ids = FALSE 94 | AOI = return.what(AOI, type = 'nhd', report, vals = if(ids){"comid"}) 95 | AOI[sapply(AOI, is.null)] <- NULL 96 | } 97 | 98 | return(AOI) 99 | } 100 | -------------------------------------------------------------------------------- /R/findNID.R: -------------------------------------------------------------------------------- 1 | #' @title Find Dams in the US Army Core National Inventory (NID) 2 | #' @description \code{findNID} returns a \code{SpatialPointsDataFrame} 3 | #' of all US Army Corps Dams for an Area of Interest from the National Inventory of Dams dataset. 4 | #' The National Inventory of Dams (NID) is a congressionally authorized database documenting dams in the United States and its territories 5 | #' This dataset is accessed through the \code{dams} R package and contains 61 attributes, perhaps most notably: 6 | #' \itemize{ 7 | #' \item 'Dam_Name' : \code{character} Dam Name 8 | #' \item 'NID_ID' : \code{character} Unique ID for the dam 9 | #' \item 'River': \code{character} Name of the river 10 | #' \item 'Owner_Type' : \code{character} Type of Owner 11 | #' \item 'Dam_Type' : \code{character} Type of Dam 12 | #' \item 'Primary_Purpose' : \code{numeric} Primary Purpose served 13 | #' \item 'Dam_Length' : \code{numeric} Length of the dam 14 | #' \item 'Dam_Height' : \code{numeric} Height of the dam 15 | #' \item 'Max_Discharge' : \code{numeric} Maximum Discharge 16 | #' \item 'Max_Storage': \code{character} Maximum Storage 17 | #' \item 'Normal_Storage': \code{character} Normal Storage 18 | #' } 19 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 20 | #' @param ids If TRUE, a vector of Dam IDs is added to retuned list (default = \code{FALSE}) 21 | #' @return a list() of minimum length 2: AOI and dams 22 | #' @examples 23 | #' \dontrun{ 24 | #' # Find all dams in Texas 25 | #' tx.dams = getAOI(state = "TX") %>% findNID() 26 | #'} 27 | #' @author Mike Johnson 28 | #' @export 29 | 30 | findNID = function(AOI = NULL, ids = FALSE){ 31 | 32 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 33 | 34 | dams = dams::nid_cleaned 35 | dams = dams[!is.na(dams$Longitude),] 36 | dams = dams[!is.na(dams$Latitude),] 37 | 38 | sp = sf::st_as_sf(x = dams, coords = c('Longitude', 'Latitude'), crs = 4269) %>% sf::as_Spatial() 39 | 40 | sp = sp[AOI$AOI, ] 41 | 42 | if (dim(sp)[1] == 0) { warning("0 dams found in AOI") } else { 43 | 44 | AOI[["dams"]] = sp 45 | 46 | report = paste(length(sp), "NID dam(s)") 47 | 48 | AOI = return.what(AOI, type = 'dams', report, vals = if(ids){"Dam_Name"}else{NULL}) 49 | 50 | } 51 | 52 | return(AOI) 53 | 54 | } 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /R/findNLCD.R: -------------------------------------------------------------------------------- 1 | #' @title Find National Land Cover Products (NLCD) 2 | #' @description \code{findNLCD} returns \code{Raster} land cover data from the National Land Cover Dataset (\href{https://www.mrlc.gov}{NLCD}) for an AOI. 3 | #' Data comes the the USA National Map and is avaialble for years 2001, 2006, 2011. 4 | #' In additon to landcover, users can get data reflecting impervious surface and conaopy cover. 5 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 6 | #' @param year the year(s) to download. Options include 2001, 2006, 2011. Default = 2011 7 | #' @param type the type of data to downlaod. Options include landcover, canopy, and impervious. Default = landcover 8 | #' @return a list() of minimum length 2: AOI and NLCD 9 | #' @examples 10 | #' \dontrun{ 11 | #' dt = getAOI(clip = list("Devil Tower")) %>% findNLDC(2006, 'landcover') 12 | #' dt = getAOI(clip = list("Devil Tower")) %>% findNLDC(2011, 'canopy') 13 | #' dt = getAOI(clip = list("Devil Tower")) %>% findNLDC(2011, 'impervious') 14 | #' } 15 | #' @author Mike Johnson 16 | #' @export 17 | 18 | findNLCD = function(AOI = NULL, year = 2011, type = "landcover"){ 19 | 20 | `%+%` = crayon::`%+%` 21 | 22 | if(!(type %in% c('canopy', 'impervious', "landcover"))){stop(paste0(type, " is not a valid NLCD layer."))} 23 | if(type == "landcover") {ext = "_LC_" } 24 | if(type == "canopy") {ext = "_CAN_" } 25 | if(type == "impervious") {ext = "_IMP_" } 26 | 27 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 28 | 29 | all.rast = list() 30 | 31 | if(!any(year %in% c(2001,2006,2011))){ stop("NLCD only avaiable for 2001, 2006, and 2011.")} 32 | 33 | USAbb = c(48,66,24,123) 34 | bb = matrix(AOI$AOI@bbox, ncol = 2) 35 | 36 | lon.bb = c(abs(ceiling(bb[1,2])), abs(floor(bb[1,1]))) 37 | 38 | lon = seq(USAbb[2], USAbb[4], 3) 39 | i = which.max(1/(lon.bb[1] - lon)) 40 | j = sum((lon.bb[2] - lon) > 0) # which.max(1/(lon.bb[2] - lon)) 41 | k = seq(i,j,1) 42 | lon.f = sprintf('%03d', lon[k]) 43 | 44 | lat.bb = c(floor(bb[2,1]), ceiling(bb[2,2])) 45 | lat = seq(USAbb[3], USAbb[1], 3) 46 | i = which.max(1/(lat.bb[1] - lat)) 47 | j = sum((lat.bb[2] - lat) > 0) 48 | k = seq(i,j,1) 49 | lat.f = lat[k] 50 | 51 | mat = expand.grid(lat.f,lon.f) 52 | 53 | urls = vector() 54 | 55 | for(i in 1:dim(mat)[1]){ 56 | for(j in 1:length(year)){ 57 | urls = append(urls, paste0('https://prd-tnm.s3.amazonaws.com/StagedProducts/NLCD/data/', 58 | year[j], 59 | '/', 60 | type, 61 | "/3x3/NLCD", 62 | year[j], 63 | ext, 64 | "N", 65 | mat[i,1], 66 | "W", 67 | mat[i,2], 68 | ".zip")) 69 | } 70 | } 71 | 72 | if(length(urls)/length(year) > 1){ 73 | verb = 'are' 74 | noun = 'rasters' 75 | } else { 76 | verb = 'is' 77 | noun = 'raster' 78 | } 79 | 80 | #message(paste("There", verb, length(urls)/length(year), "NLCD", noun, "in this AOI per year.")) 81 | 82 | for(j in seq_along(year)){ 83 | 84 | xxx = grep(year[j], urls, value=TRUE) 85 | 86 | for(i in seq_along(xxx)){ 87 | cat(crayon::white(paste0("Downloading ", year[j], " " ,type, " raster (", i, "/", length(xxx), "): ")) %+% crayon::yellow(basename(xxx[i]), "\n" )) 88 | check = download.url(url = xxx[i]) 89 | rast = unzip_crop(AOI = AOI$AOI, path = check$destfile, file.type = "tif") 90 | all.rast[[i]] = rast 91 | } 92 | 93 | dat = mosaic.hd(all.rast) 94 | 95 | AOI[[paste0("nlcd", year[j])]] = dat 96 | 97 | } 98 | 99 | cat(crayon::white("Returned object contains: ") %+% crayon::green("cropped", type, "raster for ", paste(year, collapse = ","), "\n")) 100 | 101 | class(AOI) = "HydroData" 102 | return(AOI) 103 | } 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /R/findNLDI.R: -------------------------------------------------------------------------------- 1 | #' Get NLDI Data 2 | #' 3 | #' This function acts as a formal query to the NLDI 4 | #' 5 | #' @param comid a COMID value (see \code{findNHD} and \code{findNearestCOMID}) 6 | #' @param nwis a USGS station values (see \code{findUSGS} and \code{findNearestUSGS}) 7 | #' @param huc12 a HUC12 id (see \code{findHUC}) 8 | #' @param type a type of data to return ("UT", "UM","DD", "DM", "basin") 9 | #' @param spatial if \code{TRUE} returned data will be sp, else of type sf 10 | #' @param resources what type of resources to add ("comid", "huc12pp", "npdes_rad", "nwis", "wqp") 11 | #' 12 | #' @return a list of spatial / sf features 13 | #' @export 14 | #' @author Mike Johnson 15 | #' 16 | 17 | findNLDI = function(comid = NULL, 18 | nwis = NULL, 19 | huc12 = NULL, 20 | type = NULL, 21 | spatial = TRUE, 22 | resources = NULL) { 23 | 24 | all.sources = c("comid", "huc12pp", "npdes_rad", "nwis", "wqp") 25 | 26 | get_basin_url = function(base.url, url) { 27 | l = readChar(url, nchars = 1000, useBytes = TRUE) 28 | comid = gsub(".*comid\":\"*|\",\"navigation*.*", "", l) 29 | return(paste0(base.url, "comid/", comid, "/basin")) 30 | } 31 | 32 | urls = list() 33 | 34 | if (sum(!is.null(comid), !is.null(nwis), !is.null(huc12)) != 1) { 35 | stop("message here") 36 | } 37 | 38 | base.url = "https://cida.usgs.gov/nldi/" 39 | 40 | if (!is.null(comid)) { 41 | url = paste0(base.url, "comid/", comid) 42 | } 43 | if (!is.null(nwis)) { 44 | url = paste0(base.url, "nwissite/USGS-", nwis) 45 | } 46 | if (!is.null(huc12)) { 47 | url = paste0(base.url, "huc12pp/", huc12) 48 | } 49 | 50 | urls[["site"]] = url 51 | 52 | for (i in seq_along(type)) { 53 | if (type[i] %in% c("UM", "UT", "DD", "DM")) { 54 | urls[[type[i]]] = paste0(url, "/navigate/", type[i]) 55 | } 56 | } 57 | 58 | if (any(type == 'basin')) { 59 | if (any(!is.null(comid), !is.null(nwis))) { 60 | urls[["basin"]] = paste0(url, "/basin") 61 | } else { 62 | urls[["basin"]] = get_basin_url(base.url, url) 63 | } 64 | } 65 | 66 | for (i in seq_along(resources)) { 67 | tmp = paste0(urls[[2]], "/", resources[i]) 68 | if (length(nchar(readChar(tmp, nchars = 40))) != 0) { 69 | urls[[resources[i]]] = tmp 70 | } else { 71 | message(paste0("No '" , resources[i], "' in this region")) 72 | } 73 | } 74 | 75 | shp = lapply(urls, sf::read_sf) 76 | 77 | for(i in 1:length(shp)){ 78 | if( any(is.na(as.character(sf::st_bbox(shp[[i]])))) ) { shp[[i]] = NULL} 79 | } 80 | 81 | if (spatial) { 82 | shp = lapply(shp, sf::as_Spatial) 83 | } 84 | 85 | shp[['bb']] = AOI::getBoundingBox(shp[[length(shp)]]) 86 | return(shp) 87 | 88 | } 89 | -------------------------------------------------------------------------------- /R/findNWIS.R: -------------------------------------------------------------------------------- 1 | #' @title Find USGS NWIS Stream Gages 2 | #' @description \code{findNWIS} returns a \code{SpatialPointsDataFrame} 3 | #' of all USGS NWIS gages for an Area of Interest. This dataset is accessed through the NWIS web portal and contains the following attributes: 4 | #' \itemize{ 5 | #' \item 'OBJECTID' : \code{character} Unique ID in dataset 6 | #' \item 'feature_id' : \code{character} NHD COMID for reach 7 | #' \item 'site_no': \code{character} NWIS ID number 8 | #' \item 'site_name' : \code{character} Name of site 9 | #' \item 'da_sqkm' : \code{character} Area drainign to gage in square kilometers 10 | #' \item 'lat_reachCent' : \code{numeric} Latitude of the reach center, decimil degrees 11 | #' \item 'lon_reachCent' : \code{numeric} Longitude of the reach center, decimil degrees 12 | #' } 13 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 14 | #' @param ids If TRUE, a vector of NIWS gage IDs are added to retuned list (default = \code{FALSE}) 15 | #' @param comids f TRUE, a vector of NHD COMIDs IDs are added to retuned list (default = \code{FALSE}) 16 | #' @return a list() of minimum length 2: AOI and nwis 17 | #' @examples 18 | #' \dontrun{ 19 | #' co = getAOI(state = "CO") %>% findNWIS() 20 | #' } 21 | #' @author Mike Johnson 22 | #' @export 23 | #' 24 | 25 | 26 | findNWIS = function(AOI = NULL, siteType = "ST", paramCode = "00060", startDate = NULL, endDate = NULL, active = TRUE, full = FALSE){ 27 | 28 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 29 | 30 | if(all(!is.null(startDate), is.null(endDate))){ endDate = Sys.Date() - 1} 31 | bb = round(AOI::bbox_st(AOI$AOI), 7) 32 | 33 | url = paste0("https://waterservices.usgs.gov/nwis/site/?format=mapper&bBox=", 34 | bb$xmin, ",", bb$ymin, ",", bb$xmax, ",", bb$ymax, 35 | if(!is.null(siteType)) { paste0("&siteType=", paste(siteType, collapse = ","))}, 36 | if(full) {"&seriesCatalogOutput=true"}, 37 | if(!is.null(paramCode)) { paste0("¶meterCd=", paste(paramCode, collapse = ","))}, 38 | if(!is.null(startDate)) { paste0("&startDT=", startDate)}, 39 | if(!is.null(endDate)) { paste0("&endDT=", endDate)}, 40 | "&siteStatus=", ifelse(active, "active", "all")) 41 | 42 | dest = file.path(tempdir(), "tmp.xml") 43 | y = httr::GET(url, httr::write_disk(dest, overwrite=T), httr::add_headers('--header="Accept-Encoding: gzip"')) 44 | 45 | if(y$status_code != 200) { message("No gages found in this AOI.")} else { 46 | 47 | y <- xml2::read_xml(dest) 48 | doc <- xml2::xml_root(y) 49 | sc <- xml2::xml_children(doc) 50 | sites <- xml2::xml_children(sc) 51 | site_no <- xml2::xml_attr(sites, "sno") 52 | station_nm <- xml2::xml_attr(sites, "sna") 53 | site_type <- xml2::xml_attr(sites, "cat") 54 | lat <- as.numeric(xml2::xml_attr(sites, "lat")) 55 | lon <- as.numeric(xml2::xml_attr(sites, "lng")) 56 | agency_cd <- xml2::xml_attr(sites, "agc") 57 | 58 | df <- data.frame(agency_cd, site_no, station_nm, site_type, 59 | lat, lon, stringsAsFactors=FALSE) 60 | 61 | 62 | sp = sf::st_as_sf(x = df, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) %>% sf::as_Spatial() 63 | 64 | AOI[["nwis"]] = sp 65 | 66 | report = paste(length(unique(sp$site_no)), "USGS NWIS", paste0(siteType, collapse = ", "), "stations") 67 | ids = FALSE 68 | AOI = return.what(AOI, type = 'nwis', report, vals = if(ids){"site_no"} else {NULL}) 69 | return(AOI) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /R/findNearestAirports.R: -------------------------------------------------------------------------------- 1 | #' @title Find the Airports nearest a point 2 | #' @description \code{findNearestAirports} returns a \code{SpatialPointsDataFrame} of the 'n' number of airports closest to a declared point. 3 | #' @param point a point described by lat/long, can be piped from \link[AOI]{geocode} 4 | #' @param n the number of Airports to find (default = 5) 5 | #' @param ids If TRUE, a vector of airport ICAO IDs is added to retuned list (default = \code{FALSE}) 6 | #' @param bb If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE}) 7 | #' @export 8 | #' @seealso findAirports 9 | #' @return a list() of minimum length 2: AOI and ap 10 | #' @author Mike Johnson 11 | #' @examples 12 | #' \dontrun{ 13 | #' pt = geocode("UCSB") %>% findNearestAirports(n = 5) 14 | #' } 15 | 16 | findNearestAirports = function(point = NULL, n = 5, ids = FALSE, bb = FALSE){ 17 | 18 | fin = list(loc = point) 19 | 20 | df = HydroData::ap 21 | df = sf::st_as_sf(x = df, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) 22 | point = sf::st_as_sf(x = point, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) 23 | dist = data.frame(ICAO = df$ICAO, Distance_km = sf::st_distance(x = df, y = point)) 24 | dist = dist[order(dist$Distance_km)[1:n],] 25 | 26 | fin[['ap']] = sf::as_Spatial(merge(df, dist, by = "ICAO")) 27 | if (bb) { fin[["AOI"]] = AOI::getBoundingBox(fin$ap) } 28 | if (ids) { fin[["ICAO"]] = unique(fin$closest_ap$ICAO) } 29 | 30 | return(fin) 31 | } 32 | 33 | -------------------------------------------------------------------------------- /R/findNearestCOMID.R: -------------------------------------------------------------------------------- 1 | #' @title Find Neareast COMIDs 2 | #' @description \code{findNearestCOMID} returns a \code{SpatialPointsDataFrame} of the 'n' number of COMIDs closest to a declared point. 3 | #' @param point a point described by lat/long, can be piped from \link[AOI]{geocode} 4 | #' @param n the number of COMIDs to find (default = 5) 5 | #' @param ids If TRUE, a vector of NHD COMIDs is added to retuned list (default = \code{FALSE}) 6 | #' @param bb If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE}) 7 | #' @export 8 | #' @seealso findAirports 9 | #' @return a list() of minimum length 2: AOI and ap 10 | #' @author Mike Johnson 11 | #' @examples 12 | #' \dontrun{ 13 | #' pt = geocode("University of Oregon") %>% findNearestCOMID(n = 5) 14 | #' } 15 | 16 | findNearestCOMID = function(point = NULL, n = 5, ids = FALSE, streamorder = NULL, bb = FALSE){ 17 | 18 | h = 5 19 | w = 5 20 | lines = data.frame() 21 | fin = list(loc = point) 22 | 23 | while (dim(lines)[1] < n) { 24 | lines <- suppressWarnings( 25 | findNHD( 26 | AOI = suppressMessages(AOI::getAOI( clip = list(point$lat, point$lon, h, w ))), 27 | streamorder = streamorder) 28 | ) 29 | 30 | lines = lines[['nhd']] 31 | 32 | if (is.null(lines)) { 33 | lines = data.frame() 34 | } 35 | 36 | h = h + 2 37 | w = w + 2 38 | } 39 | 40 | lines = lines %>% sf::st_as_sf() 41 | point = sf::st_as_sf(x = point, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) 42 | dist = data.frame(comid = lines$comid, Distance_km = sf::st_distance(x = lines, y = point)) 43 | dist = dist[order(dist$Distance_km)[1:n], ] 44 | 45 | fin[["nhd"]] = as_Spatial(merge(lines, dist, by = "comid")) 46 | if (bb) { fin[["AOI"]] = AOI::getBoundingBox(fin$nhd) } 47 | if (ids) { fin[["comids"]] = unique(fin$nhd$comid) } 48 | 49 | return(fin) 50 | 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /R/findNearestHUC12.R: -------------------------------------------------------------------------------- 1 | #' @title Find Neareast HUC12 boundaries 2 | #' @description \code{findNearestHUC12} returns a \code{SpatialPolygonDataFrame} of the 'n' number of HUC12 basins closest to a declared point. 3 | #' @param point a point described by lat/long, can be piped from \link[AOI]{geocode} 4 | #' @param n the number of basins to find (default = 5) 5 | #' @param ids If TRUE, a vector of basin HUC IDs is added to retuned list (default = \code{FALSE}) 6 | #' @param bb If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE}) 7 | #' @export 8 | #' @seealso findWBD 9 | #' @return a list() of minimum length 2: AOI and wbd 10 | #' @author Mike Johnson 11 | #' @examples 12 | #' \dontrun{ 13 | #' pt = geocode("UCSB") %>% findNearestHUC12(n = 5) 14 | #' } 15 | 16 | findNearestHUC12 = function(point = NULL, n = 1, ids = FALSE, bb = FALSE){ 17 | 18 | h = 10 19 | w = 10 20 | lines = data.frame() 21 | fin = list(loc = point) 22 | 23 | while(dim(lines)[1] < n){ 24 | lines <- suppressWarnings(query_cida(AOI = suppressMessages( 25 | AOI::getAOI(clip = list(point$lat, point$lon, h, w))), 26 | type = 'huc12', 27 | spatial = FALSE)) 28 | 29 | if(is.null(lines)){lines = data.frame()} 30 | h = h + 2 31 | w = w + 2 32 | } 33 | 34 | point = sf::st_as_sf(x = point, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) 35 | dist = data.frame(huc12 = lines$huc12, Distance_km = sf::st_distance(x = lines, y = point)) 36 | dist = dist[order(dist$Distance_km)[1:n],] 37 | fin[["wbd"]] = merge(lines, dist, by = "huc12") 38 | 39 | 40 | if (bb) { fin[["AOI"]] = AOI::getBoundingBox(fin$closest_huc12) } 41 | if (ids) { fin[["huc12"]] = unique(fin$closest_huc12$huc12) } 42 | 43 | return(fin) 44 | 45 | } 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /R/findNearestUSGS.R: -------------------------------------------------------------------------------- 1 | #' @title Find Neareast NWIS stations 2 | #' @description \code{findNearestNWIS} returns a \code{SpatialPointsDataFrame} of the 'n' number of NWIS gages closest to a declared point. 3 | #' @param point a point described by lat/long, can be piped from \link[AOI]{geocode} 4 | #' @param n the number of NWIS gages to find (default = 5) 5 | #' @param ids If TRUE, a vector of station IDs is added to retuned list (default = \code{FALSE}) 6 | #' @param bb If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE}) 7 | #' @export 8 | #' @seealso findNWIS 9 | #' @return a list() of minimum length 2: AOI and nwis 10 | #' @author Mike Johnson 11 | #' @examples 12 | #' \dontrun{ 13 | #' pt = geocode("UCSB") %>% findNearestNWIS(n = 5) 14 | #' } 15 | 16 | findNearestNWIS = function(point = NULL, n = 5, ids = FALSE, bb = FALSE, ...) { 17 | 18 | h = 5 19 | w = 5 20 | sta = data.frame() 21 | fin = list(loc = point) 22 | 23 | while (dim(sta)[1] < n) { 24 | sta <- suppressWarnings( 25 | findNWIS( 26 | AOI = AOI::getAOI( clip = list(point$lat, point$lon, h, w )), ... ) 27 | ) 28 | 29 | sta = sta[['nwis']] 30 | 31 | if (is.null(sta)) { 32 | sta = data.frame() 33 | } 34 | 35 | h = h + 2 36 | w = w + 2 37 | } 38 | 39 | point = sf::st_as_sf(x = point, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) 40 | 41 | sta = sta %>% sf::st_as_sf( crs = sf::st_crs(point)) 42 | 43 | dist = data.frame(site_no = sta$site_no, Distance_km = sf::st_distance(x = sta, y = point)) 44 | dist = dist[order(dist$Distance_km)[1:n], ] 45 | 46 | fin[["nwis"]] = as_Spatial(merge(sta, dist, by = "site_no")) 47 | if (bb & dim(fin$nwis)[1] > 1) { fin[["AOI"]] = AOI::getBoundingBox(fin$nwis) } 48 | if (ids) { fin[["site_no"]] = unique(fin$nwis$site_no) } 49 | 50 | return(fin) 51 | } 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /R/findNearestWaterbodies.R: -------------------------------------------------------------------------------- 1 | #' @title Find Neareast NHD Waterbodies 2 | #' @description \code{findNearestWaterbodies} returns a \code{SpatialPointsDataFrame} of the 'n' number of NHDwaterbodies closest to a declared point. 3 | #' @param point a point described by lat/long, can be piped from \link[AOI]{geocode} 4 | #' @param n the number of NWIS gages to find (default = 5) 5 | #' @param ids If TRUE, a vector of station IDs is added to retuned list (default = \code{FALSE}) 6 | #' @param bb If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE}) 7 | #' @export 8 | #' @seealso findNWIS 9 | #' @return a list() of minimum length 2: AOI and nwis 10 | #' @author Mike Johnson 11 | #' @examples 12 | #' \dontrun{ 13 | #' pt = geocode("UCSB") %>% findNearestWaterbodies(n = 5) 14 | #' } 15 | 16 | findNearestWaterbodies = function(point = NULL, n = 5, ids = FALSE, bb = FALSE){ 17 | 18 | h = 10 19 | w = 10 20 | lines = data.frame() 21 | fin = list(loc = point) 22 | 23 | while(dim(lines)[1] < n){ 24 | lines <- suppressWarnings(query_cida(AOI = suppressMessages( 25 | AOI::getAOI(clip = list(point$lat, point$lon, h, w))), 26 | type = 'nhdwaterbody', 27 | spatial = FALSE)) 28 | 29 | if(is.null(lines)){lines = data.frame()} 30 | h = h + 2 31 | w = w + 2 32 | } 33 | 34 | point = sf::st_as_sf(x = point, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) 35 | dist = data.frame(objectid = lines$objectid, Distance_km = sf::st_distance(x = lines, y = point)) 36 | dist = dist[order(dist$Distance_km)[1:n],] 37 | 38 | fin[["waterbodies"]] = sf::as_Spatial(merge(lines, dist, by = "objectid")) 39 | if (bb) { fin[["AOI"]] = AOI::getBoundingBox(fin$waterbodies) } 40 | if (ids) { fin[["objectid"]] = unique(fin$waterbodies$objectid) } 41 | 42 | 43 | return(fin) 44 | 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /R/findRoads.R: -------------------------------------------------------------------------------- 1 | #' @title Find US Census Bureau TIGER Road Networks 2 | #' 3 | #' @description \code{findRoads} returns a \code{SpatialLinesDataFrame} of TIGER road networks cropped to an Area of Interest. 4 | #' This dataset is accessed through the US Census geo portal and contains the following attributes: 5 | #' \itemize{ 6 | #' \item 'LINEARID' : \code{character} Linear feature identifier 7 | #' \item 'FULLNAME' : \code{character} Feature Name 8 | #' \item 'RTTYP': \code{character} Route Type Code 9 | #' \item 'MTFCC' : \code{character} Road Classification 10 | #' \itemize{ 11 | #' \item S1100 Primary Roads 12 | #' \item R1011 Railroad Feature (Main, Spur, or Yard) 13 | #' \item R1051 Carline, Streetcar Track, Monorail, Other Mass Transit Rail) 14 | #' \item R1052 Cog Rail Line, Incline Rail Line, Tram 15 | #' \item S1100 Primary Road 16 | #' \item S1200 Secondary Road 17 | #' } 18 | #' } 19 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 20 | #' @return a list() of minimum length 2: AOI and tiger 21 | #' @examples 22 | #' \dontrun{ 23 | #' AOI = getAOI(clip = list("UCSB", 10, 10)) %>% findRoads() 24 | #' } 25 | #' @author Mike Johnson 26 | #' @export 27 | #' 28 | 29 | findRoads = function(AOI = FALSE) { 30 | 31 | `%+%` = crayon::`%+%` 32 | 33 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 34 | 35 | FIP = sprintf("%05d", as.numeric(AOI::counties[AOI$AOI,]$geoid)) 36 | 37 | urls = paste0("https://www2.census.gov/geo/tiger/TIGER2017/ROADS/tl_2017_",FIP, "_roads.zip") 38 | 39 | if (length(urls) > 1) { verb = 'are'; noun = 'files' } else { verb = 'is'; noun = 'file' } 40 | 41 | input.shp = list() 42 | 43 | sl <- for(i in seq_along(urls)){ 44 | cat(crayon::white(paste0("Downloading (", i, "/", length(urls), "): ")) %+% crayon::yellow(basename(urls[i]), "\n")) 45 | x = download.url(urls[i]) 46 | unzip(x$destfile, exdir = tempdir(), overwrite = TRUE) 47 | input.shp[[i]] = sf::read_sf(list.files(tempdir(), pattern = "roads.shp$", full.names = T)) 48 | input.shp[[i]] = sf::st_transform(input.shp[[i]], as.character(AOI$AOI@proj4string)) 49 | input.shp[[i]] = suppressMessages(suppressWarnings( sf::st_intersection(input.shp[[i]], sf::st_as_sf(AOI$AOI)))) 50 | input.shp[[i]] = sf::as_Spatial(input.shp[[i]]) 51 | } 52 | 53 | sl = do.call(rbind, input.shp) 54 | 55 | AOI[["tiger"]] <- sl 56 | 57 | #raster::crop(x = sl, y = raster::extent(AOI$AOI)) 58 | 59 | cat(crayon::white("Returned object contains: ") %+% crayon::green("cropped TIGER road network\n")) 60 | 61 | return(AOI) 62 | } 63 | 64 | -------------------------------------------------------------------------------- /R/findSSURGO.R: -------------------------------------------------------------------------------- 1 | #' @title Find SSURGO Maps and Mapunit Aggregated Attributes 2 | #' @description SSURGO is a geospatial database of soils produced by the Natural Resources Conservation Service (NRCS). \code{findSSURGO} 3 | #' returns a \code{SpatialPolygonsDataFrame} of SSURGO map units and the Mapunit aggregated attributes (muaggatt table) associated with each MUKEY. In total 43 attributes are returned, 4 | #' all of which can be found in the [SSURGO documentation](https://sdmdataaccess.sc.egov.usda.gov/documents/TableColumnDescriptionsReport.pdf). The MUAGGATT values cover a wide range of 5 | #' soil realted questions however if a user is interested in the full range of tabular data associated with the SSURGO map units we suggest checking out the FedData package. 6 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 7 | #' @return a list() of minimum length 2: AOI and ssurgo 8 | #' @examples 9 | #' \dontrun{ 10 | #' AOI = getAOI(clip = list("UCSB", 10, 10)) %>% findSSURGO() 11 | #' } 12 | #' @author Mike Johnson 13 | #' @export 14 | #' 15 | 16 | findSSURGO <- function(AOI) { 17 | 18 | `%+%` = crayon::`%+%` 19 | 20 | 21 | if (!(class(AOI) %in% c("list", "HydroData"))) {AOI = list(AOI = AOI)} 22 | 23 | bb.st = AOI::bbox_st(AOI$AOI) 24 | AOI.sf = sf::st_as_sf(AOI$AOI) 25 | AOI.sf = sf::st_transform(AOI.sf, "+proj=longlat +datum=WGS84") 26 | 27 | if (any((bb.st$xmax - bb.st$xmin) > 1, (bb.st$ymax - bb.st$ymin) > 1)) { 28 | grid = sf::as_Spatial(sf::st_make_grid(AOI.sf, cellsize = c(.95, .95))) 29 | } else { 30 | grid = AOI.sf 31 | } 32 | 33 | input.shp = list() 34 | 35 | cat(crayon::cyan("Locating regions\n")) 36 | 37 | for (i in seq_along(grid)) { 38 | bound <- grid[i] %>% AOI::bbox_st() 39 | url <- 40 | paste0( 41 | "https://sdmdataaccess.nrcs.usda.gov/Spatial/SDMNAD83Geographic.wfs?Service=WFS&Version=1.0.0&Request=GetFeature&Typename=SurveyAreaPoly&BBOX=", 42 | paste(bound$xmin, 43 | bound$ymin, 44 | bound$xmax, 45 | bound$ymax, 46 | sep = ",") 47 | ) 48 | 49 | check = download.url(url) 50 | sf = sf::read_sf(check$destfile) 51 | sf::st_crs(sf) = "+proj=longlat +datum=WGS84" 52 | sf$saverest <- as.Date(sf$saverest, format = "%b %d %Y") 53 | input.shp[[i]] = suppressWarnings(suppressMessages(sf::st_intersection(sf, AOI.sf))) 54 | } 55 | 56 | regions = do.call(rbind, input.shp) 57 | 58 | input.shp = list() 59 | 60 | for (i in 1:NROW(regions)) { 61 | url <- paste0("http://websoilsurvey.sc.egov.usda.gov/DSD/Download/Cache/SSA/wss_SSA_", 62 | as.character(regions$areasymbol[i]), 63 | "_[", 64 | as.Date(regions$saverest[i], format = "%m/%d/%Y"), 65 | "].zip" ) 66 | 67 | cat(crayon::white(paste0( "Downloading (", i, "/", NROW(regions), "): ")) %+% crayon::yellow(basename(url), "\n")) 68 | 69 | check = download.url(url) 70 | unzip(check$destfile, exdir = tempdir(), overwrite = TRUE) 71 | shp.path = list.files( tempdir(), 72 | full.names = T, 73 | recursive = T, 74 | pattern = paste0("soilmu_a_", tolower(as.character(regions$areasymbol[i])), ".shp") 75 | ) 76 | sf = sf::read_sf(shp.path) 77 | input.shp[[i]] = suppressWarnings(suppressMessages(sf::st_intersection(sf, AOI.sf))) 78 | } 79 | 80 | if(length(input.shp) > 1){ soils = do.call(rbind, input.shp) }else{ soils = input.shp[[1]] } 81 | 82 | tab = do.call(rbind, 83 | lapply(list.files(tempdir(), recursive = T, pattern = 'muaggatt', full.names = T), 84 | function(e){ utils::read.delim(e, header = F, sep = "|", stringsAsFactors = F) } 85 | )) 86 | 87 | names(tab) = names(utils::read.csv( paste0("https://casoilresource.lawr.ucdavis.edu/soil_web/component_data.php?mukey=95439&action=muaggatt&format=csv")))[-1] 88 | 89 | soils = merge(soils, tab, by.x = "MUKEY", by.y = "mukey") 90 | 91 | AOI[["ssurgo"]] = sf::as_Spatial(soils) 92 | 93 | cat( crayon::white("Returned object contains: ") %+% crayon::green("cropped SSURGO Soils Map\n") ) 94 | 95 | return(AOI) 96 | } 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /R/findSnotel.R: -------------------------------------------------------------------------------- 1 | #' @title Find USDA NRCS Snotel Stations 2 | #' 3 | #' @description \code{findSnotel} returns a \code{SpatialPointsDataFrame*} Objects cropped to an Area of Interest. 4 | #' Station data is extacted from \href{https://wcc.sc.egov.usda.gov/nwcc/yearcount?network=sntl&counttype=statelist&state=}{NRCS reports} and contains 11 attributes: 5 | #'\itemize{ 6 | #' \item 'NETWORK' : \code{integer} Description of Network (all = 'SNTL') 7 | #' \item 'STATE' : \code{character} The state the station is located in 8 | #' \item 'NAME': \code{POSITct} Unique station name 9 | #' \item 'ID' : \code{character} Unique identifier assigned by NRCS 10 | #' \item 'START.DATE' : \code{character} Date the station made first measurment ("Year-Month") 11 | #' \item 'LAT' : \code{numeric} Latitude of station, decimil degrees 12 | #' \item 'LON' : \code{numeric} Longitude of station, decimil degrees 13 | #' \item 'ELEV' : \code{character} Elevation of station 14 | #' \item 'COUNTY' : \code{integer} The county the station is located in 15 | #' \item 'HUC12.NAME': \code{character} The HUC12 name the station is located in 16 | #' \item 'HUC12.ID': \code{character} The HUC12 ID the station is located in 17 | #' } 18 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 19 | #' @param ids If TRUE, a vector of NHD COMIDs is added to retuned list (default = \code{FALSE}) 20 | #' @examples 21 | #' \dontrun{ 22 | #' CA.sno = getAOI(state = 'CA') %>% findSnotel() 23 | #'} 24 | #' @export 25 | #' @author 26 | #' Mike Johnson 27 | 28 | findSnotel = function(AOI = NULL, ids = FALSE){ 29 | 30 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 31 | 32 | sp = sf::st_as_sf(x = HydroData::snotel, coords = c('LONG', 'LAT'), crs = 4269 ) %>% sf::as_Spatial() 33 | 34 | sp = sp[AOI$AOI,] 35 | 36 | if (dim(sp)[1] == 0) { cat(crayon::red("0 stations found in AOI")) } else { 37 | 38 | AOI[["snotel"]] = sp 39 | 40 | report = paste(length(sp), "snotel stations") 41 | AOI = return.what(AOI, type = 'snotel', report, vals = if(ids){"ID"}) 42 | 43 | } 44 | 45 | return(AOI) 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /R/findWaterPoly.R: -------------------------------------------------------------------------------- 1 | #' @title Find Water Polygon 2 | #' @description A function to join all NHD water featrues into a single polygon. 3 | #' Flowlines are sized according to there Strahler stream order multiplied by 10 m. 4 | #' Useful for viualization and masking operations where a water surface is needed. 5 | #' @param AOI an AOI 6 | #' @return a single polygon of all NHD water features. 7 | #' @author Mike Johnson 8 | #' @examples 9 | #' \dontrun{ 10 | #' getAOI(state = 'CO', county = 'El Paso') %>% findWaterPoly() 11 | #' } 12 | #' @export 13 | #' 14 | 15 | findWaterPoly = function(AOI){ 16 | 17 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 18 | 19 | val = AOI$AOI %>% findNHD() %>% findWaterbodies() %>% to_sf() 20 | 21 | river = val$nhd 22 | wb = val$waterbodies 23 | #wb = wb[!is.na(wb$lakearea),] 24 | wb = wb[wb$areasqkm > .1,] 25 | 26 | river.p = sf::st_transform(river, "+init=epsg:3395") 27 | if(dim(wb)[1] > 1){ wb.p = sf::st_transform(wb, "+init=epsg:3395") } else {wb.p = NULL} 28 | 29 | rivers = list() 30 | 31 | st.order = unique(river.p$streamorde) 32 | st.order = sort(st.order[st.order !=0]) 33 | 34 | for( i in st.order ){ 35 | tmp = river.p[river.p$streamorde == i,] 36 | rivers[[i]] = sf::st_buffer(tmp, dist=10 * i) 37 | } 38 | 39 | 40 | rivers[sapply(rivers, is.null)] <- NULL 41 | 42 | t = do.call(rbind, rivers) 43 | t = sf::st_union(t) 44 | 45 | if(!is.null(wb.p)){ 46 | wb.j = sf::st_union(wb.p) 47 | t = sf::st_union(t, wb.j) 48 | } 49 | 50 | t = sf::st_transform(t, as.character(AOI::aoiProj)) %>% sf::as_Spatial() 51 | 52 | AOI[["waterPoly"]] = t 53 | 54 | return(AOI) 55 | } 56 | 57 | -------------------------------------------------------------------------------- /R/findWaterbodies.R: -------------------------------------------------------------------------------- 1 | #' @title Find National Hydrography Dataset Waterbodies 2 | #' @description \code{findWaterbodies} returns a \code{SpatialPolgonsDataframe} of all NHDwaterbodies within an AOI. 3 | #' Data comes from the USGS CIDA server and contain 23 attributes, perhaps most notably: 4 | #' \itemize{ 5 | #' \item 'objectid' : \code{integer} Integer value that uniquely identifies the waterbody of each feature in the NHD 6 | #' \item 'comid' : \code{character} The COMID draining into the feature 7 | #' \item 'fdate': \code{POSITct} Date of last feature modification 8 | #' \item 'gnis_id' : \code{character} Unique identifier assigned by GNIS 9 | #' \item 'gnis_name' : \code{character} Proper name, term, or expression by which a particular geographic entity is known 10 | #' \item 'meandepth' : \code{numeric} Mean depth of the waterbody 11 | #' \item 'lakevolume' : \code{numeric} Total waterbody volume 12 | #' \item 'maxdepth' : \code{character} Maximum depth of waterbody 13 | #' \item 'meanused' : \code{integer} The average amount of water used 14 | #' } 15 | #' @param AOI A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI} 16 | #' @param ids If TRUE, a vector of waterbody IDs is added to retuned list (default = \code{FALSE}) 17 | #' @return a list() of minimum length 2: AOI and waterboies 18 | #' @export 19 | #' @author Mike Johnson 20 | #' @examples 21 | #' \dontrun{ 22 | #' getAOI(clip = "Tuscaloosa") %>% findWaterbodies() 23 | #' } 24 | #' 25 | 26 | findWaterbodies = function(AOI = NULL, area = NULL) { 27 | 28 | if(!(class(AOI) %in% c("list","HydroData"))){AOI = list(AOI = AOI)} 29 | f= NULL 30 | if(!is.null(area)){ 31 | 32 | f = paste0('', 33 | '', 34 | 'areasqkm', 35 | '',area,'', 36 | '' 37 | ) 38 | } 39 | 40 | sl = query_cida(AOI$AOI, type = "waterbodies", spatial = TRUE, filter = f) 41 | 42 | if(!is.null(sl)){ 43 | 44 | AOI[["waterbodies"]] = sl 45 | 46 | report = paste(length(sl), "NHD waterbodies") 47 | 48 | ids = FALSE 49 | AOI = return.what(AOI, type = 'waterbodies', report, vals = if(ids){"objectid"}) 50 | } 51 | return(AOI) 52 | } 53 | -------------------------------------------------------------------------------- /R/findWatershed.R: -------------------------------------------------------------------------------- 1 | findWatershed = function(pt, includeParameters = TRUE){ 2 | 3 | id = findNearestCOMID(point = pt, n = 1) 4 | line = id$nhd@lines[[1]]@Lines[[1]]@coords 5 | line = tail(data.frame(line, stringsAsFactors = FALSE), 1) 6 | colnames(line) = c("lon", "lat") 7 | 8 | point = sf::st_as_sf(x = pt, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) %>% sf::as_Spatial() 9 | drainage = sf::st_as_sf(x = line, coords = c("lon", "lat"), crs = as.character(AOI::aoiProj)) %>% sf::as_Spatial() 10 | state = AOI::states[drainage,]$state_abbr 11 | 12 | tmp = httr::GET( 13 | paste0("https://streamstats.usgs.gov/streamstatsservices/watershed.geojson?rcode=", 14 | state, 15 | "&", 16 | 'xlocation=', line$lon, 17 | '&ylocation=', line$lat , 18 | "&crs=4326&includeparameters=", as.character(tolower(includeParameters)), 19 | "&includeflowtypes=false&includefeatures=true&simplify=true"), httr::progress(type = "down")) 20 | 21 | if(tmp$status_code == 200){ 22 | res <- httr::content(tmp, as = "text", encoding = "UTF-8") 23 | out <- jsonlite::fromJSON(res, simplifyVector = FALSE) 24 | 25 | x = matrix(unlist(out$featurecollection[[2]]$feature$feature[[1]]$geometry$coordinates[[1]]), ncol = 2, byrow = TRUE) 26 | tt = lapply(out$parameters, as.data.frame, stringsAsFactors = FALSE) 27 | tt = do.call(rbind, tt) 28 | 29 | pol = sf::st_sfc(sf::st_polygon(list(as.matrix(x)))) 30 | h = sf::st_sf(tt, pol, row.names = row.names(tt)) 31 | 32 | return(list(basin = h, drainage = drainage, point = point)) 33 | } else { 34 | stop("basin not delinimated!") 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /R/meta.data.R: -------------------------------------------------------------------------------- 1 | #' @title Return HydroData Object metadata 2 | #' @description Function for generating descriptive meta data for all HyrdroData objects 3 | #' @param AOI and AOI object with appended HydroData features 4 | #' @return a data.frame of meta.data describing a HydroData object 5 | #' @export 6 | #' @author Mike Johnson 7 | 8 | meta.data = function(AOI){ 9 | 10 | meta = data.frame(matrix(ncol = 9, nrow = 0), stringsAsFactors = F) 11 | 12 | names(meta) = c("type", 13 | "agency", 14 | "source", 15 | "dataset", 16 | "feature_name", 17 | "feature_no", 18 | "other", 19 | "class", 20 | "accessDate") 21 | 22 | 23 | if("nwis" %in% names(AOI)){ 24 | meta[nrow(meta) + 1, ] = c("Stream gages", "USGS", "CIDA", "NWIS", "nwis_gages", length(AOI$nwis), "NA", class(AOI$nwis)[1], as.character(Sys.Date())) 25 | } 26 | 27 | if("nhd" %in% names(AOI)){ 28 | meta[nrow(meta) + 1, ] = c("River Networks", "USGS", "CIDA", "NHD", "nhdflowlines", length(AOI$nhd), "NA", class(AOI$nhd)[1], as.character(Sys.Date())) 29 | } 30 | 31 | if("snotel" %in% names(AOI)){ 32 | meta[nrow(meta) + 1, ] = c("Snotel Stations", "USDA", "NRCS", "SNOTEL", "snotel_sta", length(AOI$snotel), "NA", class(AOI$snotel)[1], as.character(Sys.Date())) 33 | } 34 | 35 | if("ap" %in% names(AOI)){ 36 | meta[nrow(meta) + 1, ] = c("International Airports", "Open flights", "NCAR", "Airports", "ap", length(AOI$ap), "NA", class(AOI$ap)[1], as.character(Sys.Date())) 37 | } 38 | 39 | if("ghcn" %in% names(AOI)){ 40 | meta[nrow(meta) + 1, ] = c("Climate Stations", "NOAA", "GHCN", "GHCN", "ghcn", length(AOI$ghcn), "NA", class(AOI$ghcn)[1], as.character(Sys.Date())) 41 | } 42 | 43 | if("waterbodies" %in% names(AOI)){ 44 | meta[nrow(meta) + 1, ] = c("Waterbodies", "USGS", "CIDA", "NHD", "nhdwaterbodies", length(AOI$waterbodies), "NA", class(AOI$waterbodies)[1], as.character(Sys.Date())) 45 | } 46 | 47 | if("dams" %in% names(AOI)){ 48 | meta[nrow(meta) + 1, ] = c("Dams", "USACE", "NID", "dams", "niddams", length(AOI$dams), "NA", class(AOI$dams)[1], as.character(Sys.Date())) 49 | } 50 | 51 | if("gagesII" %in% names(AOI)){ 52 | meta[nrow(meta) + 1, ] = c("GagesII points", "USGS", "CIDA", "gagesII", "gagesII", length(AOI$gagesII), "NA", class(AOI$gagesII)[1], as.character(Sys.Date())) 53 | } 54 | 55 | if("gagesII_basins" %in% names(AOI)){ 56 | meta[nrow(meta) + 1, ] = c("GagesII basins", "USGS", "CIDA", "GgagesII_basins", "gagesII_basins", length(AOI$gagesII_basins), "NA", class(AOI$gagesII_basins)[1], as.character(Sys.Date())) 57 | } 58 | 59 | if(any(grepl("huc", names(AOI)))){ 60 | tmp = names(AOI)[grepl("huc", names(AOI))] 61 | 62 | for(i in seq_along(tmp)){ 63 | d = eval(parse(text = paste("AOI", tmp[i], sep = "$"))) 64 | meta[nrow(meta) + 1, ] = c(tmp[i], "USGS", "CIDA", "WBD", tmp[i], length(d), "NA", class(d)[1], as.character(Sys.Date())) 65 | } 66 | } 67 | 68 | if(any(grepl("nlcd", names(AOI)))){ 69 | tmp = names(AOI)[grepl("nlcd", names(AOI))] 70 | 71 | for(i in seq_along(tmp)){ 72 | d = eval(parse(text = paste("AOI", tmp[i], sep = "$"))) 73 | meta[nrow(meta) + 1, ] = c(tmp[i], "USGS", "MRLC", "NLCD", tmp[i], length(d), "NA", class(d)[1], as.character(Sys.Date())) 74 | } 75 | } 76 | 77 | AOI[["meta.data"]] = meta 78 | return(AOI) 79 | } 80 | 81 | -------------------------------------------------------------------------------- /R/pipe.R: -------------------------------------------------------------------------------- 1 | #' re-export magrittr pipe operator 2 | #' 3 | #' @importFrom magrittr %>% 4 | #' @name %>% 5 | #' @rdname pipe 6 | #' @export 7 | 8 | NULL 9 | -------------------------------------------------------------------------------- /R/query_cida_12718.R: -------------------------------------------------------------------------------- 1 | #' CIDA Server Query 2 | #' 3 | #' @param AOI and AOI object generated with the AOI package, or a bounding box 4 | #' @param type the WBD or nhdplus object to return 5 | #' @param spatial return `sp` (default) if \code{FALSE} return `sf` 6 | #' 7 | #' @return a \code{Spatial} object 8 | #' @export 9 | 10 | query_cida = function(AOI = NULL, type, spatial = TRUE, filter = NULL){ 11 | 12 | df = data.frame(server = c(rep("WBD", 2), 13 | rep("nhdplus", 3), 14 | rep("NWC", 3)), 15 | 16 | type = c('huc8','huc12', 17 | 'nhd', 'catchments', 'waterbodies', 18 | 'gagesII','gagesII_basins', 'epa_basins'), 19 | 20 | call = c("huc08", "huc12", 21 | "nhdflowline_network", "catchmentsp", "nhdwaterbody", 22 | "gagesII", "gagesii_basins", "epa_basins"), 23 | 24 | stringsAsFactors = F) 25 | 26 | if(!(type %in% df$type)) { stop(paste("Name not avalaile must be one of:", paste(df$type, collapse = ", "))) } 27 | 28 | call = df[which(df$type == type),] 29 | 30 | URL <- paste0("https://cida.usgs.gov/nwc/geoserver/", call$server, "/ows") 31 | 32 | startXML <- paste0('', 33 | '', 36 | '', 37 | '') 38 | 39 | if(!is.null(AOI)){ 40 | 41 | bb = AOI::bbox_st(AOI) 42 | 43 | clipFilter = paste0('', 44 | 'the_geom', 45 | '', 46 | '',bb$ymin," ",bb$xmin,'', 47 | '',bb$ymax," ",bb$xmax,'', 48 | '', 49 | '' 50 | ) 51 | } else { clipFilter = NULL} 52 | 53 | endXML = paste0('', 54 | '', 55 | '') 56 | 57 | 58 | filterXML = paste0(startXML, 59 | if(!is.null(filter)){ filter }, 60 | clipFilter, 61 | if(all(!is.null(filter), substring(filter, 1, 9) == '')) { ""}, 62 | endXML) 63 | 64 | dest = file.path(tempdir(), "spatial_query1.zip") 65 | file <- httr::POST(URL, body = filterXML, httr::write_disk(dest, overwrite=T)) 66 | 67 | #lines = sf::read_sf(rawToChar(file$content)) 68 | 69 | filePath <- tempdir() 70 | list.files(filePath) 71 | #suppressWarnings( 72 | unzip(dest, exdir = filePath) 73 | # #) 74 | 75 | myfile = list.files(filePath, pattern = call$call, full.names = TRUE) 76 | file.call = substr(basename(myfile[1]), 1, nchar(basename(myfile)) - 4) 77 | lines <- sf::read_sf(filePath, file.call) 78 | 79 | 80 | sl = tryCatch({sf::st_zm(lines)}, 81 | error = function(e){ 82 | return(NULL) 83 | }, warning = function(w){ 84 | return(NULL) 85 | } 86 | ) 87 | 88 | #file.remove(c(myfile, dest)) 89 | 90 | if(any(is.null(sl), nrow(sl) ==0)) { 91 | sl = NULL 92 | warning("No features found in this AOI.") 93 | } else { 94 | if(spatial){ sl = sf::as_Spatial(sl) 95 | } 96 | return(sl) 97 | } 98 | 99 | } 100 | 101 | 102 | -------------------------------------------------------------------------------- /R/to_sf.R: -------------------------------------------------------------------------------- 1 | #' @title Convert Spatial HydroData Objects to Simple Features 2 | #' @description A function to convert all Spatial* HydroData objects to simple feature geometries. 3 | #' Non-Spatial objects (eg raster and list components) will be skipped over. 4 | #' @param hydro.data.object a HydroData object with Spatial components 5 | #' @return a list with the same length as the input 6 | #' @examples 7 | #' \dontrun{ 8 | #' AOI = getAOI(clip = 'UCSB') %>% findNED %>% findNHD %>% findNWIS %>% to_sf 9 | #' } 10 | #' @export 11 | #' @author Mike Johnson 12 | 13 | to_sf = function(hydro.data.object = NULL){ 14 | 15 | `%+%` = crayon::`%+%` 16 | 17 | b = vector() 18 | for(i in seq_along(hydro.data.object)){ b = append(b, grepl("Spatial", class(hydro.data.object[[i]]))) } 19 | sf = c(hydro.data.object[!b], lapply(hydro.data.object[b], sf::st_as_sf)) 20 | 21 | cat(crayon::white('\nConverted to simple features: ') %+% crayon::cyan(paste(names(hydro.data.object[b]), collapse = ", ")), "\n") 22 | 23 | return(sf) 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /R/utilitiy_mosaic.R: -------------------------------------------------------------------------------- 1 | #' Mosaic 2 | #' 3 | #' Internal function for mosaicing a list of rasters 4 | #' 5 | #' @param input raster stack 6 | #' @author Mike Johnson 7 | #' @export 8 | 9 | 10 | mosaic.hd = function(input){ 11 | if(length(input) > 1){ 12 | message("Mosaicing raster...") 13 | utils::flush.console() 14 | input$fun <- max 15 | input$na.rm <- TRUE 16 | mos = do.call(raster::mosaic, input) 17 | gc() 18 | } else { 19 | mos = input[[1]] 20 | } 21 | return(mos) 22 | } 23 | -------------------------------------------------------------------------------- /R/utility_data.R: -------------------------------------------------------------------------------- 1 | #' Airports 2 | #' 3 | #' Dataset containing information global Airports subset to the Daymet Domain 4 | #' 5 | #' @docType data 6 | #' 7 | #' @format a \code{dataframe} instance, 1 row per station with columns: 8 | #' \itemize{ 9 | #' \item 'name': A \code{character} Name of airport. May or may not contain the City name. 10 | #' \item 'city': A \code{character} Main city served by airport. May be spelled differently from Name. 11 | #' \item 'country': A \code{character} Country or territory where airport is located. 12 | #' \item 'IATA': A \code{character} 3-letter IATA code 13 | #' \item 'ICAO': A \code{numeric} 4-letter ICAO code 14 | #' \item 'lat': A \code{numeric} Latitude of airport 15 | #' \item 'lon': A \code{numeric} Longitude of airport 16 | #' } 17 | #' 18 | #' @source \href{https://openflights.org/data.html}{OpenFlights} 19 | #' 20 | #' @examples 21 | #' \dontrun{ 22 | #' airports = HydroData::ap 23 | #' } 24 | #' 25 | 26 | "ap" 27 | 28 | #' USGS NWIS station information 29 | #' 30 | #' Dataset containing information about USGS stations in the United States 31 | #' 32 | #' @docType data 33 | #' 34 | #' @format a \code{dataframe} instance, 1 row per station with columns: 35 | #' \itemize{ 36 | #' \item 'OBJECTID': A \code{character} Object id in the dataset 37 | #' \item 'feature_id': A \code{character} NHD COMID of reach 38 | #' \item 'site_no': A \code{character} USGS site number 39 | #' \item 'site_name': A \code{character} USGS site name 40 | #' \item 'da_sqkm': A \code{numeric} Area that drains to the location in square kilometers 41 | #' \item 'lat_reachCent': A \code{numeric} Latitude of NHD reach center 42 | #' \item 'lon_reachCent': A \code{numeric} Longitude of NHD reach center 43 | #' } 44 | #' 45 | #' @source Compiled from USGS and NHD datasets 46 | #' 47 | #' @examples 48 | #' \dontrun{ 49 | #' usgs = HydroData::usgsStations 50 | #' } 51 | 52 | "usgsStations" 53 | 54 | #' Snotel Stations 55 | #' 56 | #' \code{snotel}NRCS SNOTEL station metadata 57 | #' 58 | #' @docType data 59 | #' 60 | #' @format a \code{dataframe} instance, 1 row per station with columns: 61 | #' \itemize{ 62 | #' \item 'NETWORK': A \code{integer} Network of interest 63 | #' \item 'STATE': A \code{integer} State abbriviation 64 | #' \item 'NAME': A \code{character} Site name 65 | #' \item 'START.DATE': A \code{integer} Day of first measurement 66 | #' \item 'LAT': A \code{integer} Station Latitude 67 | #' \item 'LONG': A \code{character} Station Longitude 68 | #' \item 'ELEV': A \code{character} Station Elevation 69 | #' \item 'COUNTY': A \code{character} County 70 | #' \item 'HUC12.NAME': A \code{character} HUC 12 Name 71 | #' \item 'HUC12.ID': A \code{character} HUC 12 code 72 | #' } 73 | #' 74 | #' @source \href{https://wcc.sc.egov.usda.gov/nwcc/yearcount?network=sntl&state=&counttype=statelist}{SNOTEL INFORMATION} 75 | #' 76 | #' @examples 77 | #' \dontrun{ 78 | #' tiles = HydroData::snotelStations.rda 79 | #' } 80 | 81 | "snotel" 82 | -------------------------------------------------------------------------------- /R/utility_download_url.R: -------------------------------------------------------------------------------- 1 | #' @title Download data from URL via httr::GET 2 | #' @description Download file from URL using httr:GET. 3 | #' File is written to the tmp directory with the basename of the URL call. 4 | #' @param url url 5 | #' @return a status and path to downloaded file 6 | #' @author Mike Johnson 7 | #' @export 8 | 9 | download.url = function(url){ 10 | 11 | destdir <- normalizePath(paste0(tempdir(), "/.")) 12 | destfile <- paste0(destdir, "/", basename(url)) 13 | 14 | if(!file.exists(destfile)){ 15 | x = httr::GET(url = url, httr::write_disk(destfile, overwrite = T), httr::progress(type = "down")) 16 | } else {x = list(status_code = 200)} 17 | 18 | if(x$status_code != 200){ file.remove(destfile) } 19 | 20 | return(list(code = x$status_code, destfile = destfile)) 21 | 22 | } 23 | -------------------------------------------------------------------------------- /R/utility_return_what.R: -------------------------------------------------------------------------------- 1 | #' @title Choose what to return for HydroData Calls 2 | #' @description A function defining what should be returned in a HydroData object 3 | #' @param AOI Spatial object 4 | #' @param type the index of the AOI object to report on 5 | #' @param report character sting to append values to 6 | #' @param vals the ids call 7 | #' @return a list of HydroData components 8 | #' @export 9 | #' @author Mike Johnson 10 | 11 | return.what = function(AOI, 12 | type, 13 | report, 14 | vals) { 15 | 16 | `%+%` = crayon::`%+%` 17 | 18 | if (!is.null(vals)) { 19 | AOI[[vals]] = eval(parse(text = paste("AOI",type, vals, sep = "$"))) 20 | report = append(report, paste("list of", vals, "IDs")) 21 | } 22 | 23 | if (length(report) > 1) { 24 | report[length(report)] = paste("and", tail(report, n = 1)) 25 | } 26 | 27 | cat(crayon::white("Returned object contains: ") %+% crayon::green(paste(report, collapse = ", "), "\n")) 28 | 29 | class(AOI) = "HydroData" 30 | 31 | return(AOI) 32 | 33 | } 34 | -------------------------------------------------------------------------------- /R/utility_save.file.R: -------------------------------------------------------------------------------- 1 | #' Save File 2 | #' 3 | #' @param AOI What data to write 4 | #' @param path State abb 5 | #' @param ext country call 6 | #' 7 | #' @export 8 | 9 | 10 | 11 | saveHD = function(AOI = NULL, path = NULL, ext = 'shp') { 12 | 13 | if(ext == "shp"){ 14 | ext = ".shp" 15 | driver = "ESRI Shapefile" 16 | } else { 17 | ext = ".gpkg" 18 | driver = "GPKG" 19 | } 20 | 21 | name = AOI::revgeocode(c(mean(AOI$AOI@bbox[2,]), mean(AOI$AOI@bbox[1,]))) 22 | if(!is.null(name$match_addr)){name = name$match_addr} else {name = name[1]} 23 | 24 | if(is.null(path)){raw.dir = normalizePath(paste0("./HydroData/"), mustWork = FALSE) 25 | } else { raw.dir = normalizePath(path, mustWork = FALSE) } 26 | 27 | AOI = AOI %>% meta.data() 28 | 29 | # initialize HydroData folder 30 | if (!file.exists(raw.dir)) { 31 | dir.create(raw.dir, showWarnings = FALSE, recursive = TRUE) 32 | } 33 | 34 | # initialize name folder 35 | if (!file.exists(paste0(raw.dir, "/", name))) { 36 | dir.create(paste0(raw.dir, "/", name), 37 | showWarnings = FALSE, 38 | recursive = TRUE) 39 | } 40 | 41 | meta = AOI$meta.data 42 | 43 | # initialize all folders 44 | 45 | for(i in unique(meta$agency)){ 46 | 47 | tmp.a = paste0(raw.dir, "/", name, "/", i) 48 | 49 | if (!file.exists(tmp.a)) { dir.create(tmp.a, showWarnings = FALSE,recursive = TRUE) } 50 | 51 | for(j in which(meta$agency == i)){ 52 | 53 | dataset = meta[j,]$dataset 54 | class = meta[j,]$class 55 | feature_name = meta[j,]$feature_name 56 | 57 | tmp.b = paste0(raw.dir, "/", name, "/", i, "/", dataset) 58 | 59 | if (!file.exists(tmp.b)) {dir.create(tmp.b, showWarnings = FALSE, recursive = TRUE) } 60 | writeHD(class , dir = tmp.b, feature_name, ext = ext) 61 | } 62 | } 63 | 64 | } 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /R/utility_unzipCrop.R: -------------------------------------------------------------------------------- 1 | unzip_crop = function(AOI = NULL, path, file.type = "img"){ 2 | 3 | file <- tempfile() 4 | 5 | if(!file.exists(path)){stop("Zip folder does not exist")} 6 | if (!dir.create(file)) { stop("failed to create a temporary directory") } 7 | 8 | fname = utils::unzip(zipfile = path, list = T)$Name 9 | f = fname[grepl(paste0(".",file.type,"$"), fname)] 10 | utils::unzip(path, files=f, exdir=file, overwrite=TRUE) 11 | 12 | dat <- list.files(file, full.names = TRUE, recursive = F) 13 | 14 | dat <- raster::raster(dat) 15 | 16 | AOI = sp::spTransform(AOI, dat@crs) 17 | 18 | if(!is.null(raster::intersect(raster::extent(dat),raster::extent(AOI)))){ 19 | dat <- raster::crop(dat, AOI, snap = "out") 20 | #message("Raster Cropped.") 21 | } else { 22 | message("Raster not needed") 23 | } 24 | 25 | unlink(file, recursive = TRUE) 26 | 27 | return(dat) 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /R/utility_writeHD.R: -------------------------------------------------------------------------------- 1 | #' @title Write Data to disk 2 | #' @description interal function used to write data to disk according to it meta.data found via HydroData::meta.data() 3 | #' @param AOI a HydroData object with components to write to disk 4 | #' @param class objects class 5 | #' @param dir directory 6 | #' @param feature_name object id 7 | #' @param ext shp or gpkg 8 | #' 9 | #' @return NULL 10 | #' @export 11 | #' 12 | 13 | 14 | writeHD = function(AOI, class, dir, feature_name, ext = "shp") { 15 | 16 | data = eval(parse(text = paste0("AOI$", feature_name))) 17 | 18 | if (grepl("Spatial", class)) { 19 | 20 | if(ext == "shp"){ 21 | ext = ".shp" 22 | driver = "ESRI Shapefile" 23 | } else { 24 | ext = ".gpkg" 25 | driver = "GPKG" 26 | } 27 | 28 | file = paste0(dir, "/", feature_name, ext) 29 | 30 | if (!file.exists(file)) { 31 | 32 | data = sf::st_as_sf(data) 33 | names(data) = abbreviate(names(data), 10) 34 | st_write(data, dsn = file, layer = feature_name, 35 | driver = driver, delete_dsn = TRUE, quiet = TRUE) 36 | 37 | } 38 | } 39 | 40 | if (grepl("raster", class)) { 41 | write 42 | } 43 | if (grepl("data.frame", class)) { 44 | 45 | write.csv(data, file) 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | title: HydroData 2 | template: 3 | params: 4 | bootswatch: flatly 5 | reference: 6 | - title: Find Features 7 | desc: ~ 8 | Functions for finding Spatial Data 9 | contents: 10 | - '`findCDL`' 11 | - '`findGAGESII`' 12 | - '`findNED`' 13 | - '`findNHD`' 14 | - '`findNID`' 15 | - '`findNLCD`' 16 | - '`findNLDI`' 17 | - '`findRoads`' 18 | - '`findSSURGO`' 19 | - '`findWaterbodies`' 20 | - '`findWaterPoly`' 21 | - '`findWBD`' 22 | - title: Find Stations 23 | desc: ~ 24 | Functions for station locations 25 | contents: 26 | - '`findAirports`' 27 | - '`findACIS`' 28 | - '`findASOS`' 29 | - '`findGHCN`' 30 | - '`findUSCRN`' 31 | - '`findNOAAnorms`' 32 | - '`findNWIS`' 33 | - '`findSnotel`' 34 | - title: Find Nearest Features 35 | desc: ~ 36 | Functions for finding the 'n' nearest features to a location 37 | contents: 38 | - '`findNearestAirports`' 39 | - '`findNearestCOMID`' 40 | - '`findNearestGHCN`' 41 | - '`findNearestHUC12`' 42 | - '`findNearestNWIS`' 43 | - '`findNearestWaterbodies`' 44 | - title: Tools 45 | desc: ~ 46 | Tools for exploring, describing and defining AOIs 47 | contents: 48 | - '`explore`' 49 | - '`meta.data`' 50 | - '`saveHD`' 51 | - '`to_sf`' 52 | navbar: 53 | left: 54 | - icon: fa-home 55 | href: index.html 56 | - text: "Documentation" 57 | icon: fas fa-book 58 | menu: 59 | - text: Available Data Source 60 | href: articles/sources.html 61 | - icon: fa-file-code-o 62 | text: "functions" 63 | href: reference/index.html 64 | -------------------------------------------------------------------------------- /data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/data/.DS_Store -------------------------------------------------------------------------------- /data/.Rapp.history: -------------------------------------------------------------------------------- 1 | load("/Users/mikejohnson/Library/Mobile Documents/com~apple~CloudDocs/RPackages/HydroData/data/usgsStations.Rdata") 2 | load("/Users/mikejohnson/Documents/GitHub/HydroData/data/comids.rda") 3 | df 4 | -------------------------------------------------------------------------------- /data/airports.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/data/airports.rda -------------------------------------------------------------------------------- /data/snotelStations.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/data/snotelStations.rda -------------------------------------------------------------------------------- /data/usgsStations.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/data/usgsStations.rda -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | License • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 |
53 |
54 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 |
MIT License
122 | 
123 | Copyright (c) 2018 Mike Johnson
124 | 
125 | Permission is hereby granted, free of charge, to any person obtaining a copy
126 | of this software and associated documentation files (the "Software"), to deal
127 | in the Software without restriction, including without limitation the rights
128 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
129 | copies of the Software, and to permit persons to whom the Software is
130 | furnished to do so, subject to the following conditions:
131 | 
132 | The above copyright notice and this permission notice shall be included in all
133 | copies or substantial portions of the Software.
134 | 
135 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
136 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
137 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
138 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
139 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
140 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
141 | SOFTWARE.
142 | 
143 | 144 |
145 | 146 |
147 | 148 | 149 |
150 | 153 | 154 |
155 |

Site built with pkgdown.

156 |
157 | 158 |
159 |
160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /docs/articles/img/sources.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/docs/articles/img/sources.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 |
53 |
54 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 |
122 |

All vignettes

123 |

124 | 125 | 128 |
129 |
130 |
131 | 132 |
133 | 136 | 137 |
138 |

Site built with pkgdown.

139 |
140 | 141 |
142 |
143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 50 | 51 | 52 |
53 |
54 | 111 | 112 | 113 |
114 | 115 |
116 |
117 | 120 | 121 |
    122 |
  • 123 |

    Mike Johnson. Author, maintainer. 124 |

    125 |
  • 126 |
127 | 128 |
129 | 130 |
131 | 132 | 133 |
134 | 137 | 138 |
139 |

Site built with pkgdown.

140 |
141 | 142 |
143 |
144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/docs/favicon.ico -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/docs/logo.png -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body > .container { 21 | display: flex; 22 | height: 100%; 23 | flex-direction: column; 24 | 25 | padding-top: 60px; 26 | } 27 | 28 | body > .container .row { 29 | flex: 1 0 auto; 30 | } 31 | 32 | footer { 33 | margin-top: 45px; 34 | padding: 35px 0 36px; 35 | border-top: 1px solid #e5e5e5; 36 | color: #666; 37 | display: flex; 38 | flex-shrink: 0; 39 | } 40 | footer p { 41 | margin-bottom: 0; 42 | } 43 | footer div { 44 | flex: 1; 45 | } 46 | footer .pkgdown { 47 | text-align: right; 48 | } 49 | footer p { 50 | margin-bottom: 0; 51 | } 52 | 53 | img.icon { 54 | float: right; 55 | } 56 | 57 | img { 58 | max-width: 100%; 59 | } 60 | 61 | /* Typographic tweaking ---------------------------------*/ 62 | 63 | .contents h1.page-header { 64 | margin-top: calc(-60px + 1em); 65 | } 66 | 67 | /* Section anchors ---------------------------------*/ 68 | 69 | a.anchor { 70 | margin-left: -30px; 71 | display:inline-block; 72 | width: 30px; 73 | height: 30px; 74 | visibility: hidden; 75 | 76 | background-image: url(./link.svg); 77 | background-repeat: no-repeat; 78 | background-size: 20px 20px; 79 | background-position: center center; 80 | } 81 | 82 | .hasAnchor:hover a.anchor { 83 | visibility: visible; 84 | } 85 | 86 | @media (max-width: 767px) { 87 | .hasAnchor:hover a.anchor { 88 | visibility: hidden; 89 | } 90 | } 91 | 92 | 93 | /* Fixes for fixed navbar --------------------------*/ 94 | 95 | .contents h1, .contents h2, .contents h3, .contents h4 { 96 | padding-top: 60px; 97 | margin-top: -40px; 98 | } 99 | 100 | /* Static header placement on mobile devices */ 101 | @media (max-width: 767px) { 102 | .navbar-fixed-top { 103 | position: absolute; 104 | } 105 | .navbar { 106 | padding: 0; 107 | } 108 | } 109 | 110 | 111 | /* Sidebar --------------------------*/ 112 | 113 | #sidebar { 114 | margin-top: 30px; 115 | } 116 | #sidebar h2 { 117 | font-size: 1.5em; 118 | margin-top: 1em; 119 | } 120 | 121 | #sidebar h2:first-child { 122 | margin-top: 0; 123 | } 124 | 125 | #sidebar .list-unstyled li { 126 | margin-bottom: 0.5em; 127 | } 128 | 129 | .orcid { 130 | height: 16px; 131 | vertical-align: middle; 132 | } 133 | 134 | /* Reference index & topics ----------------------------------------------- */ 135 | 136 | .ref-index th {font-weight: normal;} 137 | 138 | .ref-index td {vertical-align: top;} 139 | .ref-index .alias {width: 40%;} 140 | .ref-index .title {width: 60%;} 141 | 142 | .ref-index .alias {width: 40%;} 143 | .ref-index .title {width: 60%;} 144 | 145 | .ref-arguments th {text-align: right; padding-right: 10px;} 146 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 147 | .ref-arguments .name {width: 20%;} 148 | .ref-arguments .desc {width: 80%;} 149 | 150 | /* Nice scrolling for wide elements --------------------------------------- */ 151 | 152 | table { 153 | display: block; 154 | overflow: auto; 155 | } 156 | 157 | /* Syntax highlighting ---------------------------------------------------- */ 158 | 159 | pre { 160 | word-wrap: normal; 161 | word-break: normal; 162 | border: 1px solid #eee; 163 | } 164 | 165 | pre, code { 166 | background-color: #f8f8f8; 167 | color: #333; 168 | } 169 | 170 | pre code { 171 | overflow: auto; 172 | word-wrap: normal; 173 | white-space: pre; 174 | } 175 | 176 | pre .img { 177 | margin: 5px 0; 178 | } 179 | 180 | pre .img img { 181 | background-color: #fff; 182 | display: block; 183 | height: auto; 184 | } 185 | 186 | code a, pre a { 187 | color: #375f84; 188 | } 189 | 190 | a.sourceLine:hover { 191 | text-decoration: none; 192 | } 193 | 194 | .fl {color: #1514b5;} 195 | .fu {color: #000000;} /* function */ 196 | .ch,.st {color: #036a07;} /* string */ 197 | .kw {color: #264D66;} /* keyword */ 198 | .co {color: #888888;} /* comment */ 199 | 200 | .message { color: black; font-weight: bolder;} 201 | .error { color: orange; font-weight: bolder;} 202 | .warning { color: #6A0366; font-weight: bolder;} 203 | 204 | /* Clipboard --------------------------*/ 205 | 206 | .hasCopyButton { 207 | position: relative; 208 | } 209 | 210 | .btn-copy-ex { 211 | position: absolute; 212 | right: 0; 213 | top: 0; 214 | visibility: hidden; 215 | } 216 | 217 | .hasCopyButton:hover button.btn-copy-ex { 218 | visibility: visible; 219 | } 220 | 221 | /* mark.js ----------------------------*/ 222 | 223 | mark { 224 | background-color: rgba(255, 255, 51, 0.5); 225 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 226 | padding: 1px; 227 | } 228 | 229 | /* vertical spacing after htmlwidgets */ 230 | .html-widget { 231 | margin-bottom: 10px; 232 | } 233 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $("#sidebar") 6 | .stick_in_parent({offset_top: 40}) 7 | .on('sticky_kit:bottom', function(e) { 8 | $(this).parent().css('position', 'static'); 9 | }) 10 | .on('sticky_kit:unbottom', function(e) { 11 | $(this).parent().css('position', 'relative'); 12 | }); 13 | 14 | $('body').scrollspy({ 15 | target: '#sidebar', 16 | offset: 60 17 | }); 18 | 19 | $('[data-toggle="tooltip"]').tooltip(); 20 | 21 | var cur_path = paths(location.pathname); 22 | var links = $("#navbar ul li a"); 23 | var max_length = -1; 24 | var pos = -1; 25 | for (var i = 0; i < links.length; i++) { 26 | if (links[i].getAttribute("href") === "#") 27 | continue; 28 | var path = paths(links[i].pathname); 29 | 30 | var length = prefix_length(cur_path, path); 31 | if (length > max_length) { 32 | max_length = length; 33 | pos = i; 34 | } 35 | } 36 | 37 | // Add class to parent
  • , and enclosing
  • if in dropdown 38 | if (pos >= 0) { 39 | var menu_anchor = $(links[pos]); 40 | menu_anchor.parent().addClass("active"); 41 | menu_anchor.closest("li.dropdown").addClass("active"); 42 | } 43 | }); 44 | 45 | function paths(pathname) { 46 | var pieces = pathname.split("/"); 47 | pieces.shift(); // always starts with / 48 | 49 | var end = pieces[pieces.length - 1]; 50 | if (end === "index.html" || end === "") 51 | pieces.pop(); 52 | return(pieces); 53 | } 54 | 55 | function prefix_length(needle, haystack) { 56 | if (needle.length > haystack.length) 57 | return(0); 58 | 59 | // Special case for length-0 haystack, since for loop won't run 60 | if (haystack.length === 0) { 61 | return(needle.length === 0 ? 1 : 0); 62 | } 63 | 64 | for (var i = 0; i < haystack.length; i++) { 65 | if (needle[i] != haystack[i]) 66 | return(i); 67 | } 68 | 69 | return(haystack.length); 70 | } 71 | 72 | /* Clipboard --------------------------*/ 73 | 74 | function changeTooltipMessage(element, msg) { 75 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 76 | element.setAttribute('data-original-title', msg); 77 | $(element).tooltip('show'); 78 | element.setAttribute('data-original-title', tooltipOriginalTitle); 79 | } 80 | 81 | if(Clipboard.isSupported()) { 82 | $(document).ready(function() { 83 | var copyButton = ""; 84 | 85 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 86 | 87 | // Insert copy buttons: 88 | $(copyButton).prependTo(".hasCopyButton"); 89 | 90 | // Initialize tooltips: 91 | $('.btn-copy-ex').tooltip({container: 'body'}); 92 | 93 | // Initialize clipboard: 94 | var clipboardBtnCopies = new Clipboard('[data-clipboard-copy]', { 95 | text: function(trigger) { 96 | return trigger.parentNode.textContent; 97 | } 98 | }); 99 | 100 | clipboardBtnCopies.on('success', function(e) { 101 | changeTooltipMessage(e.trigger, 'Copied!'); 102 | e.clearSelection(); 103 | }); 104 | 105 | clipboardBtnCopies.on('error', function() { 106 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 107 | }); 108 | }); 109 | } 110 | })(window.jQuery || window.$) 111 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 1.19.2.1 2 | pkgdown: 1.1.0 3 | pkgdown_sha: ~ 4 | articles: 5 | sources: sources.html 6 | 7 | -------------------------------------------------------------------------------- /docs/reference/HydroData.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | HydroData — HydroData • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    HydroData package

    128 | 129 |
    130 | 131 | 132 |

    Details

    133 | 134 |

    Access earth systems geospatial and observation data programatically

    135 |

    See the README on

    136 | 137 | 138 |
    139 | 147 |
    148 | 149 |
    150 | 153 | 154 |
    155 |

    Site built with pkgdown.

    156 |
    157 | 158 |
    159 |
    160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /docs/reference/col_elev.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Color Palletes Usefull for NLCD, CDL and NED plotting — col_elev • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    Color pallets for visualizing land use and elevation raster data

    128 | 129 |
    130 | 131 |
    col_elev
    132 | 133 |

    Format

    134 | 135 |

    An object of class character of length 23.

    136 | 137 | 138 |
    139 | 151 |
    152 | 153 |
    154 | 157 | 158 |
    159 |

    Site built with pkgdown.

    160 |
    161 | 162 |
    163 |
    164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /docs/reference/download.url.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Download data from URL via httr::GET — download.url • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 |
    56 |
    57 | 114 | 115 | 116 |
    117 | 118 |
    119 |
    120 | 125 | 126 |
    127 | 128 |

    Download file from URL using httr:GET. 129 | File is written to the tmp directory with the basename of the URL call.

    130 | 131 |
    132 | 133 |
    download.url(url)
    134 | 135 |

    Arguments

    136 | 137 | 138 | 139 | 140 | 141 | 142 |
    url

    url

    143 | 144 |

    Value

    145 | 146 |

    a status and path to downloaded file

    147 | 148 | 149 |
    150 | 163 |
    164 | 165 |
    166 | 169 | 170 |
    171 |

    Site built with pkgdown.

    172 |
    173 | 174 |
    175 |
    176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /docs/reference/figures/explore_ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/docs/reference/figures/explore_ex.png -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/reference/figures/plot_ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/docs/reference/figures/plot_ex.png -------------------------------------------------------------------------------- /docs/reference/figures/rayshade_ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/docs/reference/figures/rayshade_ex.png -------------------------------------------------------------------------------- /docs/reference/figures/sources.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/docs/reference/figures/sources.png -------------------------------------------------------------------------------- /docs/reference/getBoundingBox.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get Bounding box — getBoundingBox • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    A function to define a minimum bounding box for a set of points

    128 | 129 |
    130 | 131 |
    getBoundingBox(x)
    132 | 133 |

    Arguments

    134 | 135 | 136 | 137 | 138 | 139 | 140 |
    x

    a data.frame with a lat and long column

    141 | 142 |

    Value

    143 | 144 |

    a SpatialPolygon bounding box of input points x

    145 | 146 |

    See also

    147 | 148 |

    Other HydroData 'utility' function: download_shp

    149 | 150 | 151 |
    152 | 163 |
    164 | 165 |
    166 | 169 | 170 |
    171 |

    Site built with pkgdown.

    172 |
    173 | 174 |
    175 |
    176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /docs/reference/meta.data.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Return HydroData Object metadata — meta.data • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    Function for generating descriptive meta data for all HyrdroData objects

    128 | 129 |
    130 | 131 |
    meta.data(AOI)
    132 | 133 |

    Arguments

    134 | 135 | 136 | 137 | 138 | 139 | 140 |
    AOI

    and AOI object with appended HydroData features

    141 | 142 |

    Value

    143 | 144 |

    a data.frame of meta.data describing a HydroData object

    145 | 146 | 147 |
    148 | 161 |
    162 | 163 |
    164 | 167 | 168 |
    169 |

    Site built with pkgdown.

    170 |
    171 | 172 |
    173 |
    174 | 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /docs/reference/mosaic.hd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Mosaic — mosaic.hd • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    Interal function for mosaicing a list of rasters

    128 | 129 |
    130 | 131 |
    mosaic.hd(input)
    132 | 133 |

    Arguments

    134 | 135 | 136 | 137 | 138 | 139 | 140 |
    input

    raster stack

    141 | 142 | 143 |
    144 | 155 |
    156 | 157 |
    158 | 161 | 162 |
    163 |

    Site built with pkgdown.

    164 |
    165 | 166 |
    167 |
    168 | 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /docs/reference/pipe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | re-export magrittr pipe operator — %>% • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    re-export magrittr pipe operator

    128 | 129 |
    130 | 131 | 132 | 133 |
    134 | 140 |
    141 | 142 |
    143 | 146 | 147 |
    148 |

    Site built with pkgdown.

    149 |
    150 | 151 |
    152 |
    153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /docs/reference/query_cida.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | CIDA Server Query — query_cida • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    CIDA Server Query

    128 | 129 |
    130 | 131 |
    query_cida(AOI, type, spatial = TRUE)
    132 | 133 |

    Arguments

    134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 |
    AOI

    and AOI object generated with the AOI package, or a bounding box

    type

    the WBD or nhdplus object to return

    spatial

    return `sp` (default) if FALSE return `sf`

    149 | 150 |

    Value

    151 | 152 |

    a Spatial object

    153 | 154 | 155 |
    156 | 165 |
    166 | 167 |
    168 | 171 | 172 |
    173 |

    Site built with pkgdown.

    174 |
    175 | 176 |
    177 |
    178 | 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /docs/reference/saveHD.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Save File — saveHD • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    Save File

    128 | 129 |
    130 | 131 |
    saveHD(AOI = NULL, path = NULL, ext = "shp")
    132 | 133 |

    Arguments

    134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 |
    AOI

    What data to write

    path

    State abb

    ext

    country call

    149 | 150 | 151 |
    152 | 159 |
    160 | 161 |
    162 | 165 | 166 |
    167 |

    Site built with pkgdown.

    168 |
    169 | 170 |
    171 |
    172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /docs/reference/writeHD.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Write Data to disk — writeHD • HydroData 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 | 54 |
    55 |
    56 | 113 | 114 | 115 |
    116 | 117 |
    118 |
    119 | 124 | 125 |
    126 | 127 |

    interal function used to write data to disk according to it meta.data found via HydroData::meta.data()

    128 | 129 |
    130 | 131 |
    writeHD(AOI, class, dir, feature_name, ext = "shp")
    132 | 133 |

    Arguments

    134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 |
    AOI

    a HydroData object with components to write to disk

    class

    objects class

    dir

    directory

    feature_name

    object id

    ext

    shp or gpkg

    157 | 158 | 159 |
    160 | 167 |
    168 | 169 | 179 |
    180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /man/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/man/.DS_Store -------------------------------------------------------------------------------- /man/.Rapp.history: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/man/.Rapp.history -------------------------------------------------------------------------------- /man/HydroData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HydroData.R 3 | \docType{package} 4 | \name{HydroData} 5 | \alias{HydroData} 6 | \alias{HydroData-package} 7 | \title{HydroData} 8 | \description{ 9 | \code{HydroData} package 10 | } 11 | \details{ 12 | Access earth systems geospatial and observation data programatically 13 | 14 | See the README on 15 | } 16 | -------------------------------------------------------------------------------- /man/ap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_data.R 3 | \docType{data} 4 | \name{ap} 5 | \alias{ap} 6 | \title{Airports} 7 | \format{a \code{dataframe} instance, 1 row per station with columns: 8 | \itemize{ 9 | \item 'name': A \code{character} Name of airport. May or may not contain the City name. 10 | \item 'city': A \code{character} Main city served by airport. May be spelled differently from Name. 11 | \item 'country': A \code{character} Country or territory where airport is located. 12 | \item 'IATA': A \code{character} 3-letter IATA code 13 | \item 'ICAO': A \code{numeric} 4-letter ICAO code 14 | \item 'lat': A \code{numeric} Latitude of airport 15 | \item 'lon': A \code{numeric} Longitude of airport 16 | }} 17 | \source{ 18 | \href{https://openflights.org/data.html}{OpenFlights} 19 | } 20 | \usage{ 21 | ap 22 | } 23 | \description{ 24 | Dataset containing information global Airports subset to the Daymet Domain 25 | } 26 | \examples{ 27 | \dontrun{ 28 | airports = HydroData::ap 29 | } 30 | 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /man/col_elev.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color.palletes.R 3 | \docType{data} 4 | \name{col_elev} 5 | \alias{col_elev} 6 | \title{Color Palletes Usefull for NLCD, CDL and NED plotting} 7 | \format{An object of class \code{character} of length 23.} 8 | \usage{ 9 | col_elev 10 | } 11 | \description{ 12 | Color pallets for visualizing land use and elevation raster data 13 | } 14 | \author{ 15 | Mike Johnson 16 | } 17 | \keyword{datasets} 18 | -------------------------------------------------------------------------------- /man/download.url.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_download_url.R 3 | \name{download.url} 4 | \alias{download.url} 5 | \title{Download data from URL via httr::GET} 6 | \usage{ 7 | download.url(url) 8 | } 9 | \arguments{ 10 | \item{url}{url} 11 | } 12 | \value{ 13 | a status and path to downloaded file 14 | } 15 | \description{ 16 | Download file from URL using httr:GET. 17 | File is written to the tmp directory with the basename of the URL call. 18 | } 19 | \author{ 20 | Mike Johnson 21 | } 22 | -------------------------------------------------------------------------------- /man/explore.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/explore.R 3 | \name{explore} 4 | \alias{explore} 5 | \title{Explore Spatial HydroData Objects} 6 | \usage{ 7 | explore(input = NULL, save = FALSE) 8 | } 9 | \arguments{ 10 | \item{input}{a single, or list, of HydroData objects} 11 | 12 | \item{save}{(logical) should the leaflet HTML be saved to disk?} 13 | } 14 | \value{ 15 | leaflet map object 16 | } 17 | \description{ 18 | \code{explore} can be used to explore spatial HydroData objects obtained from 19 | Namely: 20 | findGHCN 21 | findNHD 22 | findReservoir 23 | findtiger 24 | findSnotel 25 | findUSGS 26 | findWaterbodies 27 | findWS 28 | findap 29 | getCLD 30 | getKoppen 31 | getNED 32 | getNLCD 33 | getWaterUse 34 | } 35 | \examples{ 36 | \dontrun{ 37 | # Find USGS station near UCSB 38 | 39 | ucsb.nwis = findUSGS(clip_unit = list("UCSB", 10, 10)) 40 | explore(ucsb.nwis) 41 | } 42 | 43 | } 44 | \author{ 45 | Mike Johnson 46 | } 47 | \concept{HydroData 'viz' functions} 48 | -------------------------------------------------------------------------------- /man/figures/explore_ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/man/figures/explore_ex.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/man/figures/logo.png -------------------------------------------------------------------------------- /man/figures/plot_ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/man/figures/plot_ex.png -------------------------------------------------------------------------------- /man/figures/rayshade_ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/man/figures/rayshade_ex.png -------------------------------------------------------------------------------- /man/figures/sources.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/man/figures/sources.png -------------------------------------------------------------------------------- /man/findAirports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findAirports.R 3 | \name{findAirports} 4 | \alias{findAirports} 5 | \title{Find Airport Data} 6 | \usage{ 7 | findAirports(AOI = NULL, ids = FALSE) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | 12 | \item{ids}{If TRUE, a vector of airport ICAO codes is added to retuned list (default = \code{FALSE})} 13 | } 14 | \value{ 15 | a list of minimum length 2: AOI and ap 16 | } 17 | \description{ 18 | \code{findAirports} returns a \code{SpatialPointsDataframe} of all airports within an AOI. 19 | Data comes from the \href{https://openflights.org/data.html}{Openflights} database and includes the following attributes: 20 | \itemize{ 21 | \item 'name' : \code{character} Name of airport. May or may not contain the City name. 22 | \item 'city' : \code{character} Main city served by airport. May be spelled differently from Name. 23 | \item 'country': \code{character} Country or territory where airport is located. 24 | \item 'IATA' : \code{character} 3-letter IATA code 25 | \item 'ICAO' : \code{numeric} 4-letter ICAO code 26 | \item 'lat' : \code{numeric} Latitude of airport 27 | \item 'lon' : \code{numeric} Longitude of airport 28 | } 29 | } 30 | \examples{ 31 | \dontrun{ 32 | ap = getAOI(state = "CO", county = "El Paso") \%>\% findAirports() 33 | } 34 | } 35 | \author{ 36 | Mike Johnson 37 | } 38 | -------------------------------------------------------------------------------- /man/findCDL.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findCDL.R 3 | \name{findCDL} 4 | \alias{findCDL} 5 | \title{Find Cropland Land Cover Data from the Cropand Data Layer} 6 | \usage{ 7 | findCDL(AOI, year = 2017) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | 12 | \item{year}{the year(s) to download. Options include 2008-2017 for most locations. Default = 2017} 13 | } 14 | \value{ 15 | a list() of minimum length 2: AOI and cld 16 | } 17 | \description{ 18 | \code{findCLD} returns \code{Raster} land cover data from the USDA Cropland Data Layer Dataset (\href{https://nassgeodata.gmu.edu/CropScape/}{Cropscape}) for an AOI. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | dt = getAOI(clip = list("Devil Tower")) \%>\% findCDL() 23 | dt = getAOI(clip = list("Devil Tower")) \%>\% findCDL(2011:2016) 24 | } 25 | } 26 | \author{ 27 | Mike Johnson 28 | } 29 | -------------------------------------------------------------------------------- /man/findGAGESII.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findGAGESII.R 3 | \name{findGAGESII} 4 | \alias{findGAGESII} 5 | \title{Find GAGESII points and basins} 6 | \usage{ 7 | findGAGESII(AOI = NULL, basins = FALSE, ids = FALSE) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | 12 | \item{basins}{If TRUE, returns a list of GAGESII basin in addition} 13 | 14 | \item{ids}{If TRUE, a vector of gage IDs is added to retuned list (default = \code{FALSE})} 15 | } 16 | \value{ 17 | a list() of minimum length 2: AOI and gagesII 18 | } 19 | \description{ 20 | The 'Geospatial Attributes of Gages for Evaluating Streamflow, version II' 21 | (\href{https://water.usgs.gov/GIS/metadata/usgswrd/XML/gagesII_Sept2011.xml#Entity_and_Attribute_Information}{GAGESII}) 22 | provides geospatial data and classifications for 9,322 stream gages maintained by the U.S. Geological Survey (USGS). \code{findGAGESII} 23 | returns a \code{SpatialPointsDataFrame*} of GAGESII outlets within an AOI. Data comes from the USGS CIDA server and contains the following attributes: 24 | \itemize{ 25 | \item 'id' : \code{character} Internal feature number 26 | \item 'STAID' : \code{character} USGS NWIS Station ID 27 | \item 'STANAME': \code{character} USGS NWIS Station Name 28 | \item 'CLASS' : \code{character} Classification (Ref or Non-ref) 29 | \item 'AGGECOREGION' : \code{numeric} Aggregated ecoregion 30 | \item 'DRAIN_SQKM' : \code{numeric} Drainage area, sq km 31 | \item 'HUC02' : \code{numeric} Hydrologic Unit Code, 2-digit 32 | \item 'LAT_GAGE' : \code{character} %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% %>% 33 | \item 'LNG_GAGE' : \code{character} Longitude, decimal degrees 34 | \item 'STATE': \code{character} State at gage location 35 | \item 'HCDN_2009' : \code{character} If gage is part of HCDN-2009 36 | \item 'ACTIVE09' : \code{numeric} If gage active in water year 2009 37 | \item 'FLYRS1990' : \code{numeric} Number of complete years of flow data between 1900 and 2009 38 | \item 'FLYRS1950' : \code{numeric} Number of complete years of flow data between 1950 and 2009 39 | \item 'FLYRS1990' : \code{numeric} Number of complete years of flow data between 1990 and 2009 40 | } 41 | If \code{basins = TRUE} a \code{SpatialPolygonsDataFrame} of the gage drainage basin will also be appended 42 | to the returned list and contain the following attributes: 43 | \itemize{ 44 | \item 'id' : \code{character} Internal feature number and data identifier 45 | \item 'ogr_fid' : \code{character} Internal feature number 46 | \item 'area': \code{character} Basin Area 47 | \item 'perimeter' : \code{character} Basein Parameters 48 | \item 'gage_id' : \code{numeric} USGS NWIS Station ID 49 | } 50 | } 51 | \examples{ 52 | \dontrun{ 53 | #Get GAGESII outlets for AOI 54 | bas = getAOI(clip = list("UCSB", 10, 10)) \%>\% findGAGESII() 55 | 56 | #Get GAGESII outlets and basins for AOI 57 | bas = getAOI(clip = list("UCSB", 10, 10)) \%>\% findGAGESII(basins = TRUE) 58 | } 59 | } 60 | \author{ 61 | Mike Johnson 62 | } 63 | -------------------------------------------------------------------------------- /man/findNED.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNED.R 3 | \name{findNED} 4 | \alias{findNED} 5 | \title{Find National Elevation Data (NED)} 6 | \usage{ 7 | findNED(AOI = NULL, res = 1) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | 12 | \item{res}{resolution of NED data. 1 equals 1 arc second, 13 equals 1/3 arc second.} 13 | } 14 | \value{ 15 | a list() of minimum length 2: AOI and NED 16 | } 17 | \description{ 18 | \code{findNED} returns \code{Raster} elevation data from the National Elevation Dataset (\href{https://nationalmap.gov/elevation.html}{NED}) for an AOI. 19 | Data comes the the USA National Map. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | el.paso.elev = getAOI(state = "CO", county = "El Paso") \%>\% findNED(res = 1) 24 | } 25 | } 26 | \author{ 27 | Mike Johnson 28 | } 29 | -------------------------------------------------------------------------------- /man/findNHD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNHD.R 3 | \name{findNHD} 4 | \alias{findNHD} 5 | \title{Find National Hydrography River Networks} 6 | \usage{ 7 | findNHD(AOI = NULL, comid = NULL, nwis = NULL, streamorder = NULL, 8 | crop = T) 9 | } 10 | \arguments{ 11 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 12 | 13 | \item{ids}{If TRUE, a vector of NHD COMIDs is added to retuned list (default = \code{FALSE})} 14 | } 15 | \value{ 16 | a list() of minimum length 2: AOI and nhd 17 | } 18 | \description{ 19 | \code{findNHD} returns a \code{SpatialLinesDataframe} of all NHDFlowlines reaches within an AOI. 20 | Data comes from the USGS CIDA server and contain 90 attributes, perhaps most notably: 21 | \itemize{ 22 | \item 'comid' : \code{integer} Integer value that uniquely identifies the occurrence of each feature in the NHD 23 | \item 'reachcode' : \code{character} Unique identifier for a ‘reach’. The first eight numbers are the WBD_HUC8 24 | \item 'fdate': \code{POSITct} Date of last feature modification 25 | \item 'gnis_id' : \code{character} Unique identifier assigned by GNIS 26 | \item 'gnis_name' : \code{character} Proper name, term, or expression by which a particular geographic entity is known 27 | \item 'lengthkm' : \code{numeric} Length of linear feature based on Albers Equal Area 28 | \item 'areasqkm' : \code{numeric} Area of areal feature based on Albers Equal Area, 29 | \item 'flowdir' : \code{character} Direction of flow relative to coordinate order. 30 | \item 'wbareacomi' : \code{integer} The COMID of the waterbody through which the flowline flows. 31 | \item 'ftype': \code{character} unique identifier of a feature type 32 | } 33 | } 34 | \examples{ 35 | \dontrun{ 36 | nhd = getAOI(clip = list("Tuscaloosa, AL", 10, 10)) \%>\% findNHD() 37 | } 38 | } 39 | \author{ 40 | Mike Johnson 41 | } 42 | -------------------------------------------------------------------------------- /man/findNID.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNID.R 3 | \name{findNID} 4 | \alias{findNID} 5 | \title{Find Dams in the US Army Core National Inventory (NID)} 6 | \usage{ 7 | findNID(AOI = NULL, ids = FALSE) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | 12 | \item{ids}{If TRUE, a vector of Dam IDs is added to retuned list (default = \code{FALSE})} 13 | } 14 | \value{ 15 | a list() of minimum length 2: AOI and dams 16 | } 17 | \description{ 18 | \code{findNID} returns a \code{SpatialPointsDataFrame} 19 | of all US Army Corps Dams for an Area of Interest from the National Inventory of Dams dataset. 20 | The National Inventory of Dams (NID) is a congressionally authorized database documenting dams in the United States and its territories 21 | This dataset is accessed through the \code{dams} R package and contains 61 attributes, perhaps most notably: 22 | \itemize{ 23 | \item 'Dam_Name' : \code{character} Dam Name 24 | \item 'NID_ID' : \code{character} Unique ID for the dam 25 | \item 'River': \code{character} Name of the river 26 | \item 'Owner_Type' : \code{character} Type of Owner 27 | \item 'Dam_Type' : \code{character} Type of Dam 28 | \item 'Primary_Purpose' : \code{numeric} Primary Purpose served 29 | \item 'Dam_Length' : \code{numeric} Length of the dam 30 | \item 'Dam_Height' : \code{numeric} Height of the dam 31 | \item 'Max_Discharge' : \code{numeric} Maximum Discharge 32 | \item 'Max_Storage': \code{character} Maximum Storage 33 | \item 'Normal_Storage': \code{character} Normal Storage 34 | } 35 | } 36 | \examples{ 37 | \dontrun{ 38 | # Find all dams in Texas 39 | tx.dams = getAOI(state = "TX") \%>\% findNID() 40 | } 41 | } 42 | \author{ 43 | Mike Johnson 44 | } 45 | -------------------------------------------------------------------------------- /man/findNLCD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNLCD.R 3 | \name{findNLCD} 4 | \alias{findNLCD} 5 | \title{Find National Land Cover Products (NLCD)} 6 | \usage{ 7 | findNLCD(AOI = NULL, year = 2011, type = "landcover") 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | 12 | \item{year}{the year(s) to download. Options include 2001, 2006, 2011. Default = 2011} 13 | 14 | \item{type}{the type of data to downlaod. Options include landcover, canopy, and impervious. Default = landcover} 15 | } 16 | \value{ 17 | a list() of minimum length 2: AOI and NLCD 18 | } 19 | \description{ 20 | \code{findNLCD} returns \code{Raster} land cover data from the National Land Cover Dataset (\href{https://www.mrlc.gov}{NLCD}) for an AOI. 21 | Data comes the the USA National Map and is avaialble for years 2001, 2006, 2011. 22 | In additon to landcover, users can get data reflecting impervious surface and conaopy cover. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | dt = getAOI(clip = list("Devil Tower")) \%>\% findNLDC(2006, 'landcover') 27 | dt = getAOI(clip = list("Devil Tower")) \%>\% findNLDC(2011, 'canopy') 28 | dt = getAOI(clip = list("Devil Tower")) \%>\% findNLDC(2011, 'impervious') 29 | } 30 | } 31 | \author{ 32 | Mike Johnson 33 | } 34 | -------------------------------------------------------------------------------- /man/findNLDI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNLDI.R 3 | \name{findNLDI} 4 | \alias{findNLDI} 5 | \title{Get NLDI Data} 6 | \usage{ 7 | findNLDI(comid = NULL, nwis = NULL, huc12 = NULL, type = NULL, 8 | spatial = TRUE, resources = NULL) 9 | } 10 | \arguments{ 11 | \item{comid}{a COMID value (see \code{findNHD} and \code{findNearestCOMID})} 12 | 13 | \item{nwis}{a USGS station values (see \code{findUSGS} and \code{findNearestUSGS})} 14 | 15 | \item{huc12}{a HUC12 id (see \code{findHUC})} 16 | 17 | \item{type}{a type of data to return ("UT", "UM","DD", "DM", "basin")} 18 | 19 | \item{spatial}{if \code{TRUE} returned data will be sp, else of type sf} 20 | 21 | \item{resources}{what type of resources to add ("comid", "huc12pp", "npdes_rad", "nwis", "wqp")} 22 | } 23 | \value{ 24 | a list of spatial / sf features 25 | } 26 | \description{ 27 | This function acts as a formal query to the NLDI 28 | } 29 | \author{ 30 | Mike Johnson 31 | } 32 | -------------------------------------------------------------------------------- /man/findNWIS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNWIS.R 3 | \name{findNWIS} 4 | \alias{findNWIS} 5 | \title{Find USGS NWIS Stream Gages} 6 | \usage{ 7 | findNWIS(AOI = NULL, siteType = "ST", paramCode = "00060", 8 | startDate = NULL, endDate = NULL, active = TRUE, full = FALSE) 9 | } 10 | \arguments{ 11 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 12 | 13 | \item{ids}{If TRUE, a vector of NIWS gage IDs are added to retuned list (default = \code{FALSE})} 14 | 15 | \item{comids}{f TRUE, a vector of NHD COMIDs IDs are added to retuned list (default = \code{FALSE})} 16 | } 17 | \value{ 18 | a list() of minimum length 2: AOI and nwis 19 | } 20 | \description{ 21 | \code{findNWIS} returns a \code{SpatialPointsDataFrame} 22 | of all USGS NWIS gages for an Area of Interest. This dataset is accessed through the NWIS web portal and contains the following attributes: 23 | \itemize{ 24 | \item 'OBJECTID' : \code{character} Unique ID in dataset 25 | \item 'feature_id' : \code{character} NHD COMID for reach 26 | \item 'site_no': \code{character} NWIS ID number 27 | \item 'site_name' : \code{character} Name of site 28 | \item 'da_sqkm' : \code{character} Area drainign to gage in square kilometers 29 | \item 'lat_reachCent' : \code{numeric} Latitude of the reach center, decimil degrees 30 | \item 'lon_reachCent' : \code{numeric} Longitude of the reach center, decimil degrees 31 | } 32 | } 33 | \examples{ 34 | \dontrun{ 35 | co = getAOI(state = "CO") \%>\% findNWIS() 36 | } 37 | } 38 | \author{ 39 | Mike Johnson 40 | } 41 | -------------------------------------------------------------------------------- /man/findNearestAirports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNearestAirports.R 3 | \name{findNearestAirports} 4 | \alias{findNearestAirports} 5 | \title{Find the Airports nearest a point} 6 | \usage{ 7 | findNearestAirports(point = NULL, n = 5, ids = FALSE, bb = FALSE) 8 | } 9 | \arguments{ 10 | \item{point}{a point described by lat/long, can be piped from \link[AOI]{geocode}} 11 | 12 | \item{n}{the number of Airports to find (default = 5)} 13 | 14 | \item{ids}{If TRUE, a vector of airport ICAO IDs is added to retuned list (default = \code{FALSE})} 15 | 16 | \item{bb}{If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE})} 17 | } 18 | \value{ 19 | a list() of minimum length 2: AOI and ap 20 | } 21 | \description{ 22 | \code{findNearestAirports} returns a \code{SpatialPointsDataFrame} of the 'n' number of airports closest to a declared point. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | pt = geocode("UCSB") \%>\% findNearestAirports(n = 5) 27 | } 28 | } 29 | \seealso{ 30 | findAirports 31 | } 32 | \author{ 33 | Mike Johnson 34 | } 35 | -------------------------------------------------------------------------------- /man/findNearestCOMID.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNearestCOMID.R 3 | \name{findNearestCOMID} 4 | \alias{findNearestCOMID} 5 | \title{Find Neareast COMIDs} 6 | \usage{ 7 | findNearestCOMID(point = NULL, n = 5, ids = FALSE, 8 | streamorder = NULL, bb = FALSE) 9 | } 10 | \arguments{ 11 | \item{point}{a point described by lat/long, can be piped from \link[AOI]{geocode}} 12 | 13 | \item{n}{the number of COMIDs to find (default = 5)} 14 | 15 | \item{ids}{If TRUE, a vector of NHD COMIDs is added to retuned list (default = \code{FALSE})} 16 | 17 | \item{bb}{If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE})} 18 | } 19 | \value{ 20 | a list() of minimum length 2: AOI and ap 21 | } 22 | \description{ 23 | \code{findNearestCOMID} returns a \code{SpatialPointsDataFrame} of the 'n' number of COMIDs closest to a declared point. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | pt = geocode("University of Oregon") \%>\% findNearestCOMID(n = 5) 28 | } 29 | } 30 | \seealso{ 31 | findAirports 32 | } 33 | \author{ 34 | Mike Johnson 35 | } 36 | -------------------------------------------------------------------------------- /man/findNearestHUC12.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNearestHUC12.R 3 | \name{findNearestHUC12} 4 | \alias{findNearestHUC12} 5 | \title{Find Neareast HUC12 boundaries} 6 | \usage{ 7 | findNearestHUC12(point = NULL, n = 1, ids = FALSE, bb = FALSE) 8 | } 9 | \arguments{ 10 | \item{point}{a point described by lat/long, can be piped from \link[AOI]{geocode}} 11 | 12 | \item{n}{the number of basins to find (default = 5)} 13 | 14 | \item{ids}{If TRUE, a vector of basin HUC IDs is added to retuned list (default = \code{FALSE})} 15 | 16 | \item{bb}{If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE})} 17 | } 18 | \value{ 19 | a list() of minimum length 2: AOI and wbd 20 | } 21 | \description{ 22 | \code{findNearestHUC12} returns a \code{SpatialPolygonDataFrame} of the 'n' number of HUC12 basins closest to a declared point. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | pt = geocode("UCSB") \%>\% findNearestHUC12(n = 5) 27 | } 28 | } 29 | \seealso{ 30 | findWBD 31 | } 32 | \author{ 33 | Mike Johnson 34 | } 35 | -------------------------------------------------------------------------------- /man/findNearestNWIS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNearestUSGS.R 3 | \name{findNearestNWIS} 4 | \alias{findNearestNWIS} 5 | \title{Find Neareast NWIS stations} 6 | \usage{ 7 | findNearestNWIS(point = NULL, n = 5, ids = FALSE, bb = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{point}{a point described by lat/long, can be piped from \link[AOI]{geocode}} 11 | 12 | \item{n}{the number of NWIS gages to find (default = 5)} 13 | 14 | \item{ids}{If TRUE, a vector of station IDs is added to retuned list (default = \code{FALSE})} 15 | 16 | \item{bb}{If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE})} 17 | } 18 | \value{ 19 | a list() of minimum length 2: AOI and nwis 20 | } 21 | \description{ 22 | \code{findNearestNWIS} returns a \code{SpatialPointsDataFrame} of the 'n' number of NWIS gages closest to a declared point. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | pt = geocode("UCSB") \%>\% findNearestNWIS(n = 5) 27 | } 28 | } 29 | \seealso{ 30 | findNWIS 31 | } 32 | \author{ 33 | Mike Johnson 34 | } 35 | -------------------------------------------------------------------------------- /man/findNearestWaterbodies.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findNearestWaterbodies.R 3 | \name{findNearestWaterbodies} 4 | \alias{findNearestWaterbodies} 5 | \title{Find Neareast NHD Waterbodies} 6 | \usage{ 7 | findNearestWaterbodies(point = NULL, n = 5, ids = FALSE, 8 | bb = FALSE) 9 | } 10 | \arguments{ 11 | \item{point}{a point described by lat/long, can be piped from \link[AOI]{geocode}} 12 | 13 | \item{n}{the number of NWIS gages to find (default = 5)} 14 | 15 | \item{ids}{If TRUE, a vector of station IDs is added to retuned list (default = \code{FALSE})} 16 | 17 | \item{bb}{If TRUE, the geometry of the minimum bounding area of the features is added to returned list (default = \code{FALSE})} 18 | } 19 | \value{ 20 | a list() of minimum length 2: AOI and nwis 21 | } 22 | \description{ 23 | \code{findNearestWaterbodies} returns a \code{SpatialPointsDataFrame} of the 'n' number of NHDwaterbodies closest to a declared point. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | pt = geocode("UCSB") \%>\% findNearestWaterbodies(n = 5) 28 | } 29 | } 30 | \seealso{ 31 | findNWIS 32 | } 33 | \author{ 34 | Mike Johnson 35 | } 36 | -------------------------------------------------------------------------------- /man/findRoads.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findRoads.R 3 | \name{findRoads} 4 | \alias{findRoads} 5 | \title{Find US Census Bureau TIGER Road Networks} 6 | \usage{ 7 | findRoads(AOI = FALSE) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | } 12 | \value{ 13 | a list() of minimum length 2: AOI and tiger 14 | } 15 | \description{ 16 | \code{findRoads} returns a \code{SpatialLinesDataFrame} of TIGER road networks cropped to an Area of Interest. 17 | This dataset is accessed through the US Census geo portal and contains the following attributes: 18 | \itemize{ 19 | \item 'LINEARID' : \code{character} Linear feature identifier 20 | \item 'FULLNAME' : \code{character} Feature Name 21 | \item 'RTTYP': \code{character} Route Type Code 22 | \item 'MTFCC' : \code{character} Road Classification 23 | \itemize{ 24 | \item S1100 Primary Roads 25 | \item R1011 Railroad Feature (Main, Spur, or Yard) 26 | \item R1051 Carline, Streetcar Track, Monorail, Other Mass Transit Rail) 27 | \item R1052 Cog Rail Line, Incline Rail Line, Tram 28 | \item S1100 Primary Road 29 | \item S1200 Secondary Road 30 | } 31 | } 32 | } 33 | \examples{ 34 | \dontrun{ 35 | AOI = getAOI(clip = list("UCSB", 10, 10)) \%>\% findRoads() 36 | } 37 | } 38 | \author{ 39 | Mike Johnson 40 | } 41 | -------------------------------------------------------------------------------- /man/findSSURGO.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findSSURGO.R 3 | \name{findSSURGO} 4 | \alias{findSSURGO} 5 | \title{Find SSURGO Maps and Mapunit Aggregated Attributes} 6 | \usage{ 7 | findSSURGO(AOI) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | } 12 | \value{ 13 | a list() of minimum length 2: AOI and ssurgo 14 | } 15 | \description{ 16 | SSURGO is a geospatial database of soils produced by the Natural Resources Conservation Service (NRCS). \code{findSSURGO} 17 | returns a \code{SpatialPolygonsDataFrame} of SSURGO map units and the Mapunit aggregated attributes (muaggatt table) associated with each MUKEY. In total 43 attributes are returned, 18 | all of which can be found in the [SSURGO documentation](https://sdmdataaccess.sc.egov.usda.gov/documents/TableColumnDescriptionsReport.pdf). The MUAGGATT values cover a wide range of 19 | soil realted questions however if a user is interested in the full range of tabular data associated with the SSURGO map units we suggest checking out the FedData package. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | AOI = getAOI(clip = list("UCSB", 10, 10)) \%>\% findSSURGO() 24 | } 25 | } 26 | \author{ 27 | Mike Johnson 28 | } 29 | -------------------------------------------------------------------------------- /man/findSnotel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findSnotel.R 3 | \name{findSnotel} 4 | \alias{findSnotel} 5 | \title{Find USDA NRCS Snotel Stations} 6 | \usage{ 7 | findSnotel(AOI = NULL, ids = FALSE) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | 12 | \item{ids}{If TRUE, a vector of NHD COMIDs is added to retuned list (default = \code{FALSE})} 13 | } 14 | \description{ 15 | \code{findSnotel} returns a \code{SpatialPointsDataFrame*} Objects cropped to an Area of Interest. 16 | Station data is extacted from \href{https://wcc.sc.egov.usda.gov/nwcc/yearcount?network=sntl&counttype=statelist&state=}{NRCS reports} and contains 11 attributes: 17 | \itemize{ 18 | \item 'NETWORK' : \code{integer} Description of Network (all = 'SNTL') 19 | \item 'STATE' : \code{character} The state the station is located in 20 | \item 'NAME': \code{POSITct} Unique station name 21 | \item 'ID' : \code{character} Unique identifier assigned by NRCS 22 | \item 'START.DATE' : \code{character} Date the station made first measurment ("Year-Month") 23 | \item 'LAT' : \code{numeric} Latitude of station, decimil degrees 24 | \item 'LON' : \code{numeric} Longitude of station, decimil degrees 25 | \item 'ELEV' : \code{character} Elevation of station 26 | \item 'COUNTY' : \code{integer} The county the station is located in 27 | \item 'HUC12.NAME': \code{character} The HUC12 name the station is located in 28 | \item 'HUC12.ID': \code{character} The HUC12 ID the station is located in 29 | } 30 | } 31 | \examples{ 32 | \dontrun{ 33 | CA.sno = getAOI(state = 'CA') \%>\% findSnotel() 34 | } 35 | } 36 | \author{ 37 | Mike Johnson 38 | } 39 | -------------------------------------------------------------------------------- /man/findWBD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findWBD.R 3 | \name{findWBD} 4 | \alias{findWBD} 5 | \title{Find Watershed Boundary Geometries (WBD/HUC)} 6 | \usage{ 7 | findWBD(AOI, level = 8, subbasins = FALSE, crop = TRUE, 8 | ids = FALSE) 9 | } 10 | \arguments{ 11 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 12 | 13 | \item{level}{defines the HUC level of interest (default = 8)} 14 | 15 | \item{subbasins}{If TRUE, all subbasins of the supplied level will be joined to retuned list} 16 | 17 | \item{crop}{If TRUE, all objects are cropped to the AOI boundaries (default = \code{TRUE})} 18 | 19 | \item{ids}{If TRUE, a vector of finest resolution HUC codes is added to returned list (default = \code{FALSE})} 20 | } 21 | \description{ 22 | The United States Geological Survey maintains a hierarchical system of hydrologic units each assigned a 23 | unique code (HUC). The hierarchical level is described by the number of digits in the code. A two-digit code (eg. HUC 2) is the coarsest unit of aggregation while the HUC 12 is the finest resolution. 24 | The spatial geometries of these units are stored in the Watershed Boundary Dataset with coverage of the United States. 25 | \code{findWBD} returns a \code{SpatialPolygonsDataFrame*} of WBD boundaries for the specified level within an AOI. Pending the query, 26 | data comes from the USGS CIDA server or the USGS staged products FTP. 27 | 28 | Below you can see the general factors for each HUC level:\ 29 | \tabular{ccccc}{ 30 | Name \tab Digits \tab Average Size (sqmiles) \tab Example Name \tab Example Code \cr 31 | Region \tab 2 \tab 177,560 \tab Pacific Northwest \tab 17 \cr 32 | Subregion \tab 4 \tab 16,800 \tab Lower Snake \tab 1706\cr 33 | Basin \tab 6 \tab 10,596 \tab Lower Snake \tab 170601 \cr 34 | Subbasin \tab 8 \tab 700 \tab Imnaha River \tab 17060102 \cr 35 | Watershed \tab 10 \tab 227 \tab Upper Imnaha River \tab 1706010201 \cr 36 | Subwatershed \tab 12 \tab 40 \tab North Fork Imnaha River \tab 170601020101 \cr 37 | } 38 | } 39 | \examples{ 40 | \dontrun{ 41 | # Get Cropped HUC8s for AOI 42 | getAOI(list("UCSB", 10, 10)) \%>\% findWBD() 43 | 44 | # Get Cropped HUC10s for AOI 45 | getAOI(list("UCSB", 10, 10)) \%>\% findWBD(level = 10) 46 | 47 | # Get Cropped HUC8s, HUC10s and HUC12s for AOI 48 | getAOI(clip = list("UCSB", 10, 10)) \%>\% findWBD(level = 8, subbasins = TRUE) 49 | 50 | # Get uncropped HUC10s for AOI 51 | getAOI(clip = list("UCSB", 10, 10)) \%>\% findWBD(level = 10, crop = FALSE) 52 | } 53 | } 54 | \author{ 55 | Mike Johnson 56 | } 57 | -------------------------------------------------------------------------------- /man/findWaterPoly.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findWaterPoly.R 3 | \name{findWaterPoly} 4 | \alias{findWaterPoly} 5 | \title{Find Water Polygon} 6 | \usage{ 7 | findWaterPoly(AOI) 8 | } 9 | \arguments{ 10 | \item{AOI}{an AOI} 11 | } 12 | \value{ 13 | a single polygon of all NHD water features. 14 | } 15 | \description{ 16 | A function to join all NHD water featrues into a single polygon. 17 | Flowlines are sized according to there Strahler stream order multiplied by 10 m. 18 | Useful for viualization and masking operations where a water surface is needed. 19 | } 20 | \examples{ 21 | \dontrun{ 22 | getAOI(state = 'CO', county = 'El Paso') \%>\% findWaterPoly() 23 | } 24 | } 25 | \author{ 26 | Mike Johnson 27 | } 28 | -------------------------------------------------------------------------------- /man/findWaterbodies.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findWaterbodies.R 3 | \name{findWaterbodies} 4 | \alias{findWaterbodies} 5 | \title{Find National Hydrography Dataset Waterbodies} 6 | \usage{ 7 | findWaterbodies(AOI = NULL, area = NULL) 8 | } 9 | \arguments{ 10 | \item{AOI}{A Spatial* or simple features geometry, can be piped from \link[AOI]{getAOI}} 11 | 12 | \item{ids}{If TRUE, a vector of waterbody IDs is added to retuned list (default = \code{FALSE})} 13 | } 14 | \value{ 15 | a list() of minimum length 2: AOI and waterboies 16 | } 17 | \description{ 18 | \code{findWaterbodies} returns a \code{SpatialPolgonsDataframe} of all NHDwaterbodies within an AOI. 19 | Data comes from the USGS CIDA server and contain 23 attributes, perhaps most notably: 20 | \itemize{ 21 | \item 'objectid' : \code{integer} Integer value that uniquely identifies the waterbody of each feature in the NHD 22 | \item 'comid' : \code{character} The COMID draining into the feature 23 | \item 'fdate': \code{POSITct} Date of last feature modification 24 | \item 'gnis_id' : \code{character} Unique identifier assigned by GNIS 25 | \item 'gnis_name' : \code{character} Proper name, term, or expression by which a particular geographic entity is known 26 | \item 'meandepth' : \code{numeric} Mean depth of the waterbody 27 | \item 'lakevolume' : \code{numeric} Total waterbody volume 28 | \item 'maxdepth' : \code{character} Maximum depth of waterbody 29 | \item 'meanused' : \code{integer} The average amount of water used 30 | } 31 | } 32 | \examples{ 33 | \dontrun{ 34 | getAOI(clip = "Tuscaloosa") \%>\% findWaterbodies() 35 | } 36 | 37 | } 38 | \author{ 39 | Mike Johnson 40 | } 41 | -------------------------------------------------------------------------------- /man/meta.data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/meta.data.R 3 | \name{meta.data} 4 | \alias{meta.data} 5 | \title{Return HydroData Object metadata} 6 | \usage{ 7 | meta.data(AOI) 8 | } 9 | \arguments{ 10 | \item{AOI}{and AOI object with appended HydroData features} 11 | } 12 | \value{ 13 | a data.frame of meta.data describing a HydroData object 14 | } 15 | \description{ 16 | Function for generating descriptive meta data for all HyrdroData objects 17 | } 18 | \author{ 19 | Mike Johnson 20 | } 21 | -------------------------------------------------------------------------------- /man/mosaic.hd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilitiy_mosaic.R 3 | \name{mosaic.hd} 4 | \alias{mosaic.hd} 5 | \title{Mosaic} 6 | \usage{ 7 | mosaic.hd(input) 8 | } 9 | \arguments{ 10 | \item{input}{raster stack} 11 | } 12 | \description{ 13 | Internal function for mosaicing a list of rasters 14 | } 15 | \author{ 16 | Mike Johnson 17 | } 18 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{re-export magrittr pipe operator} 6 | \description{ 7 | re-export magrittr pipe operator 8 | } 9 | -------------------------------------------------------------------------------- /man/query_cida.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/query_cida_12718.R 3 | \name{query_cida} 4 | \alias{query_cida} 5 | \title{CIDA Server Query} 6 | \usage{ 7 | query_cida(AOI = NULL, type, spatial = TRUE, filter = NULL) 8 | } 9 | \arguments{ 10 | \item{AOI}{and AOI object generated with the AOI package, or a bounding box} 11 | 12 | \item{type}{the WBD or nhdplus object to return} 13 | 14 | \item{spatial}{return `sp` (default) if \code{FALSE} return `sf`} 15 | } 16 | \value{ 17 | a \code{Spatial} object 18 | } 19 | \description{ 20 | CIDA Server Query 21 | } 22 | -------------------------------------------------------------------------------- /man/return.what.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_return_what.R 3 | \name{return.what} 4 | \alias{return.what} 5 | \title{Choose what to return for HydroData Calls} 6 | \usage{ 7 | return.what(AOI, type, report, vals) 8 | } 9 | \arguments{ 10 | \item{AOI}{Spatial object} 11 | 12 | \item{type}{the index of the AOI object to report on} 13 | 14 | \item{report}{character sting to append values to} 15 | 16 | \item{vals}{the ids call} 17 | } 18 | \value{ 19 | a list of HydroData components 20 | } 21 | \description{ 22 | A function defining what should be returned in a HydroData object 23 | } 24 | \author{ 25 | Mike Johnson 26 | } 27 | -------------------------------------------------------------------------------- /man/saveHD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_save.file.R 3 | \name{saveHD} 4 | \alias{saveHD} 5 | \title{Save File} 6 | \usage{ 7 | saveHD(AOI = NULL, path = NULL, ext = "shp") 8 | } 9 | \arguments{ 10 | \item{AOI}{What data to write} 11 | 12 | \item{path}{State abb} 13 | 14 | \item{ext}{country call} 15 | } 16 | \description{ 17 | Save File 18 | } 19 | -------------------------------------------------------------------------------- /man/snotel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_data.R 3 | \docType{data} 4 | \name{snotel} 5 | \alias{snotel} 6 | \title{Snotel Stations} 7 | \format{a \code{dataframe} instance, 1 row per station with columns: 8 | \itemize{ 9 | \item 'NETWORK': A \code{integer} Network of interest 10 | \item 'STATE': A \code{integer} State abbriviation 11 | \item 'NAME': A \code{character} Site name 12 | \item 'START.DATE': A \code{integer} Day of first measurement 13 | \item 'LAT': A \code{integer} Station Latitude 14 | \item 'LONG': A \code{character} Station Longitude 15 | \item 'ELEV': A \code{character} Station Elevation 16 | \item 'COUNTY': A \code{character} County 17 | \item 'HUC12.NAME': A \code{character} HUC 12 Name 18 | \item 'HUC12.ID': A \code{character} HUC 12 code 19 | }} 20 | \source{ 21 | \href{https://wcc.sc.egov.usda.gov/nwcc/yearcount?network=sntl&state=&counttype=statelist}{SNOTEL INFORMATION} 22 | } 23 | \usage{ 24 | snotel 25 | } 26 | \description{ 27 | \code{snotel}NRCS SNOTEL station metadata 28 | } 29 | \examples{ 30 | \dontrun{ 31 | tiles = HydroData::snotelStations.rda 32 | } 33 | } 34 | \keyword{datasets} 35 | -------------------------------------------------------------------------------- /man/to_sf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/to_sf.R 3 | \name{to_sf} 4 | \alias{to_sf} 5 | \title{Convert Spatial HydroData Objects to Simple Features} 6 | \usage{ 7 | to_sf(hydro.data.object = NULL) 8 | } 9 | \arguments{ 10 | \item{hydro.data.object}{a HydroData object with Spatial components} 11 | } 12 | \value{ 13 | a list with the same length as the input 14 | } 15 | \description{ 16 | A function to convert all Spatial* HydroData objects to simple feature geometries. 17 | Non-Spatial objects (eg raster and list components) will be skipped over. 18 | } 19 | \examples{ 20 | \dontrun{ 21 | AOI = getAOI(clip = 'UCSB') \%>\% findNED \%>\% findNHD \%>\% findNWIS \%>\% to_sf 22 | } 23 | } 24 | \author{ 25 | Mike Johnson 26 | } 27 | -------------------------------------------------------------------------------- /man/usgsStations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_data.R 3 | \docType{data} 4 | \name{usgsStations} 5 | \alias{usgsStations} 6 | \title{USGS NWIS station information} 7 | \format{a \code{dataframe} instance, 1 row per station with columns: 8 | \itemize{ 9 | \item 'OBJECTID': A \code{character} Object id in the dataset 10 | \item 'feature_id': A \code{character} NHD COMID of reach 11 | \item 'site_no': A \code{character} USGS site number 12 | \item 'site_name': A \code{character} USGS site name 13 | \item 'da_sqkm': A \code{numeric} Area that drains to the location in square kilometers 14 | \item 'lat_reachCent': A \code{numeric} Latitude of NHD reach center 15 | \item 'lon_reachCent': A \code{numeric} Longitude of NHD reach center 16 | }} 17 | \source{ 18 | Compiled from USGS and NHD datasets 19 | } 20 | \usage{ 21 | usgsStations 22 | } 23 | \description{ 24 | Dataset containing information about USGS stations in the United States 25 | } 26 | \examples{ 27 | \dontrun{ 28 | usgs = HydroData::usgsStations 29 | } 30 | } 31 | \keyword{datasets} 32 | -------------------------------------------------------------------------------- /man/writeHD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_writeHD.R 3 | \name{writeHD} 4 | \alias{writeHD} 5 | \title{Write Data to disk} 6 | \usage{ 7 | writeHD(AOI, class, dir, feature_name, ext = "shp") 8 | } 9 | \arguments{ 10 | \item{AOI}{a HydroData object with components to write to disk} 11 | 12 | \item{class}{objects class} 13 | 14 | \item{dir}{directory} 15 | 16 | \item{feature_name}{object id} 17 | 18 | \item{ext}{shp or gpkg} 19 | } 20 | \description{ 21 | interal function used to write data to disk according to it meta.data found via HydroData::meta.data() 22 | } 23 | -------------------------------------------------------------------------------- /tests/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/tests/.DS_Store -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(HydroData) 3 | 4 | test_check("HydroData") 5 | -------------------------------------------------------------------------------- /tests/testthat/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikejohnson51/HydroData/6b7f08656d7299bca3a544652cb69ae064049d41/tests/testthat/.DS_Store -------------------------------------------------------------------------------- /tests/testthat/test_airports.R: -------------------------------------------------------------------------------- 1 | context("findAirports") 2 | 3 | test_that("check Airport routines", { 4 | state <- getAOI(state = "CO") %>% findAirports() 5 | county <- getAOI(state = "CO", county = "El Paso") %>% findAirports() 6 | clip <- getAOI(clip = list("UCSB", 30, 30)) %>% findAirports() 7 | ids <- getAOI(state = "CO") %>% findAirports(ids = T) 8 | 9 | vec = c(is.list(state), is.list(county), is.list(clip), is.list(ids)) 10 | print(!inherits(vec,"try-error")) 11 | check = !inherits(vec,"try-error") 12 | expect_true(check) 13 | }) 14 | 15 | test_that("check closest Airport routines", { 16 | clip <- geocode("UCSB") %>% findNearestAirports() 17 | 18 | vec = c(is.list(clip)) 19 | print(!inherits(vec,"try-error")) 20 | check = !inherits(vec,"try-error") 21 | expect_true(check) 22 | }) 23 | 24 | -------------------------------------------------------------------------------- /tests/testthat/test_ghcn.R: -------------------------------------------------------------------------------- 1 | context("findGHCN") 2 | 3 | test_that("GHCN throws correct errors", { 4 | expect_error(findGHCN(clip = list("UCSB", .3,.3)), "0 stations found in AOI", fixed = TRUE) 5 | expect_error(findNearestGHCN(location = c(37, -113), n = 5, PARAM = "PPT"), "PPT is not a valid GHCN parameter", fixed = TRUE) 6 | 7 | }) 8 | 9 | test_that("check GHCN routines", { 10 | PARAM <- try(findGHCN(state = "Colorado", param = "PRCP", save = FALSE)) 11 | #county <- try(findGHCN(state = "Colorado", county = "El Paso", save = TRUE)) 12 | #clip <- try(findGHCN(clip = list("UCSB", 40, 40))) 13 | ids <- try(findGHCN(clip = list("UCSB", 40, 40), ids = TRUE)) 14 | save <- try(findGHCN(state = 'TX', county = 'Harris', boundary = FALSE, save = TRUE)) 15 | bounds <- try(findGHCN(clip = list("UCSB", 40, 40), boundary = TRUE)) 16 | 17 | 18 | vec = c(is.list(PARAM), is.list(ids), is.list(save), is.list(bounds)) 19 | print(!inherits(vec,"try-error")) 20 | check = !inherits(vec,"try-error") 21 | expect_true(check) 22 | }) 23 | 24 | 25 | test_that("check closest GHCN routines", { 26 | clip <- try(findNearestGHCN(location = c(37, -113), n = 5, PARAM = "PRCP")) 27 | clip1 <- try(findNearestGHCN("UCSB", n = 10)) 28 | 29 | vec = c(is.list(clip), is.list(clip1)) 30 | print(!inherits(vec,"try-error")) 31 | check = !inherits(vec,"try-error") 32 | expect_true(check) 33 | }) 34 | 35 | -------------------------------------------------------------------------------- /tests/testthat/test_nhd.R: -------------------------------------------------------------------------------- 1 | context("findNHD") 2 | 3 | test_that("findNHD throws correct errors", { 4 | expect_error(findNHD(clip = list("UCSB", .3,.3)), "O features found in this AOI.") 5 | }) 6 | 7 | test_that("check NHD routines", { 8 | clip <- findNHD(clip = list("Denver", 10, 10), save = TRUE) 9 | clip1 <- findNHD(clip = list("Denver", 10, 10), save = FALSE, ids = T) 10 | 11 | vec = c(is.list(clip), is.list(clip1)) 12 | print(!inherits(vec,"try-error")) 13 | check = !inherits(vec,"try-error") 14 | expect_true(check) 15 | }) 16 | 17 | test_that("check closest COMID routines", { 18 | clip <- try(findNearestCOMID(location = c(37, -113), n = 5)) 19 | clip1 <- try(findNearestCOMID("UCSB", n = 10)) 20 | 21 | vec = c(is.list(clip), is.list(clip1)) 22 | print(!inherits(vec,"try-error")) 23 | check = !inherits(vec,"try-error") 24 | expect_true(check) 25 | }) 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/testthat/test_usgs.R: -------------------------------------------------------------------------------- 1 | context("findUSGS") 2 | 3 | test_that("USGS throws correct errors", { 4 | expect_error(findGHCN(clip = list("UCSB", .3,.3)), "0 stations found in AOI") 5 | expect_error(findNearestGHCN(location = c(37, -113), n = 5, PARAM = "PPT"), "PPT is not a valid GHCN parameter") 6 | 7 | }) 8 | 9 | test_that("check USGS routines", { 10 | ids <- try(findUSGS(clip = list("UCSB", 40, 40), ids = TRUE)) 11 | save <- try(findUSGS(state = 'TX', county = 'Harris', boundary = FALSE, save = TRUE)) 12 | bounds <- try(findUSGS(clip = list("UCSB", 40, 40), boundary = TRUE)) 13 | 14 | 15 | vec = c( is.list(ids), is.list(save), is.list(bounds)) 16 | print(!inherits(vec,"try-error")) 17 | check = !inherits(vec,"try-error") 18 | expect_true(check) 19 | }) 20 | 21 | 22 | # test_that("check closest USGS routines", { 23 | # clip <- try(findNearestGHCN(location = c(37, -113), n = 5, PARAM = "PRCP")) 24 | # clip1 <- try(findNearestGHCN("UCSB", n = 10)) 25 | # 26 | # vec = c(is.list(clip), is.list(clip1)) 27 | # print(!inherits(vec,"try-error")) 28 | # check = !inherits(vec,"try-error") 29 | # expect_true(check) 30 | # }) 31 | 32 | -------------------------------------------------------------------------------- /tests/testthat/test_utilities.R: -------------------------------------------------------------------------------- 1 | context("utility functions") 2 | 3 | test_that("cida server throws correct errors", { 4 | expect_error(query_cida(AOI::getAOI(clip= list("UCSB", 1, 1)), type = "test") , "Type not found.", fixed = TRUE) 5 | }) 6 | 7 | test_that("make sure data exists", { 8 | test1 = is.null(HydroData::usgsStations) 9 | test2 = is.null(HydroData::snotel) 10 | test3 = is.null(HydroData::ap) 11 | 12 | vec = c(test1, test2, test3) 13 | 14 | print(any(!isTRUE(vec))) 15 | check = any(!isTRUE(vec)) 16 | expect_true(check) 17 | }) 18 | --------------------------------------------------------------------------------