Class CRSUtilities


  • public final class CRSUtilities
    extends Object
    A set of static methods working on OpenGIS® coordinate reference system objects. Some of those methods are useful, but not really rigorous. This is why they do not appear in the "official" package, but instead in this private one. Do not rely on this API! It may change in incompatible way in any future release.
    Since:
    2.0
    Author:
    Martin Desruisseaux (IRD)
    • Method Detail

      • dimensionColinearWith

        public static int dimensionColinearWith​(CoordinateSystem cs,
                                                CoordinateSystemAxis axis)
        Returns the dimension within the coordinate system of the first occurrence of an axis colinear with the specified axis. If an axis with the same direction or an opposite direction than axis ocurs in the coordinate system, then the dimension of the first such occurrence is returned. That is, the a value k such that:
         cs.getAxis(k).getDirection().absolute() == axis.getDirection().absolute()
         
        is true. If no such axis occurs in this coordinate system, then -1 is returned.

        For example, dimensionColinearWith(CoordinateSystemAxis.TIME) returns the dimension number of time axis.

        Parameters:
        cs - The coordinate system to examine.
        axis - The axis to look for.
        Returns:
        The dimension number of the specified axis, or -1 if none.
      • getUnit

        public static Unit<?> getUnit​(CoordinateSystem cs)
        Returns the unit used for all axis in the specified coordinate system. If not all axis uses the same unit, then this method returns null. This convenience method is often used for Well Know Text (WKT) formatting.
        Parameters:
        cs - The coordinate system for which to get the unit.
        Returns:
        The unit for all axis in the given coordinate system, or null.
        Since:
        2.2
      • getSubCRS

        public static CoordinateReferenceSystem getSubCRS​(CoordinateReferenceSystem crs,
                                                          int lower,
                                                          int upper)
        Returns a sub-coordinate reference system for the specified dimension range.
        Parameters:
        crs - The coordinate reference system to decompose.
        lower - The first dimension to keep, inclusive.
        upper - The last dimension to keep, exclusive.
        Returns:
        The sub-coordinate system, or null if crs can't be decomposed for dimensions in the range [lower..upper].
      • getCRS2D

        public static CoordinateReferenceSystem getCRS2D​(CoordinateReferenceSystem crs)
                                                  throws TransformException
        Returns a two-dimensional coordinate reference system representing the two first dimensions of the specified coordinate reference system. If crs is already a two-dimensional CRS, then it is returned unchanged. Otherwise, if it is a CompoundCRS, then the head coordinate reference system is examined.
        Parameters:
        crs - The coordinate system, or null.
        Returns:
        A two-dimensional coordinate reference system that represents the two first dimensions of crs, or null if crs was null.
        Throws:
        TransformException - if crs can't be reduced to a two-coordinate system. We use this exception class since this method is usually invoked in the context of a transformation process.
      • changeDimensionInName

        public static Map<String,​?> changeDimensionInName​(IdentifiedObject object,
                                                                String search,
                                                                String replace)
        Changes the dimension declared in the name. For example if name is "WGS 84 (geographic 3D)", search is "3D" and replace is "2D", then this method returns "WGS 84 (geographic 2D)". If the string to search is not found, then it is concatenated to the name.
        Parameters:
        object - The identified object having the original name.
        search - The dimension token to search in the object name.
        replace - The new token to substitute to the one we were looking for.
        Returns:
        The name with the substitution performed.
        Since:
        2.6
      • getDatum

        public static Datum getDatum​(CoordinateReferenceSystem crs)
        Returns the datum of the specified CRS, or null if none.
        Parameters:
        crs - The coordinate reference system for which to get the datum. May be null.
        Returns:
        The datum in the given CRS, or null if none.
      • getHeadGeoEllipsoid

        public static Ellipsoid getHeadGeoEllipsoid​(CoordinateReferenceSystem crs)
        Returns the ellipsoid used by the specified coordinate reference system, providing that the two first dimensions use an instance of GeographicCRS. Otherwise (i.e. if the two first dimensions are not geographic), returns null.
        Parameters:
        crs - The coordinate reference system for which to get the ellipsoid.
        Returns:
        The ellipsoid in the given CRS, or null if none.
      • getStandardGeographicCRS2D

        public static GeographicCRS getStandardGeographicCRS2D​(CoordinateReferenceSystem crs)
        Derives a geographic CRS with (longitude, latitude) axis order in decimal degrees, relative to Greenwich. If no such CRS can be obtained of created, returns DefaultGeographicCRS.WGS84.
        Parameters:
        crs - A source CRS.
        Returns:
        A two-dimensional geographic CRS with standard axis. Never null.
      • deltaTransform

        public static Position deltaTransform​(MathTransform transform,
                                              Position origin,
                                              Position source)
                                       throws TransformException
        Transforms the relative distance vector specified by source and stores the result in dest. A relative distance vector is transformed without applying the translation components.
        Parameters:
        transform - The transform to apply.
        origin - The position where to compute the delta transform in the source CS.
        source - The distance vector to be delta transformed
        Returns:
        The result of the transformation.
        Throws:
        TransformException - if the transformation failed.
        Since:
        2.3
      • deltaTransform

        public static Point2D deltaTransform​(MathTransform2D transform,
                                             Point2D origin,
                                             Point2D source,
                                             Point2D dest)
                                      throws TransformException
        Transforms the relative distance vector specified by source and stores the result in dest. A relative distance vector is transformed without applying the translation components.
        Parameters:
        transform - The transform to apply.
        origin - The position where to compute the delta transform in the source CS.
        source - The distance vector to be delta transformed
        dest - The resulting transformed distance vector, or null
        Returns:
        The result of the transformation.
        Throws:
        TransformException - if the transformation failed.
        See Also:
        AffineTransform.deltaTransform(Point2D,Point2D)
      • toWGS84String

        public static String toWGS84String​(CoordinateReferenceSystem crs,
                                           Rectangle2D bounds)
        Returns a character string for the specified geographic area. The string will have the form "45°00.00'N-50°00.00'N 30°00.00'E-40°00.00'E". If a map projection is required in order to obtain this representation, it will be automatically applied. This string is mostly used for debugging purpose.
        Parameters:
        crs - The coordinate reference system of the bounding box.
        bounds - The bounding box to format.
        Returns:
        The bounding box formatted as a string.