Class CoordinateUtils


  • public final class CoordinateUtils
    extends Object
    Useful methods for JTS Coordinates.
    Author:
    Erwan Bocher
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean contains2D​(org.locationtech.jts.geom.Coordinate[] coords, org.locationtech.jts.geom.Coordinate coord)
      Checks if a coordinate array contains a specific coordinate.
      static double interpolate​(org.locationtech.jts.geom.Coordinate firstCoordinate, org.locationtech.jts.geom.Coordinate lastCoordinate, org.locationtech.jts.geom.Coordinate toBeInterpolated)
      Interpolates a z value (linearly) between the two coordinates.
      static org.locationtech.jts.geom.Coordinate[] removeDuplicatedCoordinates​(org.locationtech.jts.geom.Coordinate[] coords, boolean closeRing)
      Remove dupliacted coordinates Note : This method doesn't preserve the topology of geometry
      static org.locationtech.jts.geom.Coordinate[] removeRepeatedCoordinates​(org.locationtech.jts.geom.Coordinate[] coords, double tolerance, boolean duplicateFirstLast)
      Remove repeated coordinates according a given tolerance
      static double round​(double value, int places)
      Round a double value according a number of decimal places
      static org.locationtech.jts.geom.Coordinate vectorIntersection​(org.locationtech.jts.geom.Coordinate p1, org.locationtech.jts.math.Vector3D v1, org.locationtech.jts.geom.Coordinate p2, org.locationtech.jts.math.Vector3D v2)
      Compute intersection point of two vectors
      static double[] zMinMax​(org.locationtech.jts.geom.Coordinate[] cs)
      Determine the min and max "z" values in an array of Coordinates.
    • Method Detail

      • zMinMax

        public static double[] zMinMax​(org.locationtech.jts.geom.Coordinate[] cs)
        Determine the min and max "z" values in an array of Coordinates.
        Parameters:
        cs - The array to search.
        Returns:
        An array of size 2, index 0 is min, index 1 is max.
      • interpolate

        public static double interpolate​(org.locationtech.jts.geom.Coordinate firstCoordinate,
                                         org.locationtech.jts.geom.Coordinate lastCoordinate,
                                         org.locationtech.jts.geom.Coordinate toBeInterpolated)
        Interpolates a z value (linearly) between the two coordinates.
        Parameters:
        firstCoordinate -
        lastCoordinate -
        toBeInterpolated -
        Returns:
      • contains2D

        public static boolean contains2D​(org.locationtech.jts.geom.Coordinate[] coords,
                                         org.locationtech.jts.geom.Coordinate coord)
        Checks if a coordinate array contains a specific coordinate. The equality is done only in 2D (z values are not checked).
        Parameters:
        coords -
        coord -
        Returns:
      • vectorIntersection

        public static org.locationtech.jts.geom.Coordinate vectorIntersection​(org.locationtech.jts.geom.Coordinate p1,
                                                                              org.locationtech.jts.math.Vector3D v1,
                                                                              org.locationtech.jts.geom.Coordinate p2,
                                                                              org.locationtech.jts.math.Vector3D v2)
        Compute intersection point of two vectors
        Parameters:
        p1 - Origin point
        v1 - Direction from p1
        p2 - Origin point 2
        v2 - Direction of p2
        Returns:
        Null if vectors are collinear or if intersection is done behind one of origin point
      • removeDuplicatedCoordinates

        public static org.locationtech.jts.geom.Coordinate[] removeDuplicatedCoordinates​(org.locationtech.jts.geom.Coordinate[] coords,
                                                                                         boolean closeRing)
        Remove dupliacted coordinates Note : This method doesn't preserve the topology of geometry
        Parameters:
        coords - the input coordinates
        closeRing - is true the first coordinate is added at the end to close the array
        Returns:
      • removeRepeatedCoordinates

        public static org.locationtech.jts.geom.Coordinate[] removeRepeatedCoordinates​(org.locationtech.jts.geom.Coordinate[] coords,
                                                                                       double tolerance,
                                                                                       boolean duplicateFirstLast)
        Remove repeated coordinates according a given tolerance
        Parameters:
        coords - the input coordinates
        tolerance - to delete the coordinates
        duplicateFirstLast - false to delete the last coordinate if there are equals
        Returns:
      • round

        public static double round​(double value,
                                   int places)
        Round a double value according a number of decimal places
        Parameters:
        value - the double value
        places - the number of decimal places
        Returns: