Honestly, I use developing this package as a way to learn about spatial indices by decomposing their formulas and explaining to myself how they work while writing the documentation.
geomattR provides a comprehensive toolkit for
calculating geometric and morphometric attributes of spatial polygons.
It computes area, perimeter, compactness, elongation, orientation,
fractal dimension, and various shape indices.
This package is particularly useful for: - Geospatial analysts analyzing shape and size of geographic features - Urban planners characterizing building and neighborhood geometry - Environmental scientists studying habitat patch metrics - Remote sensing practitioners extracting morphological features from vector data - Landscape ecologists quantifying landscape structure - Political scientists examining electoral district shapes - Epidemiologists analyzing spatial spread patterns
Core spatial calculations use the terra package
for efficient spatial data handling and geodesic measurement support,
while geosphere
is used for bearing estimation when a metric requires geographic
coordinates. Distance- and area-based metrics are computed, and shape
indices are derived from those quantities.
Install from GitHub:
# Install devtools if needed
# install.packages("devtools")
devtools::install_github("gortegasolis/geomattR")library(geomattR)
library(terra)
# Create a sample polygon (WGS84 - geographic CRS)
coords <- cbind(c(0, 0, 1, 1, 0), c(0, 1, 1, 0, 0))
polygon <- vect(coords, type = "polygon", crs = "EPSG:4326")
# Calculate all geometric attributes (uses geodesic measurements automatically)
result <- calculate_geometric_attributes(polygon)
# View results
print(result)
# Calculate only specific metrics
result_subset <- calculate_geometric_attributes(
polygon,
metrics = c("area", "perimeter", "compactness", "bearing")
)geomattR prioritizes geodesic calculations by default
(method = "geo"), which makes the metrics suitable for
continental or global scale studies. haversine and
cosine are also supported as faster (but less precise)
great-circle approximations. All three methods are lon/lat great-circle
methods; if the input has a projected CRS,
terra::distance() ignores method and computes
Cartesian distances instead. For methods that need geographic
coordinates, the package will transform the geometry to WGS84 internally
and then restore the output geometry to the original CRS when
applicable.
Area, perimeter, extent, maximum distance, and bearing are computed
according to the selected method. Derived shape indices (for example
compactness, sinuosity, and fractaldimension) are calculated from those
base quantities. For details on the methods geo,
haversine and cosine, please refer to the
documentation of the terra
package.
Full documentation is available in R:
?calculate_geometric_attributes
?get_distant_points
?calc_elongationIf you use geomattR in your research, please cite also
terra and geosphere:
citation("geomattR")MIT License - see LICENSE file for details
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
Gabriel Ortega-Solís (g.ortega.solis@gmail.com) ORCID: 0000-0002-0516-5694
This package began as a side project during my time as a technician on BEAST – BiodivErsity dynamics Across a continuum of Space, Time, and their scales, led by Petr Keil, and was therefore partially funded by the European Union (ERC, BEAST, grant no. 101044740). Views and opinions expressed are those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Council Executive Agency; neither the European Union nor the granting authority can be held responsible for them.
Discussions with P. Keil on spatial and geometric problems inspired the package. G. Ortega-Solís developed all core functions; Claude Code was used to double-check the code and to help write unit tests.