-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistance.qmd
127 lines (106 loc) · 4.42 KB
/
distance.qmd
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
---
execute:
warning: false
error: false
cache: true
---
# Distance from Storm Track
## Data Procurement
* Hurricane track data was downloaded from the `hurricaneexposuredata` package using the `data("hurr_tracks")` command. This data originates from the [HURDAT2](https://www.nhc.noaa.gov/data/).
* ZCTA to County Crosswalk was downloaded from <https://www2.census.gov/geo/docs/maps-data/data/rel/zcta_county_rel_10.txt>
* ZCTA shapefiles were downloaded for the entire US using the `tigris` package
## Data Processing
1. Hurricane data was downloaded using `hurricaneexposuredata` package using the `data("hurr_tracks")` command and filtered using the Harvey Automated Tropical Cyclone Forecasting code (AL092017)
2. Hurricane track was imputed to every 15 minutes using `create_full_track` from the `stormwindmodel` package.
3. Separately, 2017 ZCTAs downloaded from the [US Census Cartographic Boundary Files](https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.2017.html#list-tab-1556094155)
4. Then, the ZCTAs were joined to the [US Census ZCTA to County Crosswalk](https://www2.census.gov/geo/docs/maps-data/data/rel/zcta_county_rel_10.txt) in order to identify Texas and Louisiana ZCTAs
5. The ZCTAs were filtered to Texas and Louisiana
6. ZCTA geo centroid were calculated
7. The distance from geo-centroid of each ZCTA to closest point on imputed track and time when imputed track was closest were calculated
## Output
- `TXLA_ZCTA_dist2track`
- **GEOID** - ZCTA GEOID
- **dist2track** - Distance from geo-centroid to closest point on imputed track (meters)
- **dateTime** - UTC date and time where geo-centroid is closest to imputed track
Download, filter, and impute hurricane tract
```{r}
library(tidyverse)
library(sf)
library(hurricaneexposure)
data(hurr_tracks, package = "hurricaneexposuredata")
AL092017_track <- hurr_tracks %>%
filter(usa_atcf_id == "AL092017") %>%
create_full_track() %>%
arrange(date) %>%
st_as_sf(coords = c("tclon", "tclat"), crs = "epsg:4269")
AL092017_track_line <- AL092017_track %>%
st_combine() %>%
st_cast("LINESTRING")
```
Downloaded ZCTA shapefiles and calculated centroids
```{r}
#| output: false
library(tigris)
ZCTAs <- read_csv("https://www2.census.gov/geo/docs/maps-data/data/rel/zcta_county_rel_10.txt") %>%
filter(STATE %in% c(48, 22)) %>%
distinct(ZCTA5) %>%
rename(GEOID = ZCTA5)
ZCTAs_sf <- ZCTAs %>%
left_join(zctas(cb = FALSE, year = 2017), by = join_by(GEOID == GEOID10)) %>%
st_as_sf() %>%
select(-c(ZCTA5CE10, CLASSFP10, MTFCC10, FUNCSTAT10, ALAND10, AWATER10, INTPTLAT10, INTPTLON10))
ZCTAs_center <- ZCTAs_sf %>%
st_transform("ESRI:102003") %>%
st_centroid() %>%
st_transform("EPSG:4269")
```
Calculated shortest distance to track from geo centroids
```{r}
TXLA_dist2track <- st_join(ZCTAs_center, AL092017_track, join = st_nearest_feature) %>%
rename(dateTime = date) %>%
rowwise() %>%
mutate(est_track_point =
AL092017_track %>%
filter(date == dateTime) %>%
st_geometry()
) %>%
mutate(dist2track = st_distance(geometry, est_track_point)) %>%
mutate(dist2track = as.numeric(dist2track)) %>%
st_drop_geometry() %>%
select(GEOID, dateTime, dist2track)
```
```{r}
TXLA_dist2track %>%
left_join(ZCTAs_sf) %>%
st_as_sf() %>%
ggplot() +
geom_sf(aes(fill = dist2track)) +
geom_sf(data = st_crop(AL092017_track_line, ZCTAs_sf)) +
coord_sf(datum = "ESRI:102003") +
scale_fill_distiller(
palette = "Oranges",
name = "Smallest Distance to Hurricane Track",
direction = 1,
guide = guide_colorbar(
direction = "horizontal",
title.position = "top")) +
theme_void() +
theme(
plot.title = element_text(face = "bold", size = 16),
plot.subtitle = element_text(face = "bold", size = 12),
plot.caption = element_text(size = 10, hjust = 0),
legend.title = element_text(face = "bold", size = 12),
legend.text = element_text(face = "bold", size = 12),
legend.title.align=0.5,
legend.position = "bottom",
legend.key.width = unit(dev.size()[1] / 10, "inches")) +
labs(
title = "Smallest Distance to Hurricane Track by ZCTA ",
subtitle = "Texas and Louisiana",
caption = "Author: Ryan Zomorrodi\nDate: 4/1/2024\nSource: hurricaneexposuredata")
```
```{r}
#| output: false
TXLA_dist2track %>%
st_write("output/TXLA_ZCTA_dist2track.gpkg", "TXLA_ZCTA_dist2track", append = FALSE)
```