diff --git a/queries.R b/queries.R index b75ad96..130abbb 100644 --- a/queries.R +++ b/queries.R @@ -49,16 +49,24 @@ view.hurdat_track <- tbl(con, "hurdat_track") view.all_loss_storms <- tbl(con, "all_loss_storms") view.all_loss_landfalls <- tbl(con, "all_loss_landfalls") view.yearly_normalized_losses <- tbl(con, "yearly_normalized_losses") -view.county_population_housing <- tbl(con, "county_population_housing") +view.simplified_county_geom <- tbl(con, "simplified_county_geom") # test storm -storm <- list( - storm_basin = "AL", - storm_year = 2005, - storm_name = "KATRINA", - lf_type = "LF", - lf_id = 1 -) +#katrina <- list( +# storm_basin = "AL", +# storm_year = 2005, +# storm_name = "KATRINA", +# lf_type = "LF", +# lf_id = 1 +#) + +#galveston <- list( +# storm_basin = "AL", +# storm_year = 1900, +# storm_name = "GALVESTON", +# lf_type = "LF", +# lf_id = 1 +#) # helper functions @@ -236,12 +244,9 @@ get_normalized_metric_growth <- function(storm, full_lf_id) { ) query <- normalized_metrics %>% - inner_join( - public.counties, - by = c("state_fips" = "statefp", "county_fips" = "countyfp") - ) %>% + inner_join(public.counties, by = c("state_fips" = "statefp", "county_fips" = "countyfp")) %>% mutate( - geom_wkt = sql("ST_AsText(ST_Transform(geom, 4326))") + geom_wkt = sql("ST_AsText(ST_SimplifyPreserveTopology(ST_Transform(geom, 4326), .001))") ) %>% select( state_fips, @@ -255,6 +260,26 @@ get_normalized_metric_growth <- function(storm, full_lf_id) { ) %>% arrange(state_fips, county_fips, year) + #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) + result <- query %>% collect() return(result)