From 1f848da3781f30c42025f0c1df4a9bdacf3688a6 Mon Sep 17 00:00:00 2001 From: mikejohnson51 Date: Mon, 18 Nov 2024 21:03:29 -0700 Subject: [PATCH] add st_rename --- NAMESPACE | 1 + R/hydrofabric_io.R | 13 ++++++++++ ...gpkg.Rd => make_hf_gpkg_from_reference.Rd} | 11 +++----- man/st_rename.Rd | 26 +++++++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) rename man/{gpkg.Rd => make_hf_gpkg_from_reference.Rd} (75%) create mode 100644 man/st_rename.Rd diff --git a/NAMESPACE b/NAMESPACE index 7e381a90..64107ba3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -53,6 +53,7 @@ export(refactor_nhdplus) export(sb_id) export(split_catchment_divide) export(split_flowlines) +export(st_rename) export(union_linestrings) export(union_linestrings_geos) export(union_polygons) diff --git a/R/hydrofabric_io.R b/R/hydrofabric_io.R index 86d51884..8d1bcf21 100644 --- a/R/hydrofabric_io.R +++ b/R/hydrofabric_io.R @@ -22,7 +22,20 @@ sb_id = function(type){ return(id) } +#' Rename simple features layer +#' @inheritParams sf::st_write +#' @param new_layer new layer name +#' @return dsn +#' @export +st_rename = function(dsn, layer, new_layer) { + read_sf(dsn, layer) |> + write_sf(dsn, new_layer) + + st_delete(dsn, layer) + + dsn +} #' Check if a geopackage and layer exists #' This function checks if a layer exists in a geopackage diff --git a/man/gpkg.Rd b/man/make_hf_gpkg_from_reference.Rd similarity index 75% rename from man/gpkg.Rd rename to man/make_hf_gpkg_from_reference.Rd index 59921192..b0dc2c97 100644 --- a/man/gpkg.Rd +++ b/man/make_hf_gpkg_from_reference.Rd @@ -1,15 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/make_hf_gpkg_from_other.R -\docType{data} -\name{gpkg} -\alias{gpkg} +\name{make_hf_gpkg_from_reference} +\alias{make_hf_gpkg_from_reference} \title{Convert Reference Output to HF gpkg This is a temporary function as changes get pushed upstream} -\format{ -An object of class \code{character} of length 1. -} \usage{ -gpkg +make_hf_gpkg_from_reference(gpkg) } \arguments{ \item{gpkg}{gpkg file path} @@ -21,4 +17,3 @@ file.path Convert Reference Output to HF gpkg This is a temporary function as changes get pushed upstream } -\keyword{datasets} diff --git a/man/st_rename.Rd b/man/st_rename.Rd new file mode 100644 index 00000000..d5162bfd --- /dev/null +++ b/man/st_rename.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/hydrofabric_io.R +\name{st_rename} +\alias{st_rename} +\title{Rename simple features layer} +\usage{ +st_rename(dsn, layer, new_layer) +} +\arguments{ +\item{dsn}{data source name. Interpretation varies by driver: can be +a filename, a folder, a database name, or a Database Connection +(we officially test support for +\code{\link[RPostgres:Postgres]{RPostgres::Postgres()}} connections).} + +\item{layer}{layer name. Varies by driver, may be a file name without +extension; for database connection, it is the name of the table. If layer +is missing, the \code{basename} of \code{dsn} is taken.} + +\item{new_layer}{new layer name} +} +\value{ +dsn +} +\description{ +Rename simple features layer +}