Class WKTUtilities

java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.referencing.WKTUtilities

public final class WKTUtilities extends Static
Utility methods for referencing WKT formatting. This class provides a set of toFormattable(…) for various IdentifiedObject subtypes. It is important to not provide a generic toFormattable(IdentifiedObject) method, because the user may choose to implement more than one GeoAPI interface for the same object. We need to be specific in order to select the right "aspect" of the given object.
Since:
0.4
Version:
1.1
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Do not allow instantiation of this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    append(org.opengis.parameter.GeneralParameterValue parameter, Formatter formatter)
    Appends a parameter in a PARAMETER[…] element.
    static void
    appendName(org.opengis.referencing.IdentifiedObject object, Formatter formatter, ElementKind type)
    Appends the name of the given object to the formatter.
    static void
    appendParamMT(org.opengis.parameter.ParameterValueGroup parameters, Formatter formatter)
    Appends a group of parameters in a Param_MT[…] element.
    static Object[]
    cornersAndCenter(Function<int[],Number> tensor, int[] size, int cornerSize)
    Returns the values in the corners and in the center of the given tensor.
    static boolean
    isEPSG(org.opengis.parameter.GeneralParameterDescriptor descriptor, boolean ifUndefined)
    Returns true if the given parameter is defined in the EPSG code space.
    static int[]
    Suggests an amount of fraction digits to use for formatting numbers in each column of the given matrix.
    static int[]
    suggestFractionDigits(org.opengis.referencing.crs.CoordinateReferenceSystem crs, Vector[] points)
    Suggests an amount of fraction digits to use for formatting numbers in each column of the given sequence of points.
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Unit<Q>
    toFormattable(javax.measure.Unit<Q> unit)
    If the given unit is one of the unit that cannot be formatted without ambiguity in WKT format, return a proposed replacement.
    toFormattable(org.opengis.referencing.crs.CoordinateReferenceSystem object)
    Returns the given coordinate reference system as a formattable object.
    toFormattable(org.opengis.referencing.cs.CoordinateSystem object)
    Returns the given coordinate system as a formattable object.
    toFormattable(org.opengis.referencing.cs.CoordinateSystemAxis object)
    Returns the given coordinate system axis as a formattable object.
    toFormattable(org.opengis.referencing.datum.Datum object)
    Returns the given datum as a formattable object.
    toFormattable(org.opengis.referencing.datum.Ellipsoid object)
    Returns the ellipsoid as a formattable object.
    toFormattable(org.opengis.referencing.datum.GeodeticDatum object)
    Returns the given geodetic datum as a formattable object.
    toFormattable(org.opengis.referencing.datum.PrimeMeridian object)
    Returns the given prime meridian as a formattable object.
    toFormattable(org.opengis.referencing.operation.MathTransform object, boolean internal)
    Converts the given object in a FormattableObject instance.
    static String
    toType(Class<?> base, Class<?> type)
    Returns the WKT type of the given interface.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WKTUtilities

      private WKTUtilities()
      Do not allow instantiation of this class.
  • Method Details

    • toType

      public static String toType(Class<?> base, Class<?> type)
      Returns the WKT type of the given interface. For CoordinateSystem base type, the returned value shall be one of affine, Cartesian, cylindrical, ellipsoidal, linear, parametric, polar, spherical, temporal or vertical.
      Parameters:
      base - the abstract base interface.
      type - the interface or classes for which to get the WKT type.
      Returns:
      the WKT type for the given class or interface, or null if none.
      See Also:
    • toFormattable

      public static FormattableObject toFormattable(org.opengis.referencing.crs.CoordinateReferenceSystem object)
      Returns the given coordinate reference system as a formattable object.
      Parameters:
      object - the coordinate reference system, or null.
      Returns:
      the given coordinate reference system as a formattable object, or null.
    • toFormattable

      public static FormattableObject toFormattable(org.opengis.referencing.cs.CoordinateSystem object)
      Returns the given coordinate system as a formattable object.
      Parameters:
      object - the coordinate system, or null.
      Returns:
      the given coordinate system as a formattable object, or null.
    • toFormattable

      public static FormattableObject toFormattable(org.opengis.referencing.cs.CoordinateSystemAxis object)
      Returns the given coordinate system axis as a formattable object.
      Parameters:
      object - the coordinate system axis, or null.
      Returns:
      the given coordinate system axis as a formattable object, or null.
    • toFormattable

      public static FormattableObject toFormattable(org.opengis.referencing.datum.Datum object)
      Returns the given datum as a formattable object.
      Parameters:
      object - the datum, or null.
      Returns:
      the given datum as a formattable object, or null.
    • toFormattable

      public static FormattableObject toFormattable(org.opengis.referencing.datum.GeodeticDatum object)
      Returns the given geodetic datum as a formattable object.
      Parameters:
      object - the datum, or null.
      Returns:
      the given datum as a formattable object, or null.
    • toFormattable

      public static FormattableObject toFormattable(org.opengis.referencing.datum.Ellipsoid object)
      Returns the ellipsoid as a formattable object.
      Parameters:
      object - the ellipsoid, or null.
      Returns:
      the given ellipsoid as a formattable object, or null.
    • toFormattable

      public static FormattableObject toFormattable(org.opengis.referencing.datum.PrimeMeridian object)
      Returns the given prime meridian as a formattable object.
      Parameters:
      object - the prime meridian, or null.
      Returns:
      the given prime meridian as a formattable object, or null.
    • toFormattable

      public static FormattableObject toFormattable(org.opengis.referencing.operation.MathTransform object, boolean internal)
      Converts the given object in a FormattableObject instance. Callers should verify that the given object is not already an instance of FormattableObject before to invoke this method. This method returns null if it cannot convert the object.
      Parameters:
      object - the object to wrap.
      internal - true if the formatting convention is Convention.INTERNAL.
      Returns:
      the given object converted to a FormattableObject instance, or null.
    • toFormattable

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Unit<Q> toFormattable(javax.measure.Unit<Q> unit)
      If the given unit is one of the unit that cannot be formatted without ambiguity in WKT format, return a proposed replacement. Otherwise returns unit unchanged.
      Type Parameters:
      Q - the unit dimension.
      Parameters:
      unit - the unit to test.
      Returns:
      the replacement to format, or unit if not needed.
      Since:
      0.8
    • appendName

      public static void appendName(org.opengis.referencing.IdentifiedObject object, Formatter formatter, ElementKind type)
      Appends the name of the given object to the formatter.
      Parameters:
      object - the object from which to get the name.
      formatter - the formatter where to append the name.
      type - the key of colors to apply if syntax colors are enabled.
    • appendParamMT

      public static void appendParamMT(org.opengis.parameter.ParameterValueGroup parameters, Formatter formatter)
      Appends a group of parameters in a Param_MT[…] element.
      Parameters:
      parameters - the parameter to append to the WKT, or null if none.
      formatter - the formatter where to append the parameter.
    • append

      public static void append(org.opengis.parameter.GeneralParameterValue parameter, Formatter formatter)
      Appends a parameter in a PARAMETER[…] element. If the supplied parameter is actually a parameter group, all contained parameters will be flattened in a single list.
      Parameters:
      parameter - the parameter to append to the WKT, or null if none.
      formatter - the formatter where to append the parameter.
    • isEPSG

      public static boolean isEPSG(org.opengis.parameter.GeneralParameterDescriptor descriptor, boolean ifUndefined)
      Returns true if the given parameter is defined in the EPSG code space. We handle EPSG parameters in a special way because Apache SIS uses the EPSG geodetic dataset as the primary source of coordinate operation definitions.

      We intentionally don't define isEPSG(OperationMethod) method because the operation method may be the inverse of an EPSG method (for example "Inverse of Mercator (variant A)") which would not be recognized. Instead, isEPSG(method.getParameters()) should work.

      Parameters:
      descriptor - the parameter or group of parameters to inspect.
      ifUndefined - the value to return if the code space is undefined.
      Returns:
      whether the given parameter is an EPSG parameter.
    • suggestFractionDigits

      public static int[] suggestFractionDigits(Vector[] rows)
      Suggests an amount of fraction digits to use for formatting numbers in each column of the given matrix. The number of fraction digits may be negative if we could round the numbers to 10, 100, etc.
      Parameters:
      rows - the matrix rows. It is not required that each row has the same length.
      Returns:
      suggested amount of fraction digits as an array as long as the longest row.
      See Also:
    • suggestFractionDigits

      public static int[] suggestFractionDigits(org.opengis.referencing.crs.CoordinateReferenceSystem crs, Vector[] points)
      Suggests an amount of fraction digits to use for formatting numbers in each column of the given sequence of points. The number of fraction digits may be negative if we could round the numbers to 10, etc.
      Parameters:
      crs - the coordinate reference system for each points, or null if unknown.
      points - the sequence of points. It is not required that each point has the same dimension.
      Returns:
      suggested amount of fraction digits as an array as long as the longest row.
    • cornersAndCenter

      public static Object[] cornersAndCenter(Function<int[],Number> tensor, int[] size, int cornerSize)
      Returns the values in the corners and in the center of the given tensor. The values are returned in a n-dimensional array of Number where n is the length of size. If some values have been skipped, null values are inserted in the rows or columns where the skipping occurs. Caller may replace null values by "…" string at formatting time for example.

      Indices of elements in the returned array are in reverse order than in the size argument. For example if size contains the values for dimensions (x,y,z) in that order, then elements in the returned array are accessed with cornersAndCenter[z][y][x] indices in that order. It is done that way because in the common case where there is only two dimensions, cornersAndCenter[y] is a row. This is what WKT formatter expects among others.

      Parameters:
      tensor - function providing values of the tensor. Inputs are indices of the desired value with index in each dimension ranging from 0 inclusive to size[dimension] exclusive.
      size - size of the tensor. The length of this array is the tensor dimension.
      cornerSize - number of values to keep in each corner.
      Returns:
      n-dimensional array of Number containing corners and center of the given tensor.
      Since:
      1.0