Skip to content

Commit 7d62219

Browse files
authored
Merge pull request #37 from JosiahParry/explode
explode lines functio
2 parents c3489b2 + 6a917db commit 7d62219

11 files changed

+264
-87
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export(distance_haversine_pairwise)
3737
export(distance_vicenty_matrix)
3838
export(distance_vicenty_pairwise)
3939
export(expand_geoms)
40+
export(explode_lines)
4041
export(extreme_coords)
4142
export(flatten_geoms)
4243
export(frechet_distance)

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# rsgeo (unreleased)
22

3+
* `explode_lines()` will expand an `rs_LINESTRING` or `rs_MULTILINESTRING` into their component segments
34
* Adds `line_segmentize_haversine()` to segment LineStrings in geographic space.
45
* Adds `geom_line()` to construct a straight line geometry between two point vectors.
56
* Adds `coord_first()`, `coord_last()`, `coord_n()`, and `n_coords()` functions for working with coordinates of geometries.

R/explode.R

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#' Explode Lines
2+
#'
3+
#' Given a LineString or MultiLineString, expand the geometry into each and
4+
#' every component Line.
5+
#'
6+
#' @param x an object of class `rs_LINESTRING` or `rs_MULTILINESTRING`
7+
#' @details
8+
#' A `LineString` is composed of one or more `Line`s. A Line is a connected
9+
#' by a start and end coordinate only.
10+
#'
11+
#' @export
12+
#' @returns an object of class `rs_LINESTRING`
13+
#' @examples
14+
#' x <- geom_linestring(1:10, 10:1)
15+
#' length(x)
16+
#' explode_lines(x)
17+
explode_lines <- function(x) {
18+
if (rlang::inherits_any(x, "rs_LINESTRING")) {
19+
res <- explode_linestrings_(x)
20+
} else if (rlang::inherits_any(x, "rs_MULTILINESTRING")) {
21+
res <- explode_multilinestrings_(x)
22+
} else {
23+
cli::cli_abort("{.arg x} must be of class {.cls rs_LINESTRING} or {.cls rs_MULTILINESTRING")
24+
}
25+
26+
res
27+
}

R/extendr-wrappers.R

+4
Original file line numberDiff line numberDiff line change
@@ -693,5 +693,9 @@ combine_polygons <- function(x) .Call(wrap__combine_polygons, x)
693693

694694
combine_multipolygons <- function(x) .Call(wrap__combine_multipolygons, x)
695695

696+
explode_linestrings_ <- function(x) .Call(wrap__explode_linestrings_, x)
697+
698+
explode_multilinestrings_ <- function(x) .Call(wrap__explode_multilinestrings_, x)
699+
696700

697701
# nolint end

man/explode_lines.Rd

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)