-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsnap_points_to_river.R
More file actions
38 lines (29 loc) · 1.4 KB
/
snap_points_to_river.R
File metadata and controls
38 lines (29 loc) · 1.4 KB
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
#loads flame data and snaps points to river network object
#save flame data with river distance calculations
# library(sf)
# library(riverdist)
# library(dplyr)
# library(tidyverse)
#
# spatial_dir <- "C:/Users/slafond-hudson/DOI/Loken, Luke C - FLAMeIllinois/SpatialData"
# home_path <- "C:/Users/slafond-hudson/DOI/Loken, Luke C - FLAMeIllinois/Data"
# flame_path <- "C:/Users/slafond-hudson/DOI/Loken, Luke C - FLAMeIllinois/Data/Merged_Illinois_Jul_2023/Shapefiles"
# Read in flame data and snap to river network object
# points <- readRDS(file.path(processed_path, "flame_intersected_aqa.rds"))
#
# network_clean <- readRDS(file.path(spatial_dir, "IL_network.rds"))
#transforms from sp object to sf object
snap_points_to_river <- function(points, processed_path, flame_file){
#separate long and lat from geometry column
points <- points%>%
mutate(long = unlist(map(points$geometry,1)),
lat = unlist(map(points$geometry,2)))
#snap flame data points to Illinois River network object
print("starting snap")
print(format(Sys.time()))
snapped_all <- xy2segvert(points$long, points$lat, rivers=network_clean)
points$Dist_m <- unlist(network_clean$cumuldist)[snapped_all$vert]
# points$snapped_dist_m <- unlist(network_clean$cumuldist)[snapped_all$snapdist]
saveRDS(points, file=file.path(processed_path, "2_flame_snapped", paste(date, "_snapped.rds", sep="")))
return(points)
}