{"id":22413706,"url":"https://github.com/jsta/nhdr","last_synced_at":"2025-10-17T09:11:30.929Z","repository":{"id":48331889,"uuid":"75339263","full_name":"jsta/nhdR","owner":"jsta","description":"R interface to the National Hydrography Dataset :droplet:","archived":false,"fork":false,"pushed_at":"2023-08-14T13:25:27.000Z","size":10377,"stargazers_count":39,"open_issues_count":16,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-08T05:40:29.767Z","etag":null,"topics":["cran","geospatial","national-hydrography-dataset","nhd","rstats","water-quality","water-resources"],"latest_commit_sha":null,"homepage":"https://jsta.github.io/nhdR/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsta.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-12-01T22:41:39.000Z","updated_at":"2025-10-06T09:20:18.000Z","dependencies_parsed_at":"2023-09-21T19:33:10.081Z","dependency_job_id":null,"html_url":"https://github.com/jsta/nhdR","commit_stats":{"total_commits":449,"total_committers":5,"mean_commits":89.8,"dds":"0.22271714922049002","last_synced_commit":"0e5e18633e0ea9116e228c6b57c7e08919363782"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/jsta/nhdR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsta%2FnhdR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsta%2FnhdR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsta%2FnhdR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsta%2FnhdR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsta","download_url":"https://codeload.github.com/jsta/nhdR/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsta%2FnhdR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018312,"owners_count":26086342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cran","geospatial","national-hydrography-dataset","nhd","rstats","water-quality","water-resources"],"created_at":"2024-12-05T14:14:22.369Z","updated_at":"2025-10-17T09:11:30.895Z","avatar_url":"https://github.com/jsta.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\"\n)\n```\n\n[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable) \n[![CRAN\\_Status\\_Badge](http://www.r-pkg.org/badges/version/nhdR)](https://cran.r-project.org/package=nhdR) \n[![R-CMD-check](https://github.com/jsta/nhdR/actions/workflows/R-CMD-check.yml/badge.svg)](https://github.com/jsta/nhdR/actions/workflows/R-CMD-check.yml) \n[![DOI](https://zenodo.org/badge/75339263.svg)](https://zenodo.org/badge/latestdoi/75339263)\n\n# nhdR \u003ca href='https://jsta.github.io/nhdR/'\u003e\u003cimg src=\"man/figures/logo.png\" align=\"right\" height=140/\u003e\u003c/a\u003e\n\nTools for querying, downloading, and networking both the [National Hydrography Dataset (NHD)](https://www.usgs.gov/national-hydrography) and [NHDPlus](https://www.epa.gov/waterdata/nhdplus-national-hydrography-dataset-plus) datasets.\n\n## Installation\n\nCRAN policy is that no package can write to a persistent location by default. As a result, `nhdR` writes all data to a temporary location unless a `temporary = FALSE` argument is passed to the `nhd_plus_get`/`nhd_get` functions. Alternatively, `nhdR` will automatically write data to a persistent location if the `nhdR_path` environment variable is set. To do this, add the following line to your `.Rprofile`:\n```r\nSys.setenv(nhdR_path = file.path(rappdirs::user_data_dir(appname = \"nhdR\",\n      appauthor = \"nhdR\")))\n```\n\n Your `.Rprofile` file can be edited using the `usethis::edit_r_profile()` function.\n\n### Stable version from CRAN\n\n```{r, eval=FALSE}\ninstall.packages(\"nhdR\")\n```\n\n### or development version from GitHub\n\n```{r gh-installation, eval = FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"jsta/nhdR\")\n```\n\nThis package also requires an installation of [7-zip](https://www.7-zip.org/) that can be called via the command line using `7z` or `7za.exe` (check if your machine is good to go with `nhdR:::has_7z()`).\n\n## Usage\n### Load package\n\n```{r message=FALSE, results='hide'}\nlibrary(nhdR)\n```\n\n### NHD Plus\n\nNHD-Plus exports are organized by vector processing unit (vpu). See below for a low resolution vpu map (also `nhdR::vpu_shp`). A hi-res version can be found [here](https://www.epa.gov/waterdata/nhdplus-global-data).\n\n```{r echo=FALSE, message=FALSE, warning=FALSE}\nlibrary(ggplot2)\nlibrary(stringr)\n\ndt \u003c- nhdR::vpu_shp # [,\"UnitID\"]\ndt \u003c- dt[dt$UnitType == \"VPU\", ]\n\ncentroid_xy \u003c- sf::st_as_text(sf::st_geometry(sf::st_centroid(dt[, \"UnitID\"])))\nextract_coords \u003c- function(messy_centroid) {\n  res \u003c- stringr::str_split(messy_centroid, \"\\\\(\", simplify = TRUE)[2]\n  res \u003c- stringr::str_split(res, \"\\\\)\", simplify = TRUE)[1]\n  stringr::str_split(res, \" \", simplify = TRUE)\n}\n\ncoords \u003c- data.frame(matrix(\n  as.numeric(unlist(lapply(centroid_xy, extract_coords))),\n  ncol = 2, byrow = TRUE), stringsAsFactors = FALSE)\nnames(coords) \u003c- c(\"x\", \"y\")\ncoords$x \u003c- coords$x * -1\ncoords$UnitID \u003c- dt[, \"UnitID\"]$UnitID\n\nggplot(dt) +\n  geom_sf(aes(fill = UnitID), show.legend = FALSE) +\n  xlim(126, 70) +\n  ylim(23, 52) +\n  geom_text(data = coords, aes(x = x, y = y, label = UnitID)) +\n  theme_minimal() +\n  theme(axis.title = element_blank()) +\n  ggtitle(\"Vector Processing Units (VPU)\")\n```\n\n```{r eval=FALSE}\n# get a vpu export\nnhd_plus_get(vpu = 4, \"NHDSnapshot\")\nnhd_plus_get(vpu = 4, \"NHDPlusAttributes\")\nnhd_plus_get(vpu = 4, \"NHDPlusCatchment\")\n```\n\n``` r\n# list layers\nnhd_plus_list(vpu = 4, \"NHDSnapshot\")\n#\u003e  [1] \"NHDArea.dbf\"                \"NHDAreaEventFC.dbf\"        \n#\u003e  [3] \"NHDAreaEventFC.shp\"         \"NHDArea.shp\"               \n#\u003e  [5] \"NHDFCode.dbf\"               \"NHDFlowline.dbf\"           \n#\u003e  [7] \"NHDFlowline.shp\"            \"NHDFlowline.shp.xml\"       \n#\u003e  [9] \"NHDLine.dbf\"                \"NHDLineEventFC.dbf\"        \n#\u003e [11] \"NHDLineEventFC.shp\"         \"NHDLine.shp\"               \n#\u003e [13] \"NHDPoint.dbf\"               \"NHDPointEventFC.dbf\"       \n#\u003e [15] \"NHDPointEventFC.shp\"        \"NHDPoint.shp\"              \n#\u003e [17] \"NHDReachCode_Comid.dbf\"     \"NHDReachCrossReference.dbf\"\n#\u003e [19] \"NHDWaterbody.dbf\"           \"NHDWaterbody.shp\"\nnhd_plus_list(vpu = 4, \"NHDPlusAttributes\")\n#\u003e  [1] \"CumulativeArea.dbf\"              \"DivFracMP.dbf\"                  \n#\u003e  [3] \"elevslope.dbf\"                   \"HeadwaterNodeArea.dbf\"          \n#\u003e  [5] \"MegaDiv.dbf\"                     \"PlusARPointEvent.dbf\"           \n#\u003e  [7] \"PlusFlowAR.dbf\"                  \"PlusFlow.dbf\"                   \n#\u003e  [9] \"PlusFlowlineLakeMorphology.dbf\"  \"PlusFlowlineVAA.dbf\"            \n#\u003e [11] \"PlusWaterbodyLakeMorphology.dbf\"\nnhd_plus_list(vpu = 4, \"NHDPlusCatchment\")\n#\u003e [1] \"Catchment.dbf\"         \"Catchment.shp\"         \"featureidgridcode.dbf\"\n```\n\n\n``` r\n# get layer info\nnhd_plus_info(vpu = 4, \"NHDSnapshot\", \"NHDWaterbody\")\n```\n\n    #\u003e  [1] \"Driver: ESRI Shapefile; number of rows: 31830 \"     \n    #\u003e  [2] \"Feature type: wkbPolygon with 3 dimensions\"         \n    #\u003e  [3] \"Extent: (-93.24332 40.43575) - (-73.61814 48.11344)\"\n    #\u003e  [4] \"CRS: +proj=longlat +datum=NAD83 +no_defs  \"         \n    #\u003e  [5] \"LDID: 87 \"                                          \n    #\u003e  [6] \"Number of fields: 12 \"                              \n    #\u003e  [7] \"         name type length typeName\"                 \n    #\u003e  [8] \"1       COMID    0      9  Integer\"                 \n    #\u003e  [9] \"2       FDATE    9     10     Date\"                 \n    #\u003e [10] \"3  RESOLUTION    4      7   String\"                 \n    #\u003e [11] \"4     GNIS_ID    4     10   String\"                 \n    #\u003e [12] \"5   GNIS_NAME    4     65   String\"                 \n    #\u003e [13] \"6    AREASQKM    2     19     Real\"                 \n    #\u003e [14] \"7   ELEVATION    2     19     Real\"                 \n    #\u003e [15] \"8   REACHCODE    4     14   String\"                 \n    #\u003e [16] \"9       FTYPE    4     24   String\"                 \n    #\u003e [17] \"10      FCODE    0      9  Integer\"                 \n    #\u003e [18] \"11 SHAPE_LENG    2     19     Real\"                 \n    #\u003e [19] \"12 SHAPE_AREA    2     19     Real\"\n\n```{r eval=FALSE, echo=FALSE}\ninfo \u003c- capture.output(nhd_plus_info(vpu = 4, \"NHDSnapshot\", \"NHDWaterbody\"))\n# gsub(\"/home/jemma\", \"~\", info)\ninfo[2:length(info)]\n```\n\n``` r\n# load layer\ndt \u003c- nhd_plus_load(vpu = 4, \"NHDSnapshot\", \"NHDWaterbody\")\n#\u003e Reading layer `NHDWaterbody' from data source \n#\u003e   `/home/jemma/.local/share/nhdR/NHDPlus/GL_04_NHDSnapshot/NHDWaterbody.shp' \n#\u003e   using driver `ESRI Shapefile'\n#\u003e Simple feature collection with 31830 features and 12 fields\n#\u003e Geometry type: POLYGON\n#\u003e Dimension:     XYZ\n#\u003e Bounding box:  xmin: -93.24332 ymin: 40.43575 xmax: -73.61814 ymax: 48.11344\n#\u003e z_range:       zmin: 0 zmax: 0\n#\u003e Geodetic CRS:  NAD83\n```\n\n### NHD\n\nNHD exports are organized by US state. \n\n```{r eval=FALSE}\nnhd_get(state = c(\"DC\", \"HI\"))\n```\n\n``` r\nnhd_list(state = \"DC\")\n#\u003e  [1] \"ExternalCrosswalk\"           \"NHDFCode\"                   \n#\u003e  [3] \"NHDFeatureToMetadata\"        \"NHDFlow\"                    \n#\u003e  [5] \"NHDFlowlineVAA\"              \"NHDMetadata\"                \n#\u003e  [7] \"NHDProcessingParameters\"     \"NHDReachCodeMaintenance\"    \n#\u003e  [9] \"NHDReachCrossReference\"      \"NHDSourceCitation\"          \n#\u003e [11] \"NHDStatus\"                   \"NHDVerticalRelationship\"    \n#\u003e [13] \"NHDPoint\"                    \"NHDFlowline\"                \n#\u003e [15] \"NHDLine\"                     \"NHDArea\"                    \n#\u003e [17] \"NHDWaterbody\"                \"NHDAreaEventFC\"             \n#\u003e [19] \"NHDLineEventFC\"              \"NHDPointEventFC\"            \n#\u003e [21] \"WBDLine\"                     \"NonContributingDrainageArea\"\n#\u003e [23] \"NWISBoundary\"                \"NWISDrainageArea\"           \n#\u003e [25] \"WBDHU14\"                     \"WBDHU8\"                     \n#\u003e [27] \"WBDHU2\"                      \"WBDHU4\"                     \n#\u003e [29] \"WBDHU6\"                      \"WBDHU10\"                    \n#\u003e [31] \"WBDHU12\"                     \"WBDHU16\"                    \n#\u003e [33] \"HYDRO_NET_Junctions\"        \n#\u003e attr(,\"driver\")\n#\u003e [1] \"OpenFileGDB\"\n#\u003e attr(,\"nlayers\")\n#\u003e [1] 33\n```\n\n``` r\nnhd_info(state = \"DC\", dsn = \"NHDWaterbody\")\n#\u003e Source: \"/home/jemma/.local/share/nhdR/NHD_H_District_of_Columbia_State_GDB.gdb\", layer: \"NHDWaterbody\"\n#\u003e Driver: OpenFileGDB; number of rows: 8011 \n#\u003e Feature type: wkbPolygon with 3 dimensions\n#\u003e Extent: (-78.07095 38.52142) - (-76.82219 39.64683)\n#\u003e CRS: +proj=longlat +datum=NAD83 +no_defs \n#\u003e Number of fields: 13 \n#\u003e                    name type length typeName\n#\u003e 1  Permanent_Identifier    4     40   String\n#\u003e 2                 FDate   11      0 DateTime\n#\u003e 3            Resolution    0      0  Integer\n#\u003e 4               GNIS_ID    4     10   String\n#\u003e 5             GNIS_Name    4     65   String\n#\u003e 6              AreaSqKm    2      0     Real\n#\u003e 7             Elevation    2      0     Real\n#\u003e 8             ReachCode    4     14   String\n#\u003e 9                 FType    0      0  Integer\n#\u003e 10                FCode    0      0  Integer\n#\u003e 11     VisibilityFilter    0      0  Integer\n#\u003e 12         Shape_Length    2      0     Real\n#\u003e 13           Shape_Area    2      0     Real\n```\n\n``` r\nhead(nhd_load(state = \"DC\", dsn = \"NHDWaterbody\"))\n#\u003e Reading layer `NHDWaterbody' from data source \n#\u003e   `/home/jemma/.local/share/nhdR/NHD_H_District_of_Columbia_State_GDB.gdb' \n#\u003e   using driver `OpenFileGDB'\n#\u003e Simple feature collection with 8011 features and 13 fields\n#\u003e Geometry type: MULTIPOLYGON\n#\u003e Dimension:     XYZ\n#\u003e Bounding box:  xmin: -78.07095 ymin: 38.52142 xmax: -76.82219 ymax: 39.64683\n#\u003e z_range:       zmin: 0 zmax: 0\n#\u003e Geodetic CRS:  NAD83\n#\u003e Reading query `SELECT * from NHDWaterbody LIMIT 1' from data source `/home/jemma/.local/share/nhdR/NHD_H_District_of_Columbia_State_GDB.gdb' \n#\u003e   using driver `OpenFileGDB'\n#\u003e Simple feature collection with 1 feature and 13 fields\n#\u003e Geometry type: MULTIPOLYGON\n#\u003e Dimension:     XYZ\n#\u003e Bounding box:  xmin: -76.99652 ymin: 38.68957 xmax: -76.99631 ymax: 38.6897\n#\u003e z_range:       zmin: 0 zmax: 0\n#\u003e Geodetic CRS:  NAD83\n#\u003e Simple feature collection with 6 features and 13 fields\n#\u003e Geometry type: POLYGON\n#\u003e Dimension:     XY\n#\u003e Bounding box:  xmin: -77.5767 ymin: 38.68957 xmax: -76.99631 ymax: 39.5882\n#\u003e Geodetic CRS:  WGS 84\n#\u003e   Permanent_Identifier               FDate Resolution GNIS_ID GNIS_Name\n#\u003e 1             46565431 2002-07-21 18:00:00          2    \u003cNA\u003e      \u003cNA\u003e\n#\u003e 2             51767181 2002-08-14 18:00:00          2    \u003cNA\u003e      \u003cNA\u003e\n#\u003e 3             51767223 2002-08-14 18:00:00          2    \u003cNA\u003e      \u003cNA\u003e\n#\u003e 4             51767287 2002-08-14 18:00:00          2    \u003cNA\u003e      \u003cNA\u003e\n#\u003e 5             51767709 2002-08-14 18:00:00          2    \u003cNA\u003e      \u003cNA\u003e\n#\u003e 6             51768273 2002-08-14 18:00:00          2    \u003cNA\u003e      \u003cNA\u003e\n#\u003e   AreaSqKm Elevation      ReachCode FType FCode VisibilityFilter Shape_Length\n#\u003e 1    0.000        NA 02070010004605   436 43624                0 0.0005402029\n#\u003e 2    0.002        NA 02070008004808   390 39004            50000 0.0017289109\n#\u003e 3    0.001        NA 02070008004829   390 39004          2000000 0.0013369633\n#\u003e 4    0.001        NA 02070008004860   390 39004            24000 0.0011083831\n#\u003e 5    0.002        NA 02070008005063   390 39004            50000 0.0016429957\n#\u003e 6    0.001        NA 02070008005335   390 39004            24000 0.0012442057\n#\u003e     Shape_Area                          Shape\n#\u003e 1 1.879174e-08 POLYGON ((-76.99631 38.6896...\n#\u003e 2 1.954519e-07 POLYGON ((-77.56946 39.5881...\n#\u003e 3 1.239613e-07 POLYGON ((-77.56954 39.5567...\n#\u003e 4 8.130533e-08 POLYGON ((-77.57658 39.5250...\n#\u003e 5 1.745505e-07 POLYGON ((-77.46919 39.3298...\n#\u003e 6 8.126193e-08 POLYGON ((-77.2087 39.18799...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsta%2Fnhdr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsta%2Fnhdr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsta%2Fnhdr/lists"}