Combine

Load packages

library(tidyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:kableExtra':
## 
##     group_rows
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

3.0.1 Gather metrics

# Canopy
load("3_pipeline/store/can_poly_cov.rData")

# UPLVI
load("3_pipeline/store/UPLVI_class_cov.rData")

# Total length of roads
load("3_pipeline/store/road_tot.rData")

# Proportion of pinch point within 50m to a road
load("3_pipeline/store/prop_Road.rData")

# Total length of trails
load("3_pipeline/store/trail_tot.rData")

# Proportion of pinch point within 50m to a trail
load("3_pipeline/store/prop_trail.rData")

#extracted raster data
load("3_pipeline/store/pp_r.rData")

load("3_pipeline/tmp/pp_s_clip_clus.rData")


load("1_data/manual/pp_s_clip.rData")

Reformat data frames

can_poly_cov2<-
    can_poly_cov%>% 
    dplyr::select(-c(3)) %>% 
    spread(key=Class, value=proportion)%>%
    rename("Shrub_Dec"="Shrub-Dec", "Tree_Con"="Tree-Con", "Tree_Dec"="Tree-Dec", "ID"="group")

UPLVI_PRIMECLAS<-spread(UPLVI_class_cov$PRIMECLAS[-c(3)], PRIMECLAS, t_proportion)
UPLVI_LANDCLAS<-spread(UPLVI_class_cov$LANDCLAS[-c(3)], LANDCLAS, t_proportion)
UPLVI_STYPE<-spread(UPLVI_class_cov$STYPE[-c(3)], STYPE, t_proportion)

prop_Road<-prop_Road %>% 
  rename("r_proportion"="proportion") 

prop_trail<- prop_trail %>% 
  rename("t_proportion"="proportion") %>% 
  dplyr::select(-c("pp_area"))

prop_Road<-prop_Road%>%
  rename("ID"="group")

prop_trail<-prop_trail%>%
  rename("ID"="group")

trail_tot<-as.data.frame(trail_tot)%>%
  rename("ID"="group")%>%
  dplyr::select(-c(5:7))

road_tot<-as.data.frame(road_tot)%>%
  rename("ID"="group")%>%
  dplyr::select(-c(5:7))

pp_metrics<-can_poly_cov2%>%
  left_join(UPLVI_PRIMECLAS)%>%
  left_join(UPLVI_LANDCLAS)%>%
  left_join(UPLVI_STYPE)%>%
  left_join(prop_Road)%>%
  left_join(road_tot)%>%
  left_join(prop_trail)%>%
  left_join(trail_tot)

save(pp_metrics, file="1_data/manual/pp_metrics.rData")

pp_all_clus_metrics<-left_join(pp_all_clus, pp_metrics)


# change crs to wgs for shiny app
pp_all_clus_metrics_wgs<-st_transform(pp_all_clus_metrics, crs ="+proj=longlat +datum=WGS84")
save(pp_all_clus_metrics_wgs, file="1_data/manual/pp_all_clus_metrics_wgs.rdata")




# filter out polygons based on minimum area
## set min area (m^2)
m<-5000

library(units) #use this package to convert the threshold value to a units object
m=set_units(m, m^2)
f<-pp_all_clus$area>m
pp_all_clus_minArea=pp_all_clus[f,]

save(pp_all_clus_minArea, file="3_pipeline/store/pp_all_clus_minArea.rData")