Title: | Constrained Triangulation for Simple Features |
---|---|
Description: | Build a constrained high quality Delaunay triangulation from simple features objects, applying constraints based on input line segments, and triangle properties including maximum area, minimum internal angle. The triangulation code in 'RTriangle' uses the method of Cheng, Dey and Shewchuk (2012, ISBN:9781584887300). For a low-dependency alternative with low-quality path-based constrained triangulation see <https://CRAN.R-project.org/package=decido> and for high-quality configurable triangulation see <https://github.com/hypertidy/anglr>. Also consider comparison with the 'GEOS' lib which since version 3.10.0 includes a low quality polygon triangulation method that starts with ear clipping and refines to Delaunay. |
Authors: | Michael D. Sumner [aut, cre] |
Maintainer: | Michael D. Sumner <[email protected]> |
License: | CC BY-NC-SA 4.0 |
Version: | 0.3.0 |
Built: | 2024-11-04 04:19:41 UTC |
Source: | https://github.com/hypertidy/sfdct |
See data-raw for original source.
library(sf) plot(antarctica, col = rainbow(nrow(antarctica), alpha = 0.4))
library(sf) plot(antarctica, col = rainbow(nrow(antarctica), alpha = 0.4))
Triangulate simple features including the input edges as constraints, rather than being bounded to the convex hull.
ct_triangulate(x, ...) ## S3 method for class 'POINT' ct_triangulate(x, trim = TRUE, ...) ## S3 method for class 'MULTIPOINT' ct_triangulate(x, trim = TRUE, ...) ## S3 method for class 'GEOMETRYCOLLECTION' ct_triangulate(x, trim = TRUE, ...) ## S3 method for class 'sfg' ct_triangulate(x, trim = TRUE, ...) ## S3 method for class 'sfc' ct_triangulate(x, ...) ## S3 method for class 'sf' ct_triangulate(x, trim = TRUE, ...)
ct_triangulate(x, ...) ## S3 method for class 'POINT' ct_triangulate(x, trim = TRUE, ...) ## S3 method for class 'MULTIPOINT' ct_triangulate(x, trim = TRUE, ...) ## S3 method for class 'GEOMETRYCOLLECTION' ct_triangulate(x, trim = TRUE, ...) ## S3 method for class 'sfg' ct_triangulate(x, trim = TRUE, ...) ## S3 method for class 'sfc' ct_triangulate(x, ...) ## S3 method for class 'sf' ct_triangulate(x, trim = TRUE, ...)
x |
simple feature geometry or data frame |
... |
arguments for |
trim |
drop triangles that fall "outside" i.e. "holes" and non-convex regions, |
This is not a Delaunay Triangulation by default, but is "mostly-Delaunay". Use the D = TRUE
option,
passed to the underlying function in RTriangle to ensure the criterion is met, as well as edge constraints.
All POLYGON, LINESTRING, MULTIPOLYGON, and MULTILINESTRING inputs (including those in GEOMETRYCOLLECTION)
are broken down into line segments that are included in the mesh. Holes are removed
by default, but can be retained with the trim
argument.
The triangles are collected as POLYGONs within a GEOMETRYCOLLECTION, and in the case of an sf
object
it's returned within the original input data frame.
There's no way in this package to retain the set of shared vertices, or the segment or the triangle indices. It is a fundamental feature of the standard, that this information is not represented.
Further arguments may be passed down to the underlying triangulation function triangulate
.
Note that planar coordinates are assumed, no matter what projection the input is in. There's no
sensible meaning to a value for a
in units m^2 for a layer that is in longitude/latitude, for those
use "area in square degrees", the straightforward meaning in planar coordinates.
These arguments are, from the documentation of that function:
a Maximum triangle area. If specified, triangles cannot be larger than this area.
Minimum triangle angle in degrees.
If TRUE
prohibits the insertion of Steiner points
on the mesh boundary.
If TRUE
jettisons vertices that are not part of
the final triangulation from the output.
If TRUE
produce a conforming Delaunay
triangulation. This ensures that all the triangles in the mesh are
truly Delaunay, and not merely constrained Delaunay. This option
invokes Ruppert's original algorithm, which splits every
subsegment whose diametral circle is encroached. It usually
increases the number of vertices and triangles.
Specifies the maximum number of added Steiner points.
Verbosity level. Specify higher values for more detailed information about what the Triangle library is doing.
If TRUE
suppresses all explanation of what the
Triangle library is doing, unless an error occurs.
simple feature column st_sfc
or data frame st_sfc
GEOMETRYCOLLECTION as input is not yet supported.
library(sf) nc <- read_sf(system.file("shape/nc.shp", package="sf"), quiet = TRUE) nc_triangles <- ct_triangulate(nc[, c("NAME", "geometry")]) plot(nc[, "NAME"]) plot(nc_triangles, add = TRUE, col = NA, lty = "dotted") idx <- c(4, 5, 6, 7, 8, 20, 21) op <- par(mfrow = c(2, 1)) if (packageVersion("sf") <= '0.2.8'){ nc <- st_transform(nc, "+proj=eqc +ellps=WGS84") } plot(st_triangulate(nc[idx, c("NAME", "geometry")]), col = "grey") ## Warning ct_triangulate does correctly triangulate longitude/latitude data plot(ct_triangulate(nc[idx, c("NAME", "geometry")]))
library(sf) nc <- read_sf(system.file("shape/nc.shp", package="sf"), quiet = TRUE) nc_triangles <- ct_triangulate(nc[, c("NAME", "geometry")]) plot(nc[, "NAME"]) plot(nc_triangles, add = TRUE, col = NA, lty = "dotted") idx <- c(4, 5, 6, 7, 8, 20, 21) op <- par(mfrow = c(2, 1)) if (packageVersion("sf") <= '0.2.8'){ nc <- st_transform(nc, "+proj=eqc +ellps=WGS84") } plot(st_triangulate(nc[idx, c("NAME", "geometry")]), col = "grey") ## Warning ct_triangulate does correctly triangulate longitude/latitude data plot(ct_triangulate(nc[idx, c("NAME", "geometry")]))
maps
package.Data is in sf
form.
See data-raw for original source.