Skip to contents

shapefile_measures() calculates key geometric measures such as the number of points, area, perimeter, width, height, and centroid coordinates for a given shapefile (polygon) object.

Usage

shapefile_measures(shapefile, n = NULL)

Arguments

shapefile

An sf object representing the shapefile. It should contain polygonal geometries for which the measures will be calculated.

n

An integer specifying the number of polygons to process. If NULL, all polygons are considered.

Value

A modified sf object with added columns for:

  • xcoord: The x-coordinate of the centroid.

  • ycoord: The y-coordinate of the centroid.

  • area: The area of the polygon (in square units).

  • perimeter: The perimeter of the polygon (in linear units).

  • width: The calculated width based on sequential distances between points. The result will only be accurate if the polygon is rectangular.

  • height: The calculated height based on sequential distances between points. The result will only be accurate if the polygon is rectangular.

Details

This function processes a single or multi-polygon sf object and computes geometric properties. It calculates distances between points, extracts the centroid coordinates, and computes the area and perimeter of the polygons. The width and height are derived from sequential distances between points.

Examples

if (interactive() && requireNamespace("EBImage")) {
library(pliman)

path_shp <- paste0(image_pliman(), "/soy_shape.rds")
shp <- shapefile_input(path_shp)
shapefile_measures(shp)
}