View source: R/get_distant_points.R
| get_distant_points | R Documentation |
Identifies the pair of most distant points on a polygon's convex hull and
calculates their distance (using the selected method) and the bearing
from the southernmost to the northernmost point.
get_distant_points(
v,
isHull = FALSE,
distance = TRUE,
bearing = TRUE,
output = "points",
by_feature = FALSE,
method = "geo"
)
v |
A SpatVector object representing a polygon, or a pre-computed convex hull if |
isHull |
Logical. If |
distance |
Logical indicating whether to return the maximum distance
(default |
bearing |
Logical indicating whether to return the bearing (default
|
output |
Character string. |
by_feature |
Logical. If |
method |
Character string passed to |
Distances between all convex-hull vertex pairs are evaluated with
terra::distance() using the selected method, so the returned
pair is the true geodesic maximum (hulls are small, so the exhaustive
search is cheap). An earlier rotating-calipers implementation searched
antipodal pairs in planar coordinate space, which could miss the geodesic
maximum on lon/lat data.
Tie-breaking & Point Ordering: If multiple antipodal pairs share the maximum distance, ties are broken by selecting the pair containing the southernmost (and then westernmost) coordinate. The points are ordered in the output such that:
south_point (point 1): the southernmost (and westernmost, in case of a tie) point of the pair.
north_point (point 2): the northernmost (and easternmost) point of the pair.
The geographic bearing is calculated from south_point to north_point
using geosphere::bearing(). When needed, the geometry is internally
transformed to geographic coordinates for bearing calculation.
For output = "points", a list containing:
south_point |
SpatVector of the southernmost point |
north_point |
SpatVector of the northernmost point |
distance |
Maximum distance in meters (if |
bearing |
Axial orientation: geographic bearing from the southernmost
to the northernmost point, in degrees within [-90, 90] (if
|
For output = "value", returns a numeric scalar when one metric is
requested, or a named numeric vector when both are requested.
For output = "polygon", returns the input geometry with the
requested metric columns added.
When by_feature = TRUE, returns per-feature outputs (list,
numeric vector/data.frame, or polygon with columns, depending on
output).
library(terra)
coords <- cbind(c(0, 0, 1, 1, 0), c(0, 1, 1, 0, 0))
polygon <- vect(coords, type = "polygon", crs = "EPSG:4326")
distant_pts <- get_distant_points(polygon)
# Using a pre-computed convex hull
hull_geom <- terra::hull(polygon, type = "convex")
distant_pts_hull <- get_distant_points(hull_geom, isHull = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.