Package io.fleetcoreplatform.Health
Class PolygonUtils
java.lang.Object
io.fleetcoreplatform.Health.PolygonUtils
Utility functions for spatial operations and geometric calculations on PostGIS geometries.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecalculatePolygonArea(org.postgis.Geometry polygon) Computes the absolute enclosed area of a polygon using the Shoelace formula.static doubledot(double[] a, double[] b) Computes the dot product of two arrays representing vector components.static XYArraysextractXY(org.postgis.Geometry polygon) Deconstructs a geometry into separate coordinate arrays for X and Y components.static PolygonBoundingBoxgetBoundingBox(org.postgis.Geometry polygon) Determines the tightest axis-aligned bounding box that fully encompasses the given polygon.static double[]roll(double[] arr) Performs a circular right-shift on the elements of a double array.
-
Constructor Details
-
PolygonUtils
public PolygonUtils()
-
-
Method Details
-
dot
public static double dot(double[] a, double[] b) Computes the dot product of two arrays representing vector components.- Parameters:
a- The first array of components.b- The second array of components.- Returns:
- The scalar dot product.
-
roll
public static double[] roll(double[] arr) Performs a circular right-shift on the elements of a double array. The last element wraps around to become the first element.- Parameters:
arr- The array to roll.- Returns:
- A new array containing the shifted elements.
-
extractXY
Deconstructs a geometry into separate coordinate arrays for X and Y components. Useful for vectorized math operations like Shoelace formula area calculations.- Parameters:
polygon- The source geometry to unpack.- Returns:
- An
XYArraysobject containing the isolated X and Y arrays.
-
calculatePolygonArea
public static double calculatePolygonArea(org.postgis.Geometry polygon) Computes the absolute enclosed area of a polygon using the Shoelace formula. Returns 0 for degenerate polygons (less than 3 vertices).- Parameters:
polygon- The geometry to measure.- Returns:
- The calculated area in square coordinate units.
-
getBoundingBox
Determines the tightest axis-aligned bounding box that fully encompasses the given polygon.- Parameters:
polygon- The geometry to bound.- Returns:
- A
PolygonBoundingBoxrepresenting the extents. - Throws:
NoSuchElementException- If the polygon contains no vertices.
-