Skip to content

Commit

Permalink
Updated fpr_dbq_clip NewGraphEnvironment#58, updated fpr_create_hydro…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucy-schick committed Mar 13, 2024
1 parent fbe62fc commit 97f9cb6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 48 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export("%>%")
export(fpr_appendix_title)
export(fpr_create_hydrograph_local)
export(fpr_create_hydrograph)
export(fpr_dat_w_rows)
export(fpr_db_conn)
export(fpr_db_query)
Expand Down
4 changes: 2 additions & 2 deletions R/fpr_create_hydrograph.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Creates hydrographs
#' Creates hydrograph and hydrology stats figures for a given station.
#'
#' @param station String (quoted) number of station
#' @param pane_hydat Boolean TRUE if you want a pane layout of all hydrographs
Expand Down Expand Up @@ -106,7 +106,7 @@ fpr_create_hydrograph <- function(
daily_sd = sd(Value, na.rm = TRUE),
max = max(Value, na.rm = TRUE),
min = min(Value, na.rm = TRUE)) %>%
dplyr::mutate(Date = as.Date(day_of_year, origin = "2015-12-31"))
dplyr::mutate(Date = as.Date(day_of_year))

plot <- ggplot2::ggplot()+
ggplot2::geom_ribbon(data = flow, aes(x = Date, ymax = max,
Expand Down
40 changes: 40 additions & 0 deletions R/fpr_dbq_clip.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Clips a point layer by a polygon layer, and returns the clipped point layer containing user specified columns.
#'
#' @param schtab_pnt String (quoted) name of point layer schema.table.
#' @param schtab_pol String (quoted) name of polygon layer schema.table.
#' @param join_column String (quoted) name of column to join tables on from polygon. See column names of any table with \link{fpr_dbq_lscols}.
#' @param schtab_pol_filter String (quoted) or quoted comma seperated vector that defines how the polygon table is filtered, example c("FRAN", "NECR").
#' @param cols_schtab_pnt String (quoted) or list of column names to select from point layer, default is all columns (*). Must include the geom column if user wants an sf object.
#'
#' @importFrom glue glue
#' @importFrom chk chk_string
#' @family database postgres
#' @return Sf of clipped point layer
#' @export
#'
#' @examples \dontrun{fpr_db_query(query = fpr_dbq_clip('whse_environmental_monitoring.envcan_hydrometric_stn_sp',
#''whse_basemapping.fwa_watershed_groups_poly', 'watershed_group_code', c("FRAN", "NECR")))}


fpr_dbq_clip <- function(
schtab_pnt = NULL,
schtab_pol = NULL,
join_column = NULL,
schtab_pol_filter = NULL,
cols_schtab_pnt = '*') {

chk::chk_string(schtab_pnt)
chk::chk_string(schtab_pol)
chk::chk_string(join_column)

join_on_str <- paste0("'", schtab_pol_filter, "'", collapse = ", ")
cols_schtab_pnt_str <- paste0("point.", cols_schtab_pnt, collapse = ", ")

glue::glue("SELECT {cols_schtab_pnt_str}, poly.{join_column}
FROM {schtab_pnt} point
INNER JOIN {schtab_pol} poly
ON ST_Intersects(poly.geom, point.geom)
WHERE poly.{join_column} IN ({join_on_str});")

}

32 changes: 0 additions & 32 deletions R/tfpr_dbq_clip.R

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions man/fpr_dbq_clip.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 97f9cb6

Please sign in to comment.