Class PolygonUtils

java.lang.Object
io.fleetcoreplatform.Health.PolygonUtils

public class PolygonUtils extends Object
Utility functions for spatial operations and geometric calculations on PostGIS geometries.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    calculatePolygonArea(org.postgis.Geometry polygon)
    Computes the absolute enclosed area of a polygon using the Shoelace formula.
    static double
    dot(double[] a, double[] b)
    Computes the dot product of two arrays representing vector components.
    static XYArrays
    extractXY(org.postgis.Geometry polygon)
    Deconstructs a geometry into separate coordinate arrays for X and Y components.
    getBoundingBox(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static XYArrays extractXY(org.postgis.Geometry polygon)
      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 XYArrays object 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

      public static PolygonBoundingBox getBoundingBox(org.postgis.Geometry polygon)
      Determines the tightest axis-aligned bounding box that fully encompasses the given polygon.
      Parameters:
      polygon - The geometry to bound.
      Returns:
      A PolygonBoundingBox representing the extents.
      Throws:
      NoSuchElementException - If the polygon contains no vertices.