Package org.geotools.referencing.util
Class CRSUtilities
- Object
-
- 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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Map<String,?>
changeDimensionInName(IdentifiedObject object, String search, String replace)
Changes the dimension declared in the name.static Point2D
deltaTransform(MathTransform2D transform, Point2D origin, Point2D source, Point2D dest)
Transforms the relative distance vector specified bysource
and stores the result indest
.static Position
deltaTransform(MathTransform transform, Position origin, Position source)
Transforms the relative distance vector specified bysource
and stores the result indest
.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.static CoordinateReferenceSystem
getCRS2D(CoordinateReferenceSystem crs)
Returns a two-dimensional coordinate reference system representing the two first dimensions of the specified coordinate reference system.static Datum
getDatum(CoordinateReferenceSystem crs)
Returns the datum of the specified CRS, ornull
if none.static int
getDimensionOf(CoordinateReferenceSystem crs, Class<? extends CoordinateReferenceSystem> type)
Returns the dimension of the first coordinate reference system of the given type.static Ellipsoid
getHeadGeoEllipsoid(CoordinateReferenceSystem crs)
Returns the ellipsoid used by the specified coordinate reference system, providing that the two first dimensions use an instance ofGeographicCRS
.static GeographicCRS
getStandardGeographicCRS2D(CoordinateReferenceSystem crs)
Derives a geographic CRS with (longitude, latitude) axis order in decimal degrees, relative to Greenwich.static CoordinateReferenceSystem
getSubCRS(CoordinateReferenceSystem crs, int lower, int upper)
Returns a sub-coordinate reference system for the specified dimension range.static Unit<?>
getUnit(CoordinateSystem cs)
Returns the unit used for all axis in the specified coordinate system.static String
toWGS84String(CoordinateReferenceSystem crs, Rectangle2D bounds)
Returns a character string for the specified geographic area.
-
-
-
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 thanaxis
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()
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 returnsnull
. 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
-
getDimensionOf
public static int getDimensionOf(CoordinateReferenceSystem crs, Class<? extends CoordinateReferenceSystem> type) throws IllegalArgumentException
Returns the dimension of the first coordinate reference system of the given type. Thetype
argument must be a subinterface ofCoordinateReferenceSystem
. If no such dimension is found, then this method returns-1
.- Parameters:
crs
- The coordinate reference system (CRS) to examine.type
- The CRS type to look for. Must be a subclass ofCoordinateReferenceSystem
.- Returns:
- The dimension range of the specified CRS type, or
-1
if none. - Throws:
IllegalArgumentException
- if thetype
is not legal.
-
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
ifcrs
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. Ifcrs
is already a two-dimensional CRS, then it is returned unchanged. Otherwise, if it is aCompoundCRS
, then the head coordinate reference system is examined.- Parameters:
crs
- The coordinate system, ornull
.- Returns:
- A two-dimensional coordinate reference system that represents the two first
dimensions of
crs
, ornull
ifcrs
wasnull
. - Throws:
TransformException
- ifcrs
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 ifname
is "WGS 84 (geographic 3D)",search
is "3D" andreplace
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 theobject
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, ornull
if none.- Parameters:
crs
- The coordinate reference system for which to get the datum. May benull
.- 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 ofGeographicCRS
. Otherwise (i.e. if the two first dimensions are not geographic), returnsnull
.- 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, returnsDefaultGeographicCRS.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 bysource
and stores the result indest
. 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 bysource
and stores the result indest
. 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 transformeddest
- The resulting transformed distance vector, ornull
- 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.
-
-