Class PostGisUtil

java.lang.Object
io.github.sebasbaumh.postgis.PostGisUtil

@NonNullByDefault public final class PostGisUtil extends Object
Class for helper functions.
Author:
Sebastian Baumhekel
  • Field Details

    • BIG_ENDIAN

      public static final byte BIG_ENDIAN
      Big endian encoding.
      See Also:
    • HEX_CHAR

      public static final char[] HEX_CHAR
      Characters for converting data to hex strings.
    • LITTLE_ENDIAN

      public static final byte LITTLE_ENDIAN
      Little endian encoding.
      See Also:
  • Method Details

    • calcAreaSigned

      public static double calcAreaSigned(Iterable<Point> points)
      Calculates the area of the outer ring of the given polygon (signed).
      Parameters:
      points - points
      Returns:
      area (signed depending on direction)
    • checkConsistency

      public static <T extends Geometry> boolean checkConsistency(Iterable<T> geoms)
      Do some internal consistency checks on the given geometries. Currently, all Geometries must have a valid dimension (2 or 3) and a valid type. Composed geometries must have all equal SRID, dimensionality and measures, as well as that they do not contain NULL or inconsistent subgeometries. BinaryParser and WKTParser should only generate consistent geometries. BinaryWriter may produce invalid results on inconsistent geometries.
      Parameters:
      geoms - geometries
      Returns:
      true if all checks are passed.
    • equalsDouble

      public static boolean equalsDouble(double a, double b)
      Compares two double values respecting Double.NaN values.
      Parameters:
      a - Double
      b - Double
      Returns:
      true if they are equal, else false
    • equalsIterable

      public static <T, U> boolean equalsIterable(@Nullable Iterable<T> la, @Nullable Iterable<U> lb)
      Checks, if the given Iterables contain the same elements (in the same order).
      Parameters:
      la - Iterable (can be null)
      lb - Iterable (can be null)
      Returns:
      true on success, else false
    • firstOrDefault

      @Nullable public static <T> T firstOrDefault(Iterable<T> elements)
      Returns the first or a default element of the given collection.
      Parameters:
      elements - collection
      Returns:
      first element if it exists, else default element
    • lastOrDefault

      @Nullable public static <T> T lastOrDefault(Iterable<T> elements)
      Gets the last element of the given Iterable.
      Parameters:
      elements - elements
      Returns:
      last element on success, else null
    • removeBrackets

      public static String removeBrackets(String s)
      Removes brackets from the given String.
      Parameters:
      s - String
      Returns:
      String without brackets
    • split

      public static List<String> split(String value, char separator)
      Splits a string like String.split(String) without any support for regular expressions, but faster.
      Parameters:
      value - String to split.
      separator - separator
      Returns:
      the array of strings computed by splitting this string
    • toHexByte

      public static int toHexByte(char c)
      Converts the given hexadecimal character to its byte representation. i.e. 'A'->10
      Parameters:
      c - character
      Returns:
      byte value
      Throws:
      IllegalArgumentException - if character is not '0'-'9', 'a'-'f' or 'A'-'F'
    • toHexBytes

      public static byte[] toHexBytes(String hex)
      Converts the given string in hexadecimal format to the corresponding bytes.
      Parameters:
      hex - String in hex
      Returns:
      byte data
    • toHexString

      public static String toHexString(byte[] data)
      Converts the byte data to a hexadecimal string.
      Parameters:
      data - byte data
      Returns:
      hexadecimal String (lower case)