-
Notifications
You must be signed in to change notification settings - Fork 1
/
creek_selectR_GIS.Rmd
125 lines (82 loc) · 5.11 KB
/
creek_selectR_GIS.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
---
title: "Creek SelectR"
author: "Mwessel"
date: "7/4/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
rm(list = ls())
# marcus says install install.version(sf,.98) but i haven't yet.
library(sf)
library(tidyverse)
library(leaflet)
library(dplyr)
library(here)
```
# Workflow to Update Tidal Creeks to Run61
This program uses pre-processed GIS shapefiles and full IWR dataset read into R. GIS files have been intersected and joined to develop the inputs for the TC dashboard. Eventually the GIS processes will be coded in R within the Creek_selectR program. For now they are developed here to provide a replicable path.
Because some wbids include multiple creeks and some creeks include multiple wbids it is not possible to just subset the iwr dataset based on a static wbid file and run the TC functions. Instead stations (STA) must be assigned to a creek identifier (JEI) using the creek line file and a 200 meter buffer. An additional complicating factor is that FDEP changes WBID names and boundaries routinely which means that the IWR run WBID and Station shapefiles associated with each run should be used to intersect the creek population and then the data should be subset in that manner. The following workflow outlines the process using preprocessed GIS shapefiles.
Shapefile definitions:
* WBID_Run61 - shapefile generated by DEP with all WBIDS in the state of Florida
* IWR_Stations_Run61 - DEP shapefile of all water quality and biology stations ever sampled in the state of Florida
* TidalCreek_ALL_Line - Line File with CreekID and Creek Length(m). This line file is not broken into WBIDs but is used to create the 200 meter buffer
* TidalCreek_ALL_Line_Buff200m - Polygon file from All_line file above with a 200 m buffer. A flat buffer is used here so the buffer doesnt extend past the ends of the line
* TidalCreek_ALL_Line_WBID61 - Line file joined to IWR WBID shape so line file is broken into WBIDs with CreekID, total Length(m), WBID, and Length in WBID (m).
* TidalCreek_ALL_Line_StatWBID61_Join - IWR Station point file joined with the buffer file to select stations within buffer, then joined to the WBID61 line file so that station is matched with closest creek. A distance field (m) is provided and WBID is retained.
## Step 1 Read in GIS shapefiles necessary to input dahsboard.
```{r}
setwd(here::here("./shapes"))
# Full IWR Run61 WBID and station files that would be used for future updates
IWR_WBID<- sf::read_sf(dsn = ".", layer = "WBID_Run61")
IWR_STA <- sf::read_sf(dsn = ".", layer = "IWR_Stations_Run61") # all stations ever!
Creek_jei <- sf::read_sf(dsn = ".", layer = "TidalCreek_ALL_Line_WBID61")
# make unique WBID list for plotting
wbids<-unique(Creek_jei$WBID)
Creek_sta <- sf::read_sf(dsn = ".", layer = "TidalCreek_ALL_Line_StatWBID61_join")%>%
mutate(sta=STATION_ID)
# you dont need this one but i wanted to make sure it reads in
Creek_buff <- sf::read_sf(dsn = ".", layer = "TidalCreek_All_Line_Buff200m")
```
## Step 2 Read in Full IWR dataset
This dataset starts as a SAS file from DEP. i pre-processed it in the Creek_selectR program and saved it as a rdata file. The creek_selectR program will eventually supercede this program
```{r readin}
setwd(here("./data"))
load(here::here("./data/full_iwr61.rdata"))
```
# Step 3 combine the list of stations in the buffer with the IWR dataset and pull out only those stations collected in the last 10 years
```{r}
getwd()
## this outputs a dataset that has only those stations with data in the last 10 years
yearin<-2010
iwrraw<-left_join(Creek_sta,full_iwr,by='sta')%>%
filter(year > yearin & year !=2021)%>%
dplyr::select('wbid', 'class', 'sta', 'year', 'month', 'day', 'time', 'depth', 'depth2', 'param', 'masterCode', 'result','rCode', 'newComment')
# don't know why it retains geometry?
save(iwrraw, file = here('./data/iwrraw_run61.RData'))
```
#Step 4 - do some plotting by creating unique lists of stations and wbids
```{r}
# filter full iwr wbid to only those in creek pop
Creek_list<-IWR_WBID%>%filter(WBID %in% (wbids))
# save to use in index for creekstats page
save(Creek_list, file = here('./data/Creek_list.RData'))
# create unique list of stations with data only in last 10 years
selected_sta<-tibble(unique(iwrraw$sta))%>%
mutate(sta=unique(iwrraw$sta))%>%
select(sta)
# save to use in index for creekstats page
save(selected_sta, file = here('./data/selected_sta.RData'))
# filter joined shapefile to stations only in last 10 years
Creek_stas<-Creek_sta%>%filter(sta %in% (selected_sta$sta))
# assign crs
Creek_stas <- st_transform(Creek_stas, crs = 4326)
Creek_list <- st_transform(Creek_list, crs = 4326)
Creek_jei <- st_transform(Creek_jei, crs = 4326)
# plot
leaflet::leaflet() %>%
leaflet::addProviderTiles(providers$CartoDB.Voyager) %>%
leaflet::addPolygons(color = "#222", weight = 2, opacity = 1, fillOpacity = 0,label = ~lapply(WBID, htmltools::htmlEscape), data = Creek_list ) %>%
leaflet::addCircles(color = "red", label = ~lapply(sta, htmltools::htmlEscape),data = Creek_stas)%>%
leaflet::addPolylines(label = ~lapply(CreekID, htmltools::htmlEscape),data = Creek_jei)
```