org.geotools.referencing
Class CRS

java.lang.Object
  extended byorg.geotools.referencing.CRS

public final class CRS
extends java.lang.Object

Simple utility class for making use of the CoordinateReferenceSystem and associated Factory implementations.

This utility class is made up of static final functions. This class is not a Factory or a Builder. It makes use of the GeoAPI Factory interfaces provided by FactoryFinder in the most direct manner possible.

The following methods may be added in a future version:

Since:
2.1
Version:
$Id: CRS.java 18776 2006-03-22 11:36:21Z desruisseaux $
Author:
Jody Garnett (Refractions Research), Martin Desruisseaux

Nested Class Summary
static interface CRS.OperationVisitor
          Deprecated. No public API uses this interface at this time. If a particular CoordinateOperationFactory implementation is wanted, try to provide a Hints.COORDINATE_OPERATION_FACTORY hint to the FactoryFinder.getCoordinateOperationFactory(org.geotools.factory.Hints) method instead. In a future version, this interface will be removed or expanded if the hints way is not suffisient.
 
Method Summary
static org.opengis.referencing.crs.CoordinateReferenceSystem decode(java.lang.String code)
          Return a Coordinate Reference System for the specified code.
static boolean equalsIgnoreMetadata(java.lang.Object object1, java.lang.Object object2)
          Compares the specified objects for equality.
static org.opengis.spatialschema.geometry.Envelope getEnvelope(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
          Returns the valid area bounding box for the specified coordinate reference system, or if unknown.
static org.opengis.metadata.extent.GeographicBoundingBox getGeographicBoundingBox(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
          Returns the valid geographic area for the specified coordinate reference system, or if unknown.
static java.util.Set getSupportedCodes(java.lang.String authority)
          Get the list of the codes that are supported by the given authority.
static org.opengis.referencing.crs.CoordinateReferenceSystem parseWKT(java.lang.String wkt)
          Parses a Well Known Text (WKT) into a CRS object.
static org.opengis.referencing.operation.MathTransform transform(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS)
          Grab a transform between two Coordinate Reference Systems.
static org.opengis.referencing.operation.MathTransform transform(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS, boolean lenient)
          Grab a transform between two Coordinate Reference Systems.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

equalsIgnoreMetadata

public static boolean equalsIgnoreMetadata(java.lang.Object object1,
                                           java.lang.Object object2)
Compares the specified objects for equality. If both objects are Geotools implementations of class AbstractIdentifiedObject, then this method will ignore the metadata during the comparaison.

Parameters:
object1 - The first object to compare (may be null).
object2 - The second object to compare (may be null).
Returns:
if both objects are equals.
Since:
2.2

transform

public static org.opengis.referencing.operation.MathTransform transform(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS,
                                                                        org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS)
                                                                 throws org.opengis.referencing.FactoryException
Grab a transform between two Coordinate Reference Systems. This convenience method is a shorthand for the following:
FactoryFinder.getCoordinateOperationFactory(null).createOperation(sourceCRS, targetCRS).getMathTransform();
Sample use:
MathTransform transform = CRS.transform( CRS.decode("EPSG:42102"), CRS.decode("EPSG:4326") );

Parameters:
sourceCRS - The source CRS.
targetCRS - The target CRS.
Returns:
The math transform from to .
Throws:
org.opengis.referencing.FactoryException - If no math transform can be created for the specified source and target CRS.

transform

public static org.opengis.referencing.operation.MathTransform transform(org.opengis.referencing.crs.CoordinateReferenceSystem sourceCRS,
                                                                        org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS,
                                                                        boolean lenient)
                                                                 throws org.opengis.referencing.FactoryException
Grab a transform between two Coordinate Reference Systems. This method is similar to transform(sourceCRS, targetCRS), except that it can optionally tolerate lenient datum shift. If the argument is , then this method will not throw a "Bursa-Wolf parameters required" exception during datum shifts if the Bursa-Wolf paramaters are not specified. Instead it will assume a no datum shift.

Parameters:
sourceCRS - The source CRS.
targetCRS - The target CRS.
lenient - if the math transform should be created even when there is no information available for a datum shift. The default value is .
Returns:
The math transform from to .
Throws:
org.opengis.referencing.FactoryException - If no math transform can be created for the specified source and target CRS.

getSupportedCodes

public static java.util.Set getSupportedCodes(java.lang.String authority)
Get the list of the codes that are supported by the given authority. For example may returns , , , etc. It may also returns , , , etc. without the 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:

If a more determinist behavior is wanted, consider the code below instead. The following code exploit only one factory, the "preferred" one.

CRSAuthorityFactory factory = FactoryFinder.getCRSAuthorityFactory(authority, null);
Set<String> codes = factory.getAuthorityCodes(CoordinateReferenceSystem.class);
String code = ...choose a code here...
CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem(code);

Parameters:
authority - The authority name (for example ).
Returns:
The set of supported codes. May be empty, but never null.

decode

public static org.opengis.referencing.crs.CoordinateReferenceSystem decode(java.lang.String code)
                                                                    throws org.opengis.referencing.NoSuchAuthorityCodeException
Return a Coordinate Reference System for the specified code. Note that the code needs to mention the authority. Examples:
 EPSG:1234
 AUTO:42001, ..., ..., ...
 
If there is more than one factory implementation for the same authority, then this method tries all of them in their iteration order and returns the first successfully created CRS.

NOTE: The AllAuthoritiesFactory class provides similar functionality as an CRSAuthorityFactory implementation. It allows the same client code to work with either a specific authority, or all available authorities, at user choice. A call to this method maps approximatively to the following code:

AllAuthoritiesFactory.DEFAULT.createCoordinateReferenceSystem(code)
The main difference is that uses only the "preferred" implementation for each authority, while this method tries every implementations. Using only the preferred implementation way save class loading and database connections if more than one EPSG database are availables (for example an Access and a PostgreSQL ones) and their content are expected identical.

Parameters:
code - The Coordinate Reference System authority code.
Returns:
The Coordinate Reference System for the provided code.
Throws:
org.opengis.referencing.NoSuchAuthorityCodeException - If the code could not be understood.
org.opengis.referencing.FactoryException - if the CRS creation failed for an other reason.
See Also:
getSupportedCodes(java.lang.String), AllAuthoritiesFactory.createCoordinateReferenceSystem(java.lang.String)

parseWKT

public static org.opengis.referencing.crs.CoordinateReferenceSystem parseWKT(java.lang.String wkt)
                                                                      throws org.opengis.referencing.FactoryException
Parses a Well Known Text (WKT) into a CRS object. This convenience method is a shorthand for the following:
FactoryFinder.getCRSFactory(null).createFromWKT(wkt);

Throws:
org.opengis.referencing.FactoryException

getEnvelope

public static org.opengis.spatialschema.geometry.Envelope getEnvelope(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Returns the valid area bounding box for the specified coordinate reference system, or if unknown. This method search in the metadata informations associated with the given CRS. The returned envelope is expressed in terms of the specified CRS.

Parameters:
crs - The coordinate reference system, or .
Returns:
The envelope in terms of the specified CRS, or if none.
Since:
2.2

getGeographicBoundingBox

public static org.opengis.metadata.extent.GeographicBoundingBox getGeographicBoundingBox(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Returns the valid geographic area for the specified coordinate reference system, or if unknown. This method search in the metadata informations associated with the given CRS.

Parameters:
crs - The coordinate reference system, or .
Returns:
The geographic area, or if none.
Since:
2.3


Copyright © GeoTools. All Rights Reserved.