-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
122 lines (95 loc) · 3.29 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "images/"
)
```
# nhdR
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/nhdR)](https://cran.r-project.org/package=nhdR)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/nhdR)](https://cran.r-project.org/package=nhdR)
[![Travis-CI Build Status](https://travis-ci.org/jsta/nhdR.svg?branch=master)](https://travis-ci.org/jsta/nhdR)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/jsta/nhdR?branch=master&svg=true)](https://ci.appveyor.com/project/jsta/nhdR)
The goal of nhdR is to provide R tools for interacting with the [National Hydrography Dataset](https://nhd.usgs.gov/).
## Installation
You can install nhdR from github with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("jsta/nhdR")
```
## Usage
### Load package
```{r }
library(nhdR)
```
### NHD Plus
Unlike the standard NHD, the NHD-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](http://www.horizon-systems.com/NHDPlus/NHDPlusV2_data.php).
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(ggplot2)
library(stringr)
dt <- nhdR::vpu_shp#[,"UnitID"]
dt <- dt[dt$UnitType == "VPU",]
centroid_xy <- sf::st_as_text(sf::st_geometry(sf::st_centroid(dt[,"UnitID"])))
extract_coords <- function(messy_centroid){
res <- stringr::str_split(messy_centroid, "\\(", simplify = TRUE)[2]
res <- stringr::str_split(res, "\\)", simplify = TRUE)[1]
stringr::str_split(res, " ", simplify = TRUE)
}
coords <- data.frame(matrix(
as.numeric(unlist(lapply(centroid_xy, extract_coords))),
ncol = 2, byrow = TRUE), stringsAsFactors = FALSE)
names(coords) <- c("x", "y")
coords$x <- coords$x * -1
coords$UnitID <- dt[,"UnitID"]$UnitID
ggplot(dt) +
geom_sf(aes(fill = UnitID), show.legend = FALSE) +
xlim(126, 70) +
ylim(23, 52) +
geom_text(data = coords, aes(x = x, y = y, label = UnitID)) +
theme_minimal() +
theme(axis.title = element_blank()) +
ggtitle("Vector Processing Units (VPU)")
```
```{r eval=FALSE}
# get a vpu export
nhd_plus_get(vpu = 4, "NHDSnapshot")
nhd_plus_get(vpu = 4, "NHDPlusAttributes")
nhd_plus_get(vpu = 4, "NHDPlusCatchment")
```
```{r }
# list layers
nhd_plus_list(vpu = 4, "NHDSnapshot")
nhd_plus_list(vpu = 4, "NHDPlusAttributes")
nhd_plus_list(vpu = 4, "NHDPlusCatchment")
```
```{r eval=FALSE}
# get layer info
nhd_plus_info(vpu = 4, "NHDSnapshot", "NHDWaterbody")
```
```{r echo=FALSE}
info <- capture.output(nhd_plus_info(vpu = 4, "NHDSnapshot", "NHDWaterbody"))
# gsub("/home/jose", "~", info)
info[2:length(info)]
```
```{r }
# load layer
dt <- nhd_plus_load(vpu = 4, "NHDSnapshot", "NHDWaterbody")
```
### NHD
```{r eval=FALSE}
nhd_get(state = c("DC", "HI"))
```
```{r }
nhd_list(state = "DC")
```
```{r }
nhd_info(state = "DC", dsn = "NHDWaterbody")
```
```{r }
head(nhd_load(state = "DC", dsn = "NHDWaterbody"))
```