Skip to content

Commit

Permalink
updated transect extensions to polygons to use new intersection logic…
Browse files Browse the repository at this point in the history
…, the same logic used in cs point based extensions, added a single test for this, updated roxygen comments, added a junction_flowlines.gpkg for further testing
  • Loading branch information
anguswg-ucsb committed Nov 14, 2024
1 parent a62a9bf commit 64394c0
Show file tree
Hide file tree
Showing 19 changed files with 1,622 additions and 84 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hydrofabric3D
Title: hydrofabric3D
Version: 0.1.49
Version: 0.1.50
Authors@R: c(person("Mike", "Johnson", role = c("aut", "cre"), email = "[email protected]"),
person("Angus", "Watters", role = "aut"),
person("Arash", "Modaresi", role = "ctb"),
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(add_braid_ids)
export(add_cs_area)
export(add_cs_area2)
export(add_cs_bathymetry)
export(add_is_outlet_flag)
export(add_length_col)
export(add_middle_index_by_point_type)
export(add_point_type_counts)
Expand All @@ -31,13 +32,15 @@ export(extend_by_percent)
export(extend_invalid_transect_sides)
export(extend_invalid_transects)
export(extend_transects_any_side)
export(extend_transects_any_side_by_specific_distances)
export(extend_transects_both_sides)
export(extend_transects_both_sides2)
export(extend_transects_by_cs_attributes)
export(extend_transects_by_distances)
export(extend_transects_by_length)
export(extend_transects_sides)
export(extend_transects_to_polygons)
export(extend_transects_to_polygons2)
export(fill_missing_ahg_coords)
export(find_anchor_pts)
export(find_braids)
Expand Down Expand Up @@ -102,6 +105,7 @@ importFrom(dplyr,n)
importFrom(dplyr,n_distinct)
importFrom(dplyr,relocate)
importFrom(dplyr,rename)
importFrom(dplyr,row_number)
importFrom(dplyr,rowwise)
importFrom(dplyr,select)
importFrom(dplyr,slice)
Expand Down
357 changes: 352 additions & 5 deletions R/transect_extenders_with_network.R

Large diffs are not rendered by default.

55 changes: 51 additions & 4 deletions R/transect_extenders_without_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ shorten_multi_intersecting_transects <- function(x, crosswalk_id = NULL) {
# #
# x$distance_to_shorten
# x <- extended_transects
# x = transect_lines2
# x = extended_transects
# crosswalk_id = crosswalk_id
# message("intersect change2")
Expand Down Expand Up @@ -475,6 +476,7 @@ shorten_multi_intersecting_transects <- function(x, crosswalk_id = NULL) {
dir = "left",
length_col = "cs_lengthm"
)

# shorten the right side
shortened_transects <- adjust_transect_lengths(
x = shortened_transects,
Expand All @@ -483,20 +485,42 @@ shorten_multi_intersecting_transects <- function(x, crosswalk_id = NULL) {
length_col = "cs_lengthm"
)


# mapview::mapview(shortened_transects, color = "red") +
# mapview::mapview(x, color = "green")

# set is_extended to FALSE for clarity
shortened_transects$is_extended <- FALSE
shortened_transects$is_extended <- FALSE
shortened_transects$left_distance <- 0
shortened_transects$right_distance <- 0

if ("left_is_extended" %in% names(shortened_transects)) {
shortened_transects$left_is_extended <- FALSE
}

if ("right_is_extended" %in% names(shortened_transects)) {
shortened_transects$right_is_extended <- FALSE
}


# replace the geometries with the shorter transects
sf::st_geometry(x[is_multi_intersecting, ]) <- sf::st_geometry(shortened_transects)

# update the lengths and is_extended flag to align with the above replacement of geometries
x <- add_length_col(x, "cs_lengthm")

# transects[is_multi_intersecting, ]$cs_lengthm <- shortened_transects$cs_lengthm
x[is_multi_intersecting, ]$is_extended <- shortened_transects$is_extended
# transects[is_multi_intersecting, ]$cs_lengthm <- shortened_transects$cs_lengthm
x[is_multi_intersecting, ]$is_extended <- shortened_transects$is_extended
x[is_multi_intersecting, ]$left_distance <- shortened_transects$left_distance
x[is_multi_intersecting, ]$right_distance <- shortened_transects$right_distance

if ("left_is_extended" %in% names(x)) {
x[is_multi_intersecting, ]$left_is_extended <- shortened_transects$left_is_extended
}

if ("right_is_extended" %in% names(x)) {
x[is_multi_intersecting, ]$right_is_extended <- shortened_transects$right_is_extended
}

return(x)

Expand Down Expand Up @@ -603,7 +627,9 @@ shorten_multi_flowline_intersecting_transects <- function(x,

is_valid_df <- validate_df(x,
c(crosswalk_id, "cs_id", "cs_lengthm",
"is_extended", "left_distance", "right_distance", "extension_distance", "geometry"),
"is_extended", "left_distance", "right_distance",
# "extension_distance",
"geometry"),
"x")

# Try and fix any transects that cross multiple
Expand Down Expand Up @@ -658,6 +684,17 @@ shorten_multi_flowline_intersecting_transects <- function(x,

# set is_extended to FALSE for clarity
shortened_transects$is_extended <- FALSE
shortened_transects$left_distance <- 0
shortened_transects$right_distance <- 0

if ("left_is_extended" %in% names(shortened_transects)) {
shortened_transects$left_is_extended <- FALSE
}

if ("right_is_extended" %in% names(shortened_transects)) {
shortened_transects$right_is_extended <- FALSE
}


# replace the geometries with the shorter transects
sf::st_geometry(x[is_multi_intersecting_flowlines, ]) <- sf::st_geometry(shortened_transects)
Expand All @@ -667,6 +704,16 @@ shorten_multi_flowline_intersecting_transects <- function(x,
x <- add_length_col(x, "cs_lengthm")

x[is_multi_intersecting_flowlines, ]$is_extended <- shortened_transects$is_extended
x[is_multi_intersecting_flowlines, ]$left_distance <- shortened_transects$left_distance
x[is_multi_intersecting_flowlines, ]$right_distance <- shortened_transects$right_distance

if ("left_is_extended" %in% names(x)) {
x[is_multi_intersecting_flowlines, ]$left_is_extended <- shortened_transects$left_is_extended
}

if ("right_is_extended" %in% names(x)) {
x[is_multi_intersecting_flowlines, ]$right_is_extended <- shortened_transects$right_is_extended
}

return(x)

Expand Down
Loading

0 comments on commit 64394c0

Please sign in to comment.