|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectStatic
CRS
public final class CRS
Utility class for making use of the Coordinate Reference System and associated Factory implementations. This utility class is made up of static functions working with arbitrary implementations of GeoAPI interfaces.
The methods defined in this class can be grouped in three categories:
decode(String).isHorizontalCRS(CoordinateReferenceSystem).transform(CoordinateOperation,Envelope)
Note that many of those methods are also defined in the Envelopes class.
IdentifiedObjects,
Envelopes
| referencing/geotk-referencing (download) | View source code for this class |
| Method Summary | |
|---|---|
static CoordinateReferenceSystem |
decode(String code)
Returns a Coordinate Reference System for the specified code. |
static CoordinateReferenceSystem |
decode(String code,
boolean longitudeFirst)
Returns a Coordinate Reference System for the specified code, maybe forcing the axis order to (longitude, latitude). |
static double[] |
deltaTransform(MathTransform transform,
DirectPosition origin,
double... vector)
Transforms the given relative distance using the given transform. |
static boolean |
equalsApproximatively(Object object1,
Object object2)
Compares the specified objects for equality, ignoring metadata and slight differences in numerical values. |
static boolean |
equalsIgnoreMetadata(Object object1,
Object object2)
Compares the specified objects for equality, ignoring metadata. |
static MathTransform |
findMathTransform(CoordinateReferenceSystem sourceCRS,
CoordinateReferenceSystem targetCRS)
Grabs a transform between two Coordinate Reference Systems. |
static MathTransform |
findMathTransform(CoordinateReferenceSystem sourceCRS,
CoordinateReferenceSystem targetCRS,
boolean lenient)
Grab a transform between two Coordinate Reference Systems. |
static CRSAuthorityFactory |
getAuthorityFactory(Boolean longitudeFirst)
Returns the CRS authority factory used by the decode methods. |
static CompoundCRS |
getCompoundCRS(CompoundCRS crs,
SingleCRS... components)
Returns the first compound CRS which contains only the given components, in any order. |
static CoordinateOperationFactory |
getCoordinateOperationFactory(boolean lenient)
Returns the coordinate operation factory used by findMathTransform convenience methods. |
static Datum |
getDatum(CoordinateReferenceSystem crs)
Returns the datum of the specified CRS, or null if none. |
static Ellipsoid |
getEllipsoid(CoordinateReferenceSystem crs)
Returns the first ellipsoid found in a coordinate reference system, or null if there is none. |
static Envelope |
getEnvelope(CoordinateReferenceSystem crs)
Returns the domain of validity for the specified coordinate reference system, or null if unknown. |
static GeographicBoundingBox |
getGeographicBoundingBox(CoordinateReferenceSystem crs)
Returns the valid geographic area for the specified coordinate reference system, or null if unknown. |
static SingleCRS |
getHorizontalCRS(CoordinateReferenceSystem crs)
Returns the first horizontal coordinate reference system found in the given CRS, or null if there is none. |
static ProjectedCRS |
getProjectedCRS(CoordinateReferenceSystem crs)
Returns the first projected coordinate reference system found in a the given CRS, or null if there is none. |
static CoordinateReferenceSystem |
getSubCRS(CoordinateReferenceSystem crs,
int lower,
int upper)
Returns the coordinate reference system in the given range of dimension indices. |
static Set<String> |
getSupportedAuthorities(boolean returnAliases)
Returns the set of the authority identifiers supported by registered authority factories. |
static Set<String> |
getSupportedCodes(String authority)
Gets the list of the codes that are supported by the given authority. |
static TemporalCRS |
getTemporalCRS(CoordinateReferenceSystem crs)
Returns the first temporal coordinate reference system found in the given CRS, or null if there is none. |
static Version |
getVersion(String authority)
Returns the version number of the specified authority database, or null if
not available. |
static VerticalCRS |
getVerticalCRS(CoordinateReferenceSystem crs)
Returns the first vertical coordinate reference system found in a the given CRS, or null if there is none. |
static boolean |
isHorizontalCRS(CoordinateReferenceSystem crs)
Returns true if the given CRS is horizontal. |
static CoordinateReferenceSystem |
parseWKT(String wkt)
Parses a Well Known Text (WKT) into a CRS object. |
static void |
reset(String aspects)
Resets some aspects of the referencing system. |
static GeneralEnvelope |
transform(CoordinateOperation operation,
Envelope envelope)
Transforms an envelope using the given coordinate operation. |
static Rectangle2D |
transform(CoordinateOperation operation,
Rectangle2D envelope,
Rectangle2D destination)
Transforms a rectangular envelope using the given coordinate operation. |
static Envelope |
transform(Envelope envelope,
CoordinateReferenceSystem targetCRS)
Transforms the given envelope to the specified CRS. |
static Rectangle2D |
transform(MathTransform2D transform,
Rectangle2D envelope,
Rectangle2D destination)
Transforms a rectangular envelope using the given math transform. |
static GeneralEnvelope |
transform(MathTransform transform,
Envelope envelope)
Transforms an envelope using the given math transform. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static CRSAuthorityFactory getAuthorityFactory(Boolean longitudeFirst)
throws FactoryRegistryException
decode methods.
This factory uses a cache,
scans over all factories and
uses additional factories as fallbacks if there is more than one registered factory for the same authority.
This factory can be used as a kind of system-wide factory for all authorities.
However for more determinist behavior, consider using a more specific factory (as returned
by AuthorityFactoryFinder.getCRSAuthorityFactory(java.lang.String, org.geotoolkit.factory.Hints)) when the authority is known.
longitudeFirst - true if axis order should be forced to
(longitude, latitude), false if no order should be
forced (i.e. the standard specified by the authority is respected), or null
for the system default.
FactoryRegistryException - if the factory can't be created.Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDERpublic static CoordinateOperationFactory getCoordinateOperationFactory(boolean lenient)
findMathTransform convenience methods.
lenient - true if the coordinate operations should be created
even when there is no information available for a datum shift.
Hints.LENIENT_DATUM_SHIFT
public static Version getVersion(String authority)
throws FactoryRegistryException
null if
not available.
authority - The authority name (typically "EPSG").
null if unknown.
FactoryRegistryException - if no CRSAuthorityFactory implementation
was found for the specified authority.Hints.VERSIONpublic static Set<String> getSupportedCodes(String authority)
getSupportedCodes("EPSG") may returns "EPSG:2000", "EPSG:2001",
"EPSG:2002", etc. It may also returns "2000", "2001",
"2002", etc. without the "EPSG:" prefix. Whatever the authority
name is prefixed or not is factory implementation dependent.
If there is more than one factory for the given authority, then this method merges the code set of all of them. If a factory fails to provide a set of supported code, then this particular factory is ignored. Please be aware of the following potential issues:
"4326" and
"EPSG:4326"), then the returned set will contain a lot of synonymous
codes.decode(c) will use the same authority
factory than the one that formatted c.FactoryExceptions are logged as warnings and otherwise ignored.If a more determinist behavior is wanted, consider the code below instead. The following code exploit only one factory, the "preferred" one.
factory = AuthorityFactoryFinder.getCRSAuthorityFactory(authority, null); Set<String> codes = factory.getAuthorityCodes(CoordinateReferenceSystem.class); String code = ... // Choose a code here. CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem(code);
authority - The authority name (for example "EPSG").
AuthorityFactory.getAuthorityCodes(Class),
List of authority codespublic static Set<String> getSupportedAuthorities(boolean returnAliases)
returnAliases - If true, the set will contain all identifiers for each
authority. If false, only the first one
public static CoordinateReferenceSystem decode(String code)
throws NoSuchAuthorityCodeException,
FactoryException
EPSG:4326AUTO:42001,9001,0,30If there is more than one factory implementation for the same authority, then all additional factories are fallbacks to be used only when the first acceptable factory failed to create the requested CRS object.
Common codes
A few commonly used codes are:
Caching
CRS objects created by previous calls to this method are
cached
using weak references. Subsequent calls to this
method with the same authority code should be fast, unless the CRS object has been garbage
collected.
code - The Coordinate Reference System authority code.
NoSuchAuthorityCodeException - If the code could not be understood.
FactoryException - if the CRS creation failed for an other reason.getSupportedCodes(String),
Units.valueOfEPSG(int),
List of authority codes
public static CoordinateReferenceSystem decode(String code,
boolean longitudeFirst)
throws NoSuchAuthorityCodeException,
FactoryException
code argument value is parsed
as in decode(code). The longitudeFirst
argument is the value to be given to the FORCE_LONGITUDE_FIRST_AXIS_ORDER hint.
Example: by default, CRS.decode("EPSG:4326") returns a Geographic CRS with
(latitude, longitude) axis order, while CRS.decode("EPSG:4326", true)
returns the same CRS except for axis order, which is (longitude, latitude).
code - The Coordinate Reference System authority code.longitudeFirst - true if axis order should be forced to
(longitude, latitude), false if no order should
be forced (i.e. the standard specified by the authority is respected).
NoSuchAuthorityCodeException - If the code could not be understood.
FactoryException - if the CRS creation failed for an other reason.Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
LongitudeFirstEpsgFactory,
List of authority codes
public static CoordinateReferenceSystem parseWKT(String wkt)
throws FactoryException
FactoryFinder.getCRSFactory(null).createFromWKT(wkt);
wkt - The WKT string to parse.
FactoryException - if the given WKT can't be parsed.Envelopes.parseWKT(String),
IdentifiedObject.toWKT()public static Envelope getEnvelope(CoordinateReferenceSystem crs)
null if unknown. The returned envelope is expressed in terms of the
specified CRS.
This method looks in two places:
Note that this method is also accessible from the Envelopes class.
crs - The coordinate reference system, or null.
null if none.getGeographicBoundingBox(CoordinateReferenceSystem),
Envelopes.getDomainOfValidity(CoordinateReferenceSystem),
GeneralEnvelope.reduceToDomain(boolean)public static GeographicBoundingBox getGeographicBoundingBox(CoordinateReferenceSystem crs)
null if unknown.
This method fetches the domain
of validity associated with the given CRS. Only geographic
extents of kind geographic bounding box are taken in
account.
crs - The coordinate reference system, or null.
null if none.getEnvelope(CoordinateReferenceSystem)public static boolean isHorizontalCRS(CoordinateReferenceSystem crs)
true if the given CRS is horizontal. This method is provided because there is
a direct way to determine if a CRS is vertical or temporal, but no direct way to determine if
it is horizontal. So this method complements the check for spatio-temporal components as below:
if (crs instanceof TemporalCRS) determines if the CRS is for the temporal component.if (crs instanceof VerticalCRS) determines if the CRS is for the vertical component.if (CRS.isHorizontalCRS(crs)) determines if the CRS is for the horizontal component.This method considers a CRS as horizontal if it is two-dimensional and comply with one of the following conditions:
GeographicCRS.ProjectedCRS (actually this is not explicitly
checked, since this condition is a special case of the condition below).GeneralDerivedCRS based on a horizontal CRS
and using a GeodeticDatum.
The last condition (GeneralDerivedCRS based on a horizontal CRS) allows for example
to express the coordinates of a projected CRS (which use a Cartesian coordinate system) in
a polar coordinate system and still consider
the result as horizontal. However this assumes that the axes of the derived CRS are coplanar
with the axes of the base CRS. This is not always true since a derived CRS could be created
for an inclined plane, for example a plane fitting the slope of a mountain. ISO 19111 does
not specify how to handle this case. In the Geotk implementation, we suggest to define a new
datum for inclined plane which is not a geodetic datum.
crs - The coordinate reference system, or null.
true if the given CRS is non-null and comply with one of the above
conditions, or false otherwise.getHorizontalCRS(CoordinateReferenceSystem)public static SingleCRS getHorizontalCRS(CoordinateReferenceSystem crs)
null if there is none. A horizontal CRS is usually a two-dimensional
geographic or projected CRS.
See the isHorizontalCRS method for
a more accurate description about the conditions for a CRS to be considered horizontal.
crs - The coordinate reference system, or null.
null if none.public static ProjectedCRS getProjectedCRS(CoordinateReferenceSystem crs)
null if there is none.
crs - The coordinate reference system, or null.
null if none.public static VerticalCRS getVerticalCRS(CoordinateReferenceSystem crs)
null if there is none.
crs - The coordinate reference system, or null.
null if none.public static TemporalCRS getTemporalCRS(CoordinateReferenceSystem crs)
null if there is none.
crs - The coordinate reference system, or null.
null if none.
public static CompoundCRS getCompoundCRS(CompoundCRS crs,
SingleCRS... components)
SingleCRS components of the given compound CRS. If
all those components are equal, ignoring metadata
and order, to the SingleCRS components given to this method, then the given
CompoundCRS is returned. Otherwise if the given CompoundCRS contains
nested CompoundCRS, then those nested CRS are inspected recursively by the same
algorithm. Otherwise, this method returns null.
This method is useful for extracting metadata about the 3D spatial CRS part in a 4D spatio-temporal CRS. For example given the following CRS:
COMPD_CS["Mercator + height + time",
COMPD_CS["Mercator + height",
PROJCS["Mercator", ...etc...]
VERT_CS["Ellipsoidal height", ...etc...]]
TemporalCRS["Modified Julian", ...etc...]]
Then the following code will returns the nested COMPD_CS["Mercator + height"]
without prior knowledge of the CRS component order (the time CRS could be first, and
the vertical CRS could be before the horizontal one):
CompoundCRS crs = ...;
SingleCRS horizontalCRS = getHorizontalCRS(crs);
VerticalCRS verticalCRS = getVerticalCRS(crs);
if (horizontalCRS != null && verticalCRS != null) {
CompoundCRS spatialCRS = getCompoundCRS(crs, horizontalCRS, verticalCRS);
if (spatialCRS != null) {
// ...
}
}
crs - The compound CRS to compare with the given component CRS, or null.components - The CRS which must be components of the returned CRS.
null if none.DefaultCompoundCRS.getSingleCRS()
public static CoordinateReferenceSystem getSubCRS(CoordinateReferenceSystem crs,
int lower,
int upper)
crs is null, then this method returns null.lower is 0 and upper if the number of CRS dimensions,
then this method returns the given CRS unchanged.CompoundCRS, then this method
searches for a component where:
upper - lower;lower.null.
This method does not attempt to build new CRS from the components.
For example it does not attempt to create a 3D geographic CRS from a 2D one + a vertical
component. If such functionality is desired, consider using the utility methods in
ReferencingFactoryContainer instead.
crs - The coordinate reference system to decompose, or null.lower - The first dimension to keep, inclusive.upper - The last dimension to keep, exclusive.
null if the given crs was null
or can't be decomposed for dimensions in the range [lower..upper].
IndexOutOfBoundsException - If the given index are out of bounds.ReferencingFactoryContainer.separate(CoordinateReferenceSystem, int[])public static Datum getDatum(CoordinateReferenceSystem crs)
null if none.
This method processes as below:
SingleCRS, then this method returns
crs.getDatum().CompoundCRS, then:
null.
crs - The coordinate reference system for which to get the datum. May be null.
null if none.getEllipsoid(CoordinateReferenceSystem)public static Ellipsoid getEllipsoid(CoordinateReferenceSystem crs)
null if there is none. More specifically:
SingleCRS and its datum is a
GeodeticDatum, then this method returns the datum ellipsoid.CompoundCRS, then this method
invokes itself recursively for each component until a geodetic datum is found.null.Note that this method does not check if there is more than one ellipsoid (it should never be the case).
crs - The coordinate reference system, or null.
null if none.getDatum(CoordinateReferenceSystem)
public static boolean equalsIgnoreMetadata(Object object1,
Object object2)
true, then:
If the two given objects are MathTransform instances, then transforming
a set of coordinate values using one transform will produce the same results than
transforming the same coordinates with the other transform.
If the two given objects are CoordinateReferenceSystem instances,
then a call to findMathTransform(crs1, crs2) will return
an identity transform.
equalsApproximatively(Object, Object) can be used instead.
Implementation note
This is a convenience method for the following method call:
return Utilities.deepEquals(object1, object2, ComparisonMode.IGNORE_METADATA);
object1 - The first object to compare (may be null).object2 - The second object to compare (may be null).
true if both objects are equal, ignoring metadata.Utilities.deepEquals(Object, Object, ComparisonMode),
ComparisonMode.IGNORE_METADATA
public static boolean equalsApproximatively(Object object1,
Object object2)
true, then:
If the two given objects are MathTransform instances, then transforming a
set of coordinate values using one transform will produce approximatively
the same results than transforming the same coordinates with the other transform.
If the two given objects are CoordinateReferenceSystem instances,
then a call to findMathTransform(crs1, crs2) will return
a transform close to the identity transform.
Implementation note
This is a convenience method for the following method call:
return Utilities.deepEquals(object1, object2, ComparisonMode.APPROXIMATIVE);
object1 - The first object to compare (may be null).object2 - The second object to compare (may be null).
true if both objects are approximatively equal.Utilities.deepEquals(Object, Object, ComparisonMode),
ComparisonMode.APPROXIMATIVE
public static MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS,
CoordinateReferenceSystem targetCRS)
throws FactoryException
Note that some metadata like coordinate operation accuracy are lost by this method. If those metadata are wanted, use the coordinate operation factory directly.CoordinateOperationFactory factory = FactoryFinder.getCoordinateOperationFactory(null); CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS); MathTransform transform = operation.getMathTransform();
Sample use:
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:42102");
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
sourceCRS - The source CRS.targetCRS - The target CRS.
sourceCRS to targetCRS.
FactoryException - If no math transform can be created for the specified source and
target CRS.CoordinateOperationFactory.createOperation(CoordinateReferenceSystem, CoordinateReferenceSystem)
public static MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS,
CoordinateReferenceSystem targetCRS,
boolean lenient)
throws FactoryException
findMathTransform(sourceCRS, targetCRS), except that it specifies whatever this
method should tolerate lenient datum shift. If the lenient argument
is true, then this method will not throw a "Bursa-Wolf parameters required"
exception during datum shifts if the Bursa-Wolf parameters are not specified.
Instead it will assume a no datum shift.
sourceCRS - The source CRS.targetCRS - The target CRS.lenient - true if the math transform should be created even when there is
no information available for a datum shift. if this argument is not specified,
then the default value is determined from the system default.
sourceCRS to targetCRS.
FactoryException - If no math transform can be created for the specified source and
target CRS.Hints.LENIENT_DATUM_SHIFT,
CoordinateOperationFactory.createOperation(CoordinateReferenceSystem, CoordinateReferenceSystem)
public static Envelope transform(Envelope envelope,
CoordinateReferenceSystem targetCRS)
throws TransformException
See Envelopes.transform(Envelope, CoordinateReferenceSystem) for more information.
This method delegates its work to the above-cited Envelopes class and is defined
in this CRS class only for convenience.
envelope - The envelope to transform (may be null).targetCRS - The target CRS (may be null).
envelope
if no transformation was required.
TransformException - If a transformation was required and failed.
public static GeneralEnvelope transform(MathTransform transform,
Envelope envelope)
throws TransformException
See Envelopes.transform(MathTransform, Envelope) for more information.
This method delegates its work to the above-cited Envelopes class and
is defined in this CRS class only for convenience.
transform - The transform to use.envelope - Envelope to transform, or null. This envelope will not be modified.
null if envelope was null.
TransformException - if a transform failed.
public static GeneralEnvelope transform(CoordinateOperation operation,
Envelope envelope)
throws TransformException
See Envelopes.transform(CoordinateOperation, Envelope) for more information.
This method delegates its work to the above-cited Envelopes class and is defined
in this CRS class only for convenience.
operation - The operation to use.envelope - Envelope to transform, or null. This envelope will not be modified.
null if envelope was null.
TransformException - if a transform failed.
public static Rectangle2D transform(MathTransform2D transform,
Rectangle2D envelope,
Rectangle2D destination)
throws TransformException
See Envelopes.transform(MathTransform2D, Rectangle2D, Rectangle2D) for more
information. This method delegates its work to the above-cited Envelopes class
and is defined in this CRS class only for convenience.
transform - The transform to use. Source and target dimension must be 2.envelope - The rectangle to transform (may be null).destination - The destination rectangle (may be envelope).
If null, a new rectangle will be created and returned.
destination, or a new rectangle if destination was non-null
and envelope was null.
TransformException - if a transform failed.
public static Rectangle2D transform(CoordinateOperation operation,
Rectangle2D envelope,
Rectangle2D destination)
throws TransformException
See Envelopes.transform(CoordinateOperation, Rectangle2D, Rectangle2D) for more
information. This method delegates its work to the above-cited Envelopes class
and is defined in this CRS class only for convenience.
operation - The operation to use. Source and target dimension must be 2.envelope - The rectangle to transform (may be null).destination - The destination rectangle (may be envelope).
If null, a new rectangle will be created and returned.
destination, or a new rectangle if destination was non-null
and envelope was null.
TransformException - if a transform failed.
public static double[] deltaTransform(MathTransform transform,
DirectPosition origin,
double... vector)
throws TransformException
origin parameter in units
of the source CRS.
transform - The transformation to apply.origin - The position where to compute the delta transform in the source CRS.vector - The distance vector to be delta transformed.
TransformException - if the transformation failed.AffineTransform.deltaTransform(Point2D, Point2D)public static void reset(String aspects)
"plugins" for searching
the classpath for new plugins."warnings" for re-enabling the
warnings to be issued when a coordinate is out of geographic valid area.
aspects - The aspects to reset, or "all" for all of them.
Unknown aspects are silently ignored.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||