-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
175 lines (130 loc) · 5.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
tidy.opts=list(width.cutoff=60),
tidy=TRUE
)
library(NFHL)
library(tmap)
library(AOI)
library(dplyr)
library(sf)
```
# NFHL: National Flood Hazard Layers
<!-- badges: start -->
[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)
[![Dependencies](https://img.shields.io/badge/dependencies-4/19-green?style=flat)](#)
[![R CMD Check](https://github.com/mikejohnson51/NFHL/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mikejohnson51/NFHL/actions/workflows/R-CMD-check.yaml)
[![Website](https://github.com/mikejohnson51/NFHL/actions/workflows/pkgdown.yaml/badge.svg)](https://github.com/mikejohnson51/NFHL/actions/workflows/pkgdown.yaml)
<!-- badges: end -->
The `NFHL` package provides access data from FEMA's [National Flood Hazards Layers](https://www.fema.gov/national-flood-hazard-layer-nfhl). It integates with the [AOI](https://github.com/mikejohnson51/AOI) package for spatial subsetting workflows and offers functionality to extract and query NFHL layers.
## Installation
You can install the development version of `NFHL` from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
remotes::install_github("mikejohnson51/NFHL")
# load libraries
library(NFHL)
library(AOI)
library(dplyr)
```
## Basic Workflow
### Layer IDs
The NFHL contains data for `r nrow(nfhl_meta)` layers. Use `nfhl_meta` to view the list of available layer IDs and names.
```{r, eval = F}
nfhl_meta
```
```{r, echo = F}
print(nfhl_meta)
```
### Layer descriptions
To get detailed information, such as layer name, description, and bounding box, use the `nfhl_describe()` function. For example, let's explore Layer ID 14 (Cross-Sections):
```{r}
nfhl_describe(14)
```
### Extracting Spatial Data
The `nfhl_get()` function retrieves spatial data for a specific layer and area of interest (AOI). The general workflow involves:
1. Defining an AOI.
2. Selecting a layer ID.
3. Extracting spatial data.
```{r}
# Define an AOI around UCSB
AOI <- AOI::aoi_ext("UCSB", wh = 10, units = "km", bbox = TRUE) |>
st_as_sf()
# View at Layer ID 28 description
nfhl_describe(28)$Description
# Extract Flood Hazard Polygons and filter by Special Flood Hazard Areas (SFHA)
floodhazard <- nfhl_get(AOI, 28) %>%
filter(SFHA_TF == "T")
```
```{r, echo = FALSE}
tm_shape(floodhazard) +
tm_fill(col = 'STUDY_TYP') +
tm_borders() +
tm_compass(type = "8star", position = c("right", "bottom")) +
tm_layout(
legend.outside = TRUE,
legend.outside.position = 'bottom',
legend.bg.alpha = 1)
```
## Examples
### Overlaying NHD and NFHL Cross-Sections
Layer ID 14 provides cross-sectional data. Let’s overlay it with hydrographic data from the National Hydrography Dataset (NHD) using the `nhdplusTools` package:
Before we learned that the NFHL offered cross-sectional information (ID: 14). Lets get this data for our UCSB AOI, and overlay it with hydrographic data from NHD.
```{r, message = F, warning = F}
# Get NHD data for the AOI
nhd <- nhdplusTools::get_nhdplus(AOI)
# Extract NFHL Cross-Section data (ID: 14)
cs <- nfhl_get(nhd, 14)
```
```{r echo = FALSE}
tm_shape(cs) +
tm_lines() +
tm_shape(nhd) +
tm_lines(col = "blue") +
tm_compass(type = "8star", position = c("right", "bottom"))
```
## Linking General Structures with NHD
Layer ID 24 provides data on "General Structures." Here, we extract this layer, overlay it with NHD data, and identify structures that cross NHD features.
```{r}
# Describe Layer ID 24
nfhl_describe(24)$Description
# Extract General Structures
stru <- nfhl_get(AOI, 24)
# Identify crossings between structures and NHD data
crossings = st_join(stru,
st_transform(nhd, st_crs(stru)),
join = st_crosses,
left = FALSE) %>%
st_drop_geometry() %>%
mutate(realtionship = "crosses") %>%
select(OBJECTID, realtionship, comid, STRUCT_TYP, LAYER)
# View results
head(crossings)
```
Here, we identified `r nrow(crossings)` structural crossing's in the AOI river networ. For example, bridge 932599 crosses COMID 17596113.
```{r echo = FALSE}
tm_shape(nhd) +
tm_lines(col = "blue") +
tm_shape(stru) +
tm_lines(col = 'STRUCT_TYP', lwd = 5) +
tm_compass(type = "8star", position = c("right", "bottom")) +
tm_layout(
legend.outside = TRUE,
legend.outside.position = 'bottom',
legend.height = .5,
legend.position = c("left","bottom"),
legend.bg.color = "white",
legend.bg.alpha = 1)
```
Here, we identified `r nrow(crossings)` structural crossing's in the AOI river networ. For example, bridge 932599 crosses COMID 17596113.
## Acknowledgements
[Mike Johnson](http://mikejohnson51.github.io) is the Geospatial Science and Technology Lead at NOAA's Office of Water Prediction (OWP). This work contributes to the NSFfunded [Convergence Accelorator Program](https://nsf.gov/awardsearch/showAward?AWD_ID=1937099&HistoricalAwards=false) on [Urban Flooding](https://ufokn.github.io/UFOKN/).
This package is experimental and comes with no guarantee. Pull requests are welcome!!