Skip to content

Commit

Permalink
forced geometry column name instead of geom
Browse files Browse the repository at this point in the history
  • Loading branch information
anguswg-ucsb committed Jul 30, 2024
1 parent 92e8178 commit a1c3224
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 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.0.95
Version: 0.0.96
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
34 changes: 23 additions & 11 deletions R/fema_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ pick_extension_pts <- function(
#' @importFrom geos as_geos_geometry
#' @importFrom wk wk_crs
#' @importFrom sf st_geometry st_as_sf st_length
#' @importFrom nhdplusTools rename_geometry
#' @importFrom dplyr mutate relocate any_of
#' @return transects sf dataframe with extended transect geometries, left and right distance columns, and flags indicating if the transect was extended in the left and/or right directions
#' @export
Expand All @@ -1239,6 +1240,12 @@ extend_transects_by_distances <- function(
# crosswalk_id = "hy_id"
# cs_id = "cs_id"
# grouping_id = 'mainstem'
# transects = transect_lines
# flowlines = flowlines
# crosswalk_id = crosswalk_id
# cs_id = "cs_id"
# grouping_id = grouping_id

# ---------------------------------------

# ----------------------------------------------------------------------------------
Expand Down Expand Up @@ -1497,8 +1504,6 @@ extend_transects_by_distances <- function(

# })



# Update the "transects_to_extend" with new geos geometries ("geos_list")
sf::st_geometry(transects) <- sf::st_geometry(sf::st_as_sf(transects_geos))

Expand All @@ -1510,12 +1515,19 @@ extend_transects_by_distances <- function(
transects$left_is_extended <- left_extended_flag
transects$right_is_extended <- right_extended_flag

message("==========================")
message("Structure of transects object ^^^^^^^", utils::str(transects))
message("==========================")

transects <- nhdplusTools::rename_geometry(transects, "geometry")

message("Structure of transects object AFTER RENAME ^^^^^^^", utils::str(transects))
message("==========================")

transects <-
transects %>%
dplyr::mutate(
cs_lengthm = as.numeric(sf::st_length(geom))
cs_lengthm = as.numeric(sf::st_length(.))
) %>%
dplyr::relocate(
dplyr::any_of(c(crosswalk_id, cs_id)),
Expand Down Expand Up @@ -1560,7 +1572,7 @@ extend_transects_to_polygons2 <- function(
grouping_id = 'mainstem',
max_extension_distance = 3000
) {
# ----------------------------------------------------------
# # ----------------------------------------------------------
# library(sf)
# library(dplyr)
# library(geos)
Expand All @@ -1576,14 +1588,14 @@ extend_transects_to_polygons2 <- function(
# crosswalk_id = "hy_id"
# grouping_id = "mainstem"
# max_extension_distance = 3000
# #
# # mapview::npts(polygons, by_feature = T) %>% sort(decreasing = T) %>% .[1:100]
#
# # # #
# # # # mapview::npts(polygons, by_feature = T) %>% sort(decreasing = T) %>% .[1:100]
# # #
# polygons <- rmapshaper::ms_simplify(polygons, keep_shapes = T, keep = 0.02, sys = TRUE, sys_mem = 16)
# mapview::mapview(polygons, col.regions = "white", color = "green") +
# mapview::mapview(polygons2, col.regions = "white", color = "red")
# mapview::npts(polygons, by_feature = T) %>% sort(decreasing = T) %>% .[1:100]
# mapview::npts(polygons)
# # mapview::mapview(polygons, col.regions = "white", color = "green") +
# # mapview::mapview(polygons2, col.regions = "white", color = "red")
# # mapview::npts(polygons, by_feature = T) %>% sort(decreasing = T) %>% .[1:100]
# # mapview::npts(polygons)

# ----------------------------------------------------------------------------------
# ----------- Input checking ------
Expand Down
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ get_unique_tmp_ids <- function(df, x = hy_id, y = cs_id) {
move_geometry_to_last <- function(df) {
# Check if any of the columns in the dataframe are geometry types
check_for_geom <- sapply(df, function(col) {
any(class(col) %in% c("sfc_POINT", "sfc", "sfc_GEOMETRY", "sfc_MULTIPOINT"))
any(class(col) %in% c("sfc", "sfc_GEOMETRY",
"sfc_POINT", "sfc_MULTIPOINT",
"sfc_LINESTRING", "sfc_MULTILINESTRING",
"sfc_POLYGON", "sfc_MULTIPOLYGON"
))
})

# If there is a geometry type column, move it to the last position
Expand Down

0 comments on commit a1c3224

Please sign in to comment.