Skip to content

Commit

Permalink
📝 Update document, examples and representing
Browse files Browse the repository at this point in the history
  • Loading branch information
NONONOexe committed Aug 29, 2024
1 parent 86b0af6 commit 0b9bc5c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
12 changes: 6 additions & 6 deletions R/decompose-linestring.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Decompose a linestring into a list of segments
#' Decompose a linestring into a list of line segments
#'
#' This function decomposes a linestring into a list of segments, where each
#' segment is a linestring connecting two consecutive points of the input
#' linestring.
#' This function decomposes a linestring into a list of line segments,
#' where each segment is a linestring connecting two consecutive points
#' of the input linestring.
#'
#' @param linestring A linestring object.
#' @return A list of linestring objects, each representing a segment of the
Expand All @@ -12,7 +12,7 @@
#' # Create a linestring object
#' linestring <- create_linestring(0, 0, 1, 1, 2, 1, 4, 0)
#'
#' # Decompose the linestring into segments
#' # Decompose the linestring into line segments
#' decompose_linestring(linestring)
decompose_linestring <- function(linestring) {
# Extract the coordinates of the linestring
Expand All @@ -23,7 +23,7 @@ decompose_linestring <- function(linestring) {
from <- coordinates[seq_len(num_points - 1), c("X", "Y")]
to <- coordinates[seq_len(num_points - 1) + 1, c("X", "Y")]

# Create a list of segments
# Create a list of line segments
segments <- apply(cbind(from, to), 1, create_linestring, simplify = FALSE)
segments <- st_sfc(segments, crs = st_crs(linestring))

Expand Down
21 changes: 10 additions & 11 deletions R/filter-points-within-tolerance.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
#'
#' @param points A `sfc` object containing points to filter.
#' @param linestring A linestring object.
#' @param tolerance The maximum distance allowed between points and
#' the linestring. Points within this distance from the linestring
#' are kept in the result.
#' @param tolerance A numeric value representing the maximum allowable
#' distance between points and the linestring. Points within this
#' distance from the linestring will be included in the filtered set.
#' @return A `sfc` object containing the filtered points.
#' @export
#' @examples
#' library(sf)
#'
#' # Create a points
#' points <- st_sfc(
#' st_point(c(0.000, 0.000)),
#' st_point(c(1.000, 0.100)),
#' st_point(c(2.000, 0.010)),
#' st_point(c(4.000, 0.001)),
#' st_point(c(5.001, 0.000)),
#' st_point(c(6.000, 0.000))
#' st_point(c(0.000, 1.000)),
#' st_point(c(0.500, 0.600)),
#' st_point(c(1.000, 0.010)),
#' st_point(c(1.500, 0.501)),
#' st_point(c(2.000, 0.990))
#' )
#'
#' # Create a linestring (reference geometry)
#' linestring <- create_linestring(0, 0, 5, 0)
#' # Create a linestring
#' linestring <- create_linestring(0, 1, 1, 0, 2, 1)
#'
#' # Plot the points
#' plot(linestring, col = "gray")
Expand Down
10 changes: 5 additions & 5 deletions man/decompose_linestring.Rd

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

21 changes: 10 additions & 11 deletions man/filter_points_within_tolerance.Rd

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

0 comments on commit 0b9bc5c

Please sign in to comment.