Class WKTUtilities
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.referencing.WKTUtilities
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Appends a parameter in aPARAMETER[…]
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 aParam_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) Returnstrue
if the given parameter is defined in the EPSG code space.static int[]
suggestFractionDigits
(Vector[] rows) 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.static FormattableObject
toFormattable
(org.opengis.referencing.crs.CoordinateReferenceSystem object) Returns the given coordinate reference system as a formattable object.static FormattableObject
toFormattable
(org.opengis.referencing.cs.CoordinateSystem object) Returns the given coordinate system as a formattable object.static FormattableObject
toFormattable
(org.opengis.referencing.cs.CoordinateSystemAxis object) Returns the given coordinate system axis as a formattable object.static FormattableObject
toFormattable
(org.opengis.referencing.datum.Datum object) Returns the given datum as a formattable object.static FormattableObject
toFormattable
(org.opengis.referencing.datum.Ellipsoid object) Returns the ellipsoid as a formattable object.static FormattableObject
toFormattable
(org.opengis.referencing.datum.GeodeticDatum object) Returns the given geodetic datum as a formattable object.static FormattableObject
toFormattable
(org.opengis.referencing.datum.PrimeMeridian object) Returns the given prime meridian as a formattable object.static FormattableObject
toFormattable
(org.opengis.referencing.operation.MathTransform object, boolean internal) Converts the given object in aFormattableObject
instance.static String
Returns the WKT type of the given interface.
-
Constructor Details
-
WKTUtilities
private WKTUtilities()Do not allow instantiation of this class.
-
-
Method Details
-
toType
Returns the WKT type of the given interface. ForCoordinateSystem
base type, the returned value shall be one ofaffine
,Cartesian
,cylindrical
,ellipsoidal
,linear
,parametric
,polar
,spherical
,temporal
orvertical
.- 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, ornull
.- Returns:
- the given coordinate reference system as a formattable object, or
null
.
-
toFormattable
Returns the given coordinate system as a formattable object.- Parameters:
object
- the coordinate system, ornull
.- 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, ornull
.- Returns:
- the given coordinate system axis as a formattable object, or
null
.
-
toFormattable
Returns the given datum as a formattable object.- Parameters:
object
- the datum, ornull
.- Returns:
- the given datum as a formattable object, or
null
.
-
toFormattable
Returns the given geodetic datum as a formattable object.- Parameters:
object
- the datum, ornull
.- Returns:
- the given datum as a formattable object, or
null
.
-
toFormattable
Returns the ellipsoid as a formattable object.- Parameters:
object
- the ellipsoid, ornull
.- Returns:
- the given ellipsoid as a formattable object, or
null
.
-
toFormattable
Returns the given prime meridian as a formattable object.- Parameters:
object
- the prime meridian, ornull
.- 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 aFormattableObject
instance. Callers should verify that the given object is not already an instance ofFormattableObject
before to invoke this method. This method returnsnull
if it cannot convert the object.- Parameters:
object
- the object to wrap.internal
-true
if the formatting convention isConvention.INTERNAL
.- Returns:
- the given object converted to a
FormattableObject
instance, ornull
.
-
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 returnsunit
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 aParam_MT[…]
element.- Parameters:
parameters
- the parameter to append to the WKT, ornull
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 aPARAMETER[…]
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, ornull
if none.formatter
- the formatter where to append the parameter.
-
isEPSG
public static boolean isEPSG(org.opengis.parameter.GeneralParameterDescriptor descriptor, boolean ifUndefined) Returnstrue
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
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, ornull
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
Returns the values in the corners and in the center of the given tensor. The values are returned in a n-dimensional array ofNumber
where n is the length ofsize
. 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 ifsize
contains the values for dimensions (x,y,z) in that order, then elements in the returned array are accessed withcornersAndCenter[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 tosize[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
-