This tutorial will show you how to use some GIS tools to analyze which points are within a certain distance of the flood zones. I’m using rivers in Broome County to demonstrate this, but you should be able to use the flood zone shape to do this. Using these tools, you can create new variables in your EFAM data set that will allow you to filter the data by how close each location is to a flood zone.
#load in packages
library(sf)
library(dplyr)
library(spData)
library(urbnmapr)
library(ggplot2)
Let’s map the rivers data as my example data - this is shapefile data, and is very easy to map.
#Load in our rivers data
setwd("~/Binghamton/DIDA 370/hydrography")
river_shape <- st_read("LinearHydrography.shp")
Reading layer `LinearHydrography' from data source
`C:\Users\melha\OneDrive\Documents\Binghamton\DIDA 370\hydrography\LinearHydrography.shp'
using driver `ESRI Shapefile'
Simple feature collection with 151192 features and 4 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 105713.8 ymin: 4484981 xmax: 759541.5 ymax: 4985341
Projected CRS: NAD83 / UTM zone 18N
river_shape <- river_shape %>% st_transform("EPSG:32116")
#Map it!
#load in NYS county shape file and set crs
counties <- get_urbn_map("counties", sf = TRUE)
#filter the data to get just NYS
counties <- counties %>%
filter(state_abbv == "NY") %>%
st_transform("EPSG:32116")
#Let's map them now!
ggplot() +
geom_sf(data = counties,
mapping = aes(), color = "lightgray")+
geom_sf(data = river_shape,
mapping = aes(), color = "blue")+
theme_minimal()
#That map is pretty hard to see - let's focus on Broome county
broome <- counties %>% filter(county_name == "Broome County")
broome_hydro <- river_shape[broome,]
creek <- broome_hydro %>% filter(NAME == "Little Choconut Creek")
ggplot() +
geom_sf(data = broome,
mapping = aes(), color = "lightgray")+
geom_sf(data = creek,
mapping = aes(), color = "blue")+
theme_minimal()
#filter so we only have the place points for Broome county
broome_place <- place_shape[broome]
Error in `[.data.frame`(x, i) : undefined columns selected
ggplot() +
geom_sf(data = broome,
mapping = aes(), color = "lightgray")+
geom_sf(data = creek,
mapping = aes(), color = "blue")+
geom_sf(data = broome_place, mapping = aes(), color = "yellow")+
theme_minimal()
To examine what points are within a certain distance of another object, we need what’s called a buffer. This data is stored in meters rather than kilometers, just so you know. Let’s see what places are within 500 meters of the creek - they may be at risk of facing flooding!
creek_buff_500 = st_buffer(creek, dist = 500)
ggplot() +
geom_sf(data = broome,
mapping = aes(), color = "lightgray")+
geom_sf(data = creek_buff_500,
mapping = aes(), fill = "blue", color = "blue")+
geom_sf(data = broome_place, mapping = aes(), color = "yellow")+
theme_minimal()
#find what point intersect with the creek buffer
intersect <- place_shape[creek_buff_500,]
#map the intersecting points
ggplot() +
geom_sf(data = broome,
mapping = aes(), color = "lightgray")+
geom_sf(data = creek,
mapping = aes(), fill = "blue", color = "blue")+
geom_sf(data = broome_place, mapping = aes(), color = "yellow")+
geom_sf(data = intersect, mapping = aes(), color = "red")+
theme_minimal()
We probably will want to filter the data later based on which points were close to the creek. Let’s create a new variable in our original place points data frame that equals one for points that within 500 meters of the creek, and a 0 otherwise.
head(place_shape)
Simple feature collection with 6 features and 9 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 67422.36 ymin: 200951.7 xmax: 458434.5 ymax: 427758.1
Projected CRS: NAD83 / New York Central
NAME PLACETYPE RANK NBHD_CITY COUNTY FULLSTATE
1 19th Ward Neighborhood 5 Rochester Monroe New York
2 Abbott McKinley Neighborhood 5 Buffalo Erie New York
3 Accord Unincorporated Place 4 <NA> Ulster New York
4 Acra Unincorporated Place 4 <NA> Greene New York
5 Adams Incorporated Village 2 <NA> Jefferson New York
6 Adams Incorporated Town 3 <NA> Jefferson New York
DATEMOD NOTES geometry within_500
1 2015-03-27 <NA> POINT (163271 349071.5) 0
2 2015-03-27 <NA> POINT (67422.36 318923.1) 0
3 2003-02-01 <NA> POINT (445685.9 200951.7) 0
4 2003-02-01 <NA> POINT (458434.5 259723.3) 0
5 2003-02-01 <NA> POINT (295073.9 423441.9) 0
6 2003-02-01 <NA> POINT (293852.2 427758.1) 0
Once we have this, we can create multiple variables to help filter our data. For example, you could create a variable that shows only the places within the flood zone, the places within one mile, and the places within five miles of a flood zone. Those variables could then be used to filter the data in an interactive dashboard, so that users can see what places would be potentially affected by a flooding disaster.