From 1cc62fb74467abe47441c13ec4536632b79bb0d8 Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 21 Dec 2023 10:03:31 +0100 Subject: [PATCH] fixes #2291 --- NAMESPACE | 4 ++-- NEWS.md | 2 +- R/RcppExports.R | 8 ++++---- R/geom-measures.R | 13 +++++++------ R/geom-transformers.R | 11 ++++++----- man/st_project_point.Rd | 32 -------------------------------- src/RcppExports.cpp | 20 ++++++++++---------- src/geos.cpp | 4 ++-- 8 files changed, 32 insertions(+), 62 deletions(-) delete mode 100644 man/st_project_point.Rd diff --git a/NAMESPACE b/NAMESPACE index 5fc2bb617..0ccba950d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -449,7 +449,6 @@ export(st_geometrycollection) export(st_graticule) export(st_inscribed_circle) export(st_interpolate_aw) -export(st_interpolate_line) export(st_intersection) export(st_intersects) export(st_is) @@ -462,7 +461,9 @@ export(st_jitter) export(st_join) export(st_layers) export(st_length) +export(st_line_interpolate) export(st_line_merge) +export(st_line_project) export(st_line_sample) export(st_linestring) export(st_m_range) @@ -483,7 +484,6 @@ export(st_point_on_surface) export(st_polygon) export(st_polygonize) export(st_precision) -export(st_project_point) export(st_read) export(st_read_db) export(st_relate) diff --git a/NEWS.md b/NEWS.md index fae52f32d..973cb336d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # version 1.0-16 -* add `st_project_point()` to find how far a point is when projected on a line, and `st_interpolate_line()` to obtain a point along a line; #2291 +* add `st_line_project()` to find how far a point is when projected on a line, and `st_line_interpolate()` to obtain a point at a certain distance along a line; #2291 # version 1.0-15 diff --git a/R/RcppExports.R b/R/RcppExports.R index bc2c7a83e..a50a414b3 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -257,12 +257,12 @@ CPL_nary_intersection <- function(sfc) { .Call(`_sf_CPL_nary_intersection`, sfc) } -CPL_project_point <- function(lines, points, normalized) { - .Call(`_sf_CPL_project_point`, lines, points, normalized) +CPL_line_project <- function(lines, points, normalized) { + .Call(`_sf_CPL_line_project`, lines, points, normalized) } -CPL_interpolate_line <- function(lines, dists, normalized) { - .Call(`_sf_CPL_interpolate_line`, lines, dists, normalized) +CPL_line_interpolate <- function(lines, dists, normalized) { + .Call(`_sf_CPL_line_interpolate`, lines, dists, normalized) } CPL_hex_to_raw <- function(cx) { diff --git a/R/geom-measures.R b/R/geom-measures.R index b6a4f4662..97f22e5ce 100644 --- a/R/geom-measures.R +++ b/R/geom-measures.R @@ -240,14 +240,15 @@ recycle_common = function (dots) { #' @param line object of class `sfc` with `LINESTRING` geometry #' @param point object of class `sfc` with `POINT` geometry #' @param normalized logical; if `TRUE`, use or return distance normalised to 0-1 -#' @name st_project_point +#' @name st_line_project_point +#' @returns `st_line_project` returns the distance(s) of point(s) along line(s), when projected on the line(s) #' @export #' @details -#' arguments `line`, `point` and `dist` are recycled as needed +#' arguments `line`, `point` and `dist` are recycled to common length when needed #' @examples -#' st_project_point(st_as_sfc("LINESTRING (0 0, 10 10)"), st_as_sfc(c("POINT (0 0)", "POINT (5 5)"))) -#' st_project_point(st_as_sfc("LINESTRING (0 0, 10 10)"), st_as_sfc("POINT (5 5)"), TRUE) -st_project_point = function(line, point, normalized = FALSE) { +#' st_line_project(st_as_sfc("LINESTRING (0 0, 10 10)"), st_as_sfc(c("POINT (0 0)", "POINT (5 5)"))) +#' st_line_project(st_as_sfc("LINESTRING (0 0, 10 10)"), st_as_sfc("POINT (5 5)"), TRUE) +st_line_project = function(line, point, normalized = FALSE) { stopifnot(inherits(line, "sfc"), inherits(point, "sfc"), all(st_dimension(line) == 1), all(st_dimension(point) == 0), is.logical(normalized), length(normalized) == 1, @@ -257,5 +258,5 @@ st_project_point = function(line, point, normalized = FALSE) { if (isTRUE(st_is_longlat(line))) message_longlat("st_project_point") recycled = recycle_common(list(line, point)) - CPL_project_point(recycled[[1]], recycled[[2]], normalized) + CPL_line_project(recycled[[1]], recycled[[2]], normalized) } diff --git a/R/geom-transformers.R b/R/geom-transformers.R index 0d1a748c7..c3066dcbd 100644 --- a/R/geom-transformers.R +++ b/R/geom-transformers.R @@ -1123,12 +1123,13 @@ st_line_sample = function(x, n, density, type = "regular", sample = NULL) { } #nocov end #' @param dist numeric, vector with distance value(s) -#' @name st_project_point +#' @name st_line_project_point +#' @returns `st_line_interpolate` returns the point(s) at dist(s), when measured along (interpolated on) the line(s) #' @export #' @examples -#' st_interpolate_line(st_as_sfc("LINESTRING (0 0, 1 1)"), 1) -#' st_interpolate_line(st_as_sfc("LINESTRING (0 0, 1 1)"), 1, TRUE) -st_interpolate_line = function(line, dist, normalized = FALSE) { +#' st_line_interpolate(st_as_sfc("LINESTRING (0 0, 1 1)"), 1) +#' st_line_interpolate(st_as_sfc("LINESTRING (0 0, 1 1)"), 1, TRUE) +st_line_interpolate = function(line, dist, normalized = FALSE) { stopifnot(inherits(line, "sfc"), all(st_dimension(line) == 1), is.logical(normalized), length(normalized) == 1, is.numeric(dist)) @@ -1136,6 +1137,6 @@ st_interpolate_line = function(line, dist, normalized = FALSE) { message_longlat("st_project_point") line = st_cast(line, "LINESTRING") recycled = recycle_common(list(line, dist)) - st_sfc(CPL_interpolate_line(recycled[[1]], recycled[[2]], normalized), + st_sfc(CPL_line_interpolate(recycled[[1]], recycled[[2]], normalized), crs = st_crs(line)) } diff --git a/man/st_project_point.Rd b/man/st_project_point.Rd deleted file mode 100644 index edfbfe5ec..000000000 --- a/man/st_project_point.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/geom-measures.R, R/geom-transformers.R -\name{st_project_point} -\alias{st_project_point} -\alias{st_interpolate_line} -\title{Project point on linestring, interpolate along a linestring} -\usage{ -st_project_point(line, point, normalized = FALSE) - -st_interpolate_line(line, dist, normalized = FALSE) -} -\arguments{ -\item{line}{object of class \code{sfc} with \code{LINESTRING} geometry} - -\item{point}{object of class \code{sfc} with \code{POINT} geometry} - -\item{normalized}{logical; if \code{TRUE}, use or return distance normalised to 0-1} - -\item{dist}{numeric, vector with distance value(s)} -} -\description{ -Project point on linestring, interpolate along a linestring -} -\details{ -arguments \code{line}, \code{point} and \code{dist} are recycled as needed -} -\examples{ -st_project_point(st_as_sfc("LINESTRING (0 0, 10 10)"), st_as_sfc(c("POINT (0 0)", "POINT (5 5)"))) -st_project_point(st_as_sfc("LINESTRING (0 0, 10 10)"), st_as_sfc("POINT (5 5)"), TRUE) -st_interpolate_line(st_as_sfc("LINESTRING (0 0, 1 1)"), 1) -st_interpolate_line(st_as_sfc("LINESTRING (0 0, 1 1)"), 1, TRUE) -} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 25ea79456..33082aa47 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -880,29 +880,29 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// CPL_project_point -Rcpp::NumericVector CPL_project_point(Rcpp::List lines, Rcpp::List points, bool normalized); -RcppExport SEXP _sf_CPL_project_point(SEXP linesSEXP, SEXP pointsSEXP, SEXP normalizedSEXP) { +// CPL_line_project +Rcpp::NumericVector CPL_line_project(Rcpp::List lines, Rcpp::List points, bool normalized); +RcppExport SEXP _sf_CPL_line_project(SEXP linesSEXP, SEXP pointsSEXP, SEXP normalizedSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< Rcpp::List >::type lines(linesSEXP); Rcpp::traits::input_parameter< Rcpp::List >::type points(pointsSEXP); Rcpp::traits::input_parameter< bool >::type normalized(normalizedSEXP); - rcpp_result_gen = Rcpp::wrap(CPL_project_point(lines, points, normalized)); + rcpp_result_gen = Rcpp::wrap(CPL_line_project(lines, points, normalized)); return rcpp_result_gen; END_RCPP } -// CPL_interpolate_line -Rcpp::List CPL_interpolate_line(Rcpp::List lines, Rcpp::NumericVector dists, bool normalized); -RcppExport SEXP _sf_CPL_interpolate_line(SEXP linesSEXP, SEXP distsSEXP, SEXP normalizedSEXP) { +// CPL_line_interpolate +Rcpp::List CPL_line_interpolate(Rcpp::List lines, Rcpp::NumericVector dists, bool normalized); +RcppExport SEXP _sf_CPL_line_interpolate(SEXP linesSEXP, SEXP distsSEXP, SEXP normalizedSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< Rcpp::List >::type lines(linesSEXP); Rcpp::traits::input_parameter< Rcpp::NumericVector >::type dists(distsSEXP); Rcpp::traits::input_parameter< bool >::type normalized(normalizedSEXP); - rcpp_result_gen = Rcpp::wrap(CPL_interpolate_line(lines, dists, normalized)); + rcpp_result_gen = Rcpp::wrap(CPL_line_interpolate(lines, dists, normalized)); return rcpp_result_gen; END_RCPP } @@ -1526,8 +1526,8 @@ static const R_CallMethodDef CallEntries[] = { {"_sf_CPL_transpose_sparse_incidence", (DL_FUNC) &_sf_CPL_transpose_sparse_incidence, 2}, {"_sf_CPL_nary_difference", (DL_FUNC) &_sf_CPL_nary_difference, 1}, {"_sf_CPL_nary_intersection", (DL_FUNC) &_sf_CPL_nary_intersection, 1}, - {"_sf_CPL_project_point", (DL_FUNC) &_sf_CPL_project_point, 3}, - {"_sf_CPL_interpolate_line", (DL_FUNC) &_sf_CPL_interpolate_line, 3}, + {"_sf_CPL_line_project", (DL_FUNC) &_sf_CPL_line_project, 3}, + {"_sf_CPL_line_interpolate", (DL_FUNC) &_sf_CPL_line_interpolate, 3}, {"_sf_CPL_hex_to_raw", (DL_FUNC) &_sf_CPL_hex_to_raw, 1}, {"_sf_CPL_raw_to_hex", (DL_FUNC) &_sf_CPL_raw_to_hex, 1}, {"_sf_CPL_read_mdim", (DL_FUNC) &_sf_CPL_read_mdim, 8}, diff --git a/src/geos.cpp b/src/geos.cpp index d03f34406..703cf1d6a 100644 --- a/src/geos.cpp +++ b/src/geos.cpp @@ -1378,7 +1378,7 @@ Rcpp::List CPL_nary_intersection(Rcpp::List sfc) { } // [[Rcpp::export]] -Rcpp::NumericVector CPL_project_point(Rcpp::List lines, Rcpp::List points, bool normalized) { +Rcpp::NumericVector CPL_line_project(Rcpp::List lines, Rcpp::List points, bool normalized) { GEOSContextHandle_t hGEOSCtxt = CPL_geos_init(); int dim = 2; std::vector l = geometries_from_sfc(hGEOSCtxt, lines, &dim); @@ -1397,7 +1397,7 @@ Rcpp::NumericVector CPL_project_point(Rcpp::List lines, Rcpp::List points, bool } // [[Rcpp::export]] -Rcpp::List CPL_interpolate_line(Rcpp::List lines, Rcpp::NumericVector dists, bool normalized) { +Rcpp::List CPL_line_interpolate(Rcpp::List lines, Rcpp::NumericVector dists, bool normalized) { GEOSContextHandle_t hGEOSCtxt = CPL_geos_init(); int dim = 2; std::vector l = geometries_from_sfc(hGEOSCtxt, lines, &dim);