Learn R Programming

geographiclib (version 0.4.1)

polygon_area_cumulative: Compute cumulative polygon area and perimeter

Description

Compute the area and perimeter of a polygon at each vertex, showing how the measurements accumulate as vertices are added.

Usage

polygon_area_cumulative(x, polyline = FALSE)

Value

A data frame with columns:

  • lon: Longitude of vertex

  • lat: Latitude of vertex

  • area: Cumulative area in square meters up to this vertex

  • perimeter: Cumulative perimeter in meters up to this vertex

Arguments

x

A two-column matrix or data frame of coordinates (longitude, latitude) in decimal degrees defining polygon vertices, or a list with longitude and latitude components.

polyline

Logical. If FALSE (default), compute area and perimeter of a closed polygon. If TRUE, compute only the length of a polyline (area will be meaningless).

Details

This function is useful for understanding how polygon area accumulates and for debugging polygon vertex order issues.

Examples

Run this code
# Watch area accumulate as vertices are added
pts <- cbind(
  lon = c(0, -74, -43, 28),
  lat = c(52, 41, -23, -26)
)
polygon_area_cumulative(pts)

Run the code above in your browser using DataLab