mirror of
https://github.com/dylanbenzi/hurricane_normalization_app.git
synced 2026-07-30 05:08:57 +00:00
update growth map to use indirect landfall states
This commit is contained in:
+68
-19
@@ -30,6 +30,8 @@ fips.counties <- tbl(con, I("fips.counties"))
|
||||
fips.states <- tbl(con, I("fips.states"))
|
||||
|
||||
gis.affected_area_landfalls <- tbl(con, I("gis.affected_area_landfalls"))
|
||||
gis.indirect_landfalls <- tbl(con, I("gis.indirect_landfalls"))
|
||||
gis.us_states_boundary <- tbl(con, I("gis.us_states_boundary"))
|
||||
|
||||
hurdat.best_track <- tbl(con, I("hurdat.best_track"))
|
||||
hurdat.hurdat_storms <- tbl(con, I("hurdat.hurdat_storms"))
|
||||
@@ -54,6 +56,7 @@ view.all_lf_type_landfalls <- tbl(con, "all_lf_type_landfalls")
|
||||
view.lf_id_location <- tbl(con, "lf_id_location")
|
||||
view.lf_landfall_gis <- tbl(con, "lf_landfall_gis")
|
||||
view.best_track_summary <- tbl(con, "best_track_summary")
|
||||
view.yearly_state_metrics <- tbl(con, "yearly_state_metrics")
|
||||
#qry <- econ.storm_base_loss %>%
|
||||
# left_join(view.hurdat_track, by = c("storm_basin", "storm_year", "storm_name"))
|
||||
|
||||
@@ -417,6 +420,7 @@ get_hurdat_track <- function(storm) {
|
||||
get_normalized_metric_growth <- function(storm, full_lf_id) {
|
||||
lf_id_parts <- split_full_lf_id(full_lf_id)
|
||||
|
||||
if (lf_id_parts$lf_type == 'LF') {
|
||||
affected_counties <- gis.affected_area_landfalls %>%
|
||||
filter(
|
||||
storm_basin == storm$storm_basin,
|
||||
@@ -482,26 +486,71 @@ get_normalized_metric_growth <- function(storm, full_lf_id) {
|
||||
geom_wkt
|
||||
) %>%
|
||||
arrange(state_fips, county_fips, year)
|
||||
} else {
|
||||
affected_state <- gis.indirect_landfalls %>%
|
||||
filter(
|
||||
storm_basin == storm$storm_basin,
|
||||
storm_year == storm$storm_year,
|
||||
storm_name == storm$storm_name,
|
||||
lf_type == lf_id_parts$lf_type,
|
||||
lf_id == lf_id_parts$lf_id
|
||||
) %>%
|
||||
select(
|
||||
state_fips
|
||||
)
|
||||
|
||||
#query <- normalized_metrics %>%
|
||||
# inner_join(
|
||||
# public.counties,
|
||||
# by = c("state_fips" = "statefp", "county_fips" = "countyfp")
|
||||
# ) %>%
|
||||
# mutate(
|
||||
# geom_wkt = sql("ST_AsText(ST_Transform(geom, 4326))")
|
||||
# ) %>%
|
||||
# select(
|
||||
# state_fips,
|
||||
# county_fips,
|
||||
# year,
|
||||
# population,
|
||||
# housing_units,
|
||||
# normalized_population,
|
||||
# normalized_housing,
|
||||
# geom_wkt
|
||||
# ) %>%
|
||||
# arrange(state_fips, county_fips, year)
|
||||
baseline_metrics <- view.yearly_state_metrics %>%
|
||||
filter(year == storm$storm_year) %>%
|
||||
inner_join(affected_state, by = "state_fips") %>%
|
||||
select(
|
||||
state_fips,
|
||||
baseline_population = state_population,
|
||||
baseline_housing = state_housing_units
|
||||
)
|
||||
|
||||
normalized_metrics <- view.yearly_state_metrics %>%
|
||||
filter(
|
||||
year >= storm$storm_year
|
||||
) %>%
|
||||
inner_join(affected_state, by = "state_fips") %>%
|
||||
inner_join(baseline_metrics, by = "state_fips") %>%
|
||||
mutate(
|
||||
normalized_population = as.numeric(state_population) /
|
||||
as.numeric(baseline_population),
|
||||
normalized_housing = as.numeric(state_housing_units) /
|
||||
as.numeric(baseline_housing)
|
||||
) %>%
|
||||
select(
|
||||
state_fips,
|
||||
year,
|
||||
population = state_population,
|
||||
housing_units = state_housing_units,
|
||||
normalized_population,
|
||||
normalized_housing
|
||||
)
|
||||
|
||||
query <- normalized_metrics %>%
|
||||
inner_join(
|
||||
gis.us_states_boundary %>%
|
||||
rename(state_fips = statefp),
|
||||
by = "state_fips"
|
||||
) %>%
|
||||
mutate(
|
||||
geom_wkt = sql(
|
||||
"ST_AsText(ST_SimplifyPreserveTopology(ST_Transform(wkb_geometry, 4326), .001))"
|
||||
)
|
||||
) %>%
|
||||
select(
|
||||
state_fips,
|
||||
year,
|
||||
population,
|
||||
housing_units,
|
||||
normalized_population,
|
||||
normalized_housing,
|
||||
geom_wkt
|
||||
) %>%
|
||||
arrange(state_fips, year)
|
||||
}
|
||||
|
||||
result <- query %>% collect()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user