Extract geometric measures from a shapefile object
Source:R/utils_shapefile.R
shapefile_measures.Rd
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.
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.height
: The calculated height based on sequential distances between points.
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)
}
#> class : SpatVector
#> geometry : polygons
#> dimensions : 15, 5 (geometries, attributes)
#> extent : 734337.5, 734348.6, 4489013, 4489017 (xmin, xmax, ymin, ymax)
#> coord. ref. : WGS 72BE / UTM zone 14N (EPSG:32414)
#> names : unique_id block plot_id row column
#> type : <int> <chr> <chr> <int> <int>
#> values : 1 B01 P0001 1 1
#> 2 B01 P0006 2 1
#> 3 B01 P0007 3 1
#> Simple feature collection with 15 features and 11 fields
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: 734337.5 ymin: 4489013 xmax: 734348.6 ymax: 4489017
#> Projected CRS: WGS 72BE / UTM zone 14N
#> First 10 features:
#> unique_id block plot_id row column xcoord ycoord area perimeter width height
#> 1 1 B01 P0001 1 1 734339.3 4489016 2.885558 8.895713 3.659 0.789
#> 2 2 B01 P0006 2 1 734339.4 4489016 2.885558 8.895713 3.659 0.789
#> 3 3 B01 P0007 3 1 734339.4 4489015 2.885558 8.895713 3.659 0.789
#> 4 4 B01 P0012 4 1 734339.4 4489014 2.885558 8.895713 3.659 0.789
#> 5 5 B01 P0013 5 1 734339.5 4489013 2.885558 8.895713 3.659 0.789
#> 6 6 B01 P0002 1 2 734343.0 4489016 2.885558 8.895713 3.659 0.789
#> 7 7 B01 P0005 2 2 734343.0 4489016 2.885558 8.895713 3.659 0.789
#> 8 8 B01 P0008 3 2 734343.1 4489015 2.885558 8.895713 3.659 0.789
#> 9 9 B01 P0011 4 2 734343.1 4489014 2.885558 8.895713 3.659 0.789
#> 10 10 B01 P0014 5 2 734343.1 4489013 2.885558 8.895713 3.659 0.789
#> geometry
#> 1 POLYGON ((734337.5 4489017,...
#> 2 POLYGON ((734337.5 4489016,...
#> 3 POLYGON ((734337.6 4489015,...
#> 4 POLYGON ((734337.6 4489014,...
#> 5 POLYGON ((734337.6 4489014,...
#> 6 POLYGON ((734341.2 4489017,...
#> 7 POLYGON ((734341.2 4489016,...
#> 8 POLYGON ((734341.2 4489015,...
#> 9 POLYGON ((734341.3 4489014,...
#> 10 POLYGON ((734341.3 4489014,...