Skip to content

Commit 473dcbf

Browse files
committedMar 11, 2024·
working on allsg table
1 parent 177494b commit 473dcbf

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed
 

‎R/dat_proc.R

+60-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ library(raster)
1313
# this is the projection for the seagrass segment layer from the district
1414
prj <- 2882
1515

16-
1716
# bay segments clipped to shore -------------------------------------------
1817

1918
load(file = url('https://github.com/tbep-tech/benthic-dash/raw/main/data/segmask.RData'))
@@ -89,3 +88,63 @@ for(i in 1:length(fls)){
8988
save(list = flnm, file = here('data', paste0('/', flnm, '.RData')), compress = 'xz')
9089

9190
}
91+
92+
# union of all sg layers as "potential" -------------------------------------------------------
93+
94+
library(sf)
95+
library(tidyverse)
96+
library(here)
97+
98+
res <- list.files('data', '^sgdat') %>%
99+
enframe() %>%
100+
group_by(value) %>%
101+
nest %>%
102+
mutate(
103+
dat = purrr::map(value, function(x){
104+
105+
cat(x, '\t')
106+
107+
# import file
108+
load(file = here(paste0('data/', x)))
109+
dat <- get(gsub('\\.RData', '', x))
110+
111+
dat_out <- dat |>
112+
filter(FLUCCSCODE %in% c(9113, 9116)) |>
113+
st_union() |>
114+
st_geometry()
115+
116+
return(dat_out)
117+
118+
})
119+
)
120+
121+
out <- res$dat[[1]]
122+
for(i in 2:nrow(res)){
123+
124+
cat(i, '\t')
125+
out <- st_union(out, res$dat[[i]])
126+
127+
}
128+
129+
allsgdat <- out
130+
save(allsgdat, file = here('data/allsgdat.RData'))
131+
132+
133+
# area sum of allsgdat ------------------------------------------------------------------------
134+
135+
load(file = here('data/allsgdat.RData'))
136+
137+
# area sum
138+
allsgacres <- allsgdat %>%
139+
st_transform(crs = prj) %>%
140+
st_intersection(sgseg, .) %>%
141+
filter(!segment %in% c('Upper Sarasota Bay-m', 'Gulf of Mexico')) %>%
142+
mutate(
143+
Acres = st_area(.),
144+
Acres = units::set_units(Acres, 'acres'),
145+
Acres = as.numeric(Acres)
146+
) %>%
147+
st_set_geometry(NULL) |>
148+
arrange(segment)
149+
150+
save(allsgacres, file = here('data/allsgacres.RData'))

‎R/funcs.R

+28
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,32 @@ sgmapfun <- function(datin, colnm = c('Segment', 'Areas'), yrsel, bndin, maxv){
237237

238238
return(out)
239239

240+
}
241+
242+
#' @export
243+
allsgmapfun <- function(){
244+
245+
box::use(
246+
mapview[...],
247+
leaflet[...],
248+
dplyr[...],
249+
leafem[removeMouseCoordinates],
250+
here[...]
251+
)
252+
253+
load(file = here('data/allsgdat.RData'))
254+
255+
m <- mapview(allsgdat, homebutton = F, popup = NULL, legend = F, col.regions = '#006D2C', alpha = 0.8) %>%
256+
.@map %>%
257+
removeMouseCoordinates()
258+
259+
return(m)
260+
261+
}
262+
263+
#' @export
264+
allsgtabfun <- function(dat, valtyp){
265+
266+
browser()
267+
240268
}

‎data/allsgacres.RData

301 Bytes
Binary file not shown.

‎data/allsgdat.RData

4.42 MB
Binary file not shown.

‎index.Rmd

+23-1
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ box::use(
2929
tidyr[spread, gather],
3030
reactable[reactableOutput, renderReactable],
3131
knitr[include_graphics, kable],
32-
R/funcs[sgrctfun, sgmapfun, sgchgfun, sgtotchgfun]
32+
R/funcs[sgrctfun, sgmapfun, sgchgfun, sgtotchgfun, allsgmapfun]
3333
)
3434
data(file = 'seagrass', package = 'tbeptools')
3535
data(file = 'sgmanagement', package = 'tbeptools')
3636
load(file = here('data/allsegests.RData'))
3737
load(file = here('data/allmngests.RData'))
3838
load(file = here('data/segclp.RData'))
39+
load(file = here('data/allsgacres.RData'))
3940
4041
# years to select
4142
yrs2 <- unique(allsegests$yr) %>%
@@ -404,6 +405,18 @@ mngptcmap <- reactive({
404405
405406
return(out)
406407
408+
})
409+
410+
# tabular sum of allsgdat by bay segment
411+
allsgtab <- reactive({
412+
413+
# input
414+
valtyp <- input$valtyp
415+
416+
out <- allsgtabfun(allsgacres, valtyp)
417+
418+
return(out)
419+
407420
})
408421
```
409422

@@ -513,3 +526,12 @@ reactableOutput('mngptctab')
513526
output$mngptcmap <- renderLeaflet(mngptcmap())
514527
leafletOutput('mngptcmap', height = lfht)
515528
```
529+
530+
## Potential
531+
532+
```{r, out.height = 600, out.width="100%"}
533+
allsgmapfun()
534+
output$allsgtab <- renderReactable(allsgtab())
535+
reactableOutput('allsgtab')
536+
```
537+

0 commit comments

Comments
 (0)
Please sign in to comment.