org.deegree_impl.model.ct
Class CoordinateTransformationFactory

java.lang.Object
  extended byorg.deegree_impl.model.ct.CoordinateTransformationFactory

public class CoordinateTransformationFactory
extends java.lang.Object

Creates coordinate transformations.

Version:
1.0
Author:
OpenGIS (www.opengis.org), Martin Desruisseaux
See Also:
CT_CoordinateTransformationFactory

Nested Class Summary
private  class CoordinateTransformationFactory.Export
          Wrap a CoordinateTransformationFactory for use with OpenGIS.
 
Field Summary
private static CoordinateTransformationFactory DEFAULT
          The default coordinate transformation factory.
private  MathTransformFactory factory
          The underlying math transform factory.
private static int temporaryID
          Number for temporary created objects.
 
Constructor Summary
CoordinateTransformationFactory(MathTransformFactory factory)
          Construct a coordinate transformation factory.
 
Method Summary
private  CoordinateTransformation concatenate(CoordinateTransformation step1, CoordinateTransformation step2)
          Concatenate two transformation steps.
private  CoordinateTransformation concatenate(CoordinateTransformation step1, CoordinateTransformation step2, CoordinateTransformation step3)
          Concatenate three transformation steps.
 CoordinateTransformation createFromCoordinateSystems(CoordinateSystem sourceCS, CoordinateSystem targetCS)
          Creates a transformation between two coordinate systems.
private static CoordinateTransformation createFromMathTransform(CoordinateSystem sourceCS, CoordinateSystem targetCS, TransformType type, MathTransform transform)
          Create a coordinate transform from a math transform.
protected  CoordinateTransformation createTransformationStep(CompoundCoordinateSystem sourceCS, CompoundCoordinateSystem targetCS)
          Creates a transformation between two compound coordinate systems.
protected  CoordinateTransformation createTransformationStep(CompoundCoordinateSystem sourceCS, GeocentricCoordinateSystem targetCS)
          Creates a transformation between a compound and a geocentric coordinate systems.
protected  CoordinateTransformation createTransformationStep(GeocentricCoordinateSystem sourceCS, GeocentricCoordinateSystem targetCS)
          Creates a transformation between two geocentric coordinate systems.
protected  CoordinateTransformation createTransformationStep(GeographicCoordinateSystem sourceCS, GeocentricCoordinateSystem targetCS)
          Creates a transformation between a geographic and a geocentric coordinate systems.
protected  CoordinateTransformation createTransformationStep(GeographicCoordinateSystem sourceCS, GeographicCoordinateSystem targetCS)
          Creates a transformation between two geographic coordinate systems.
protected  CoordinateTransformation createTransformationStep(GeographicCoordinateSystem sourceCS, ProjectedCoordinateSystem targetCS)
          Creates a transformation between a geographic and a projected coordinate systems.
private  CoordinateTransformation createTransformationStep(ProjectedCoordinateSystem sourceCS, GeocentricCoordinateSystem targetCS)
          Creates a transformation between a projected and a geocentric coordinate systems.
protected  CoordinateTransformation createTransformationStep(ProjectedCoordinateSystem sourceCS, GeographicCoordinateSystem targetCS)
          Creates a transformation between a projected and a geographic coordinate systems.
protected  CoordinateTransformation createTransformationStep(ProjectedCoordinateSystem sourceCS, ProjectedCoordinateSystem targetCS)
          Creates a transformation between two projected coordinate systems.
protected  CoordinateTransformation createTransformationStep(TemporalCoordinateSystem sourceCS, TemporalCoordinateSystem targetCS)
          Creates a transformation between two temporal coordinate systems.
protected  CoordinateTransformation createTransformationStep(VerticalCoordinateSystem sourceCS, VerticalCoordinateSystem targetCS)
          Creates a transformation between two vertical coordinate systems.
private static AxisOrientation[] getAxisOrientations(CoordinateSystem cs, Dimensioned dim)
          Returns the axis orientation for the specified coordinate system.
static CoordinateTransformationFactory getDefault()
          Returns the default coordinate transformation factory.
private  MathTransform getGeocentricTransform(java.lang.String classification, int dimGeoCS, Ellipsoid ellipsoid)
          Returns a transform between a geocentric coordinate system and an ellipsoid.
private  CoordinateTransformation getGeographicTransformation(CoordinateSystem CS)
          Returns a transformation from CS to a geographic coordinate system.
 MathTransformFactory getMathTransformFactory()
          Returns the underlying math transform factory.
private static java.lang.String getTemporaryName(CoordinateSystem source)
          Returns a temporary name for generated objects.
private static Matrix getWGS84Parameters(HorizontalDatum datum)
          Returns the WGS84 parameters as an affine transform, or null if not available.
private static boolean hasStandardAxis(HorizontalCoordinateSystem cs, Unit unit)
          Returns true if the specified coordinate system use standard axis and standard units.
private static GeographicCoordinateSystem normalize(GeographicCoordinateSystem cs, Projection projection)
          Makes sure that the specified GeographicCoordinateSystem use standard axis (longitude and latitude in degrees), Greenwich prime meridian and an ellipsoid matching projection's parameters.
private static ProjectedCoordinateSystem normalize(ProjectedCoordinateSystem cs)
          Makes sure that a ProjectedCoordinateSystem use standard axis (x and y in metres) and a normalized GeographicCoordinateSystem.
private  Matrix swapAndScaleAxis(CoordinateSystem sourceCS, CoordinateSystem targetCS)
          Returns an affine transform between two coordinate systems.
private  Matrix swapAndScaleGeoAxis(GeographicCoordinateSystem sourceCS, GeographicCoordinateSystem targetCS)
          Returns an affine transform between two geographic coordinate systems.
(package private)  java.lang.Object toOpenGIS(java.lang.Object adapters)
          Returns an OpenGIS interface for this transform factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

private static CoordinateTransformationFactory DEFAULT
The default coordinate transformation factory. Will be constructed only when first needed.


temporaryID

private static volatile int temporaryID
Number for temporary created objects. This number is incremented each time getTemporaryName(org.deegree_impl.model.cs.CoordinateSystem) is invoked.


factory

private final MathTransformFactory factory
The underlying math transform factory.

Constructor Detail

CoordinateTransformationFactory

public CoordinateTransformationFactory(MathTransformFactory factory)
Construct a coordinate transformation factory.

Parameters:
factory - The math transform factory to use.
Method Detail

getDefault

public static CoordinateTransformationFactory getDefault()
Returns the default coordinate transformation factory.


getMathTransformFactory

public final MathTransformFactory getMathTransformFactory()
Returns the underlying math transform factory. This factory is used for constructing MathTransform objects for all CoordinateTransformation.


createFromCoordinateSystems

public CoordinateTransformation createFromCoordinateSystems(CoordinateSystem sourceCS,
                                                            CoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between two coordinate systems. This method will examine the coordinate systems in order to construct a transformation between them. This method may fail if no path between the coordinate systems is found.

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(TemporalCoordinateSystem sourceCS,
                                                            TemporalCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between two temporal coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...). The default implementation checks if both coordinate systems use the same datum, and then adjusts for axis orientation, units and epoch.

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(VerticalCoordinateSystem sourceCS,
                                                            VerticalCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between two vertical coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...). The default implementation checks if both coordinate systems use the same datum, and then adjusts for axis orientation and units.

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(GeographicCoordinateSystem sourceCS,
                                                            GeographicCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between two geographic coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...). The default implementation can adjust axis order and orientation (e.g. transforming from (NORTH,WEST) to (EAST,NORTH)), performs units conversion and apply Bursa Wolf transformation if needed.

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(ProjectedCoordinateSystem sourceCS,
                                                            ProjectedCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between two projected coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...). The default implementation can adjust axis order and orientation. It also performs units conversion if it is the only extra change needed. Otherwise, it performs three steps:
  1. Unproject sourceCS.
  2. Transform from sourceCS.geographicCS to targetCS.geographicCS.
  3. Project targetCS.

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(GeographicCoordinateSystem sourceCS,
                                                            ProjectedCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between a geographic and a projected coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...).

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(ProjectedCoordinateSystem sourceCS,
                                                            GeographicCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between a projected and a geographic coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...). The default implementation returns createTransformationStep(targetCS, sourceCS).inverse().

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(GeocentricCoordinateSystem sourceCS,
                                                            GeocentricCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between two geocentric coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...). The default implementation can adjust for axis order and orientation, adjust for prime meridian, performs units conversion and apply Bursa Wolf transformation if needed.

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(GeographicCoordinateSystem sourceCS,
                                                            GeocentricCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between a geographic and a geocentric coordinate systems. Since the source coordinate systems doesn't have a vertical axis, height above the ellipsoid is assumed equals to zero everywhere. This method is automatically invoked by createFromCoordinateSystems(...).

Parameters:
sourceCS - Input geographic coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

private CoordinateTransformation createTransformationStep(ProjectedCoordinateSystem sourceCS,
                                                          GeocentricCoordinateSystem targetCS)
                                                   throws CannotCreateTransformException
Creates a transformation between a projected and a geocentric coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...). This method doesn't need to be public since its decomposition in two step should be general enough.

Parameters:
sourceCS - Input projected coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(CompoundCoordinateSystem sourceCS,
                                                            GeocentricCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between a compound and a geocentric coordinate systems. The compound coordinate system must be an aggregate of the two following coordinate systems: This method is automatically invoked by createFromCoordinateSystems(...).

Parameters:
sourceCS - Input compound coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

createTransformationStep

protected CoordinateTransformation createTransformationStep(CompoundCoordinateSystem sourceCS,
                                                            CompoundCoordinateSystem targetCS)
                                                     throws CannotCreateTransformException
Creates a transformation between two compound coordinate systems. This method is automatically invoked by createFromCoordinateSystems(...).

Parameters:
sourceCS - Input coordinate system.
targetCS - Output coordinate system.
Returns:
A coordinate transformation from sourceCS to targetCS.
Throws:
CannotCreateTransformException - if no transformation path has been found.

getWGS84Parameters

private static Matrix getWGS84Parameters(HorizontalDatum datum)
Returns the WGS84 parameters as an affine transform, or null if not available.


getGeocentricTransform

private MathTransform getGeocentricTransform(java.lang.String classification,
                                             int dimGeoCS,
                                             Ellipsoid ellipsoid)
Returns a transform between a geocentric coordinate system and an ellipsoid.

Parameters:
classification - either "Ellipsoid_To_Geocentric" or "Geocentric_To_Ellipsoid".
dimGeoCS - Dimension of the geographic coordinate system (2 or 3).
ellipsoid - The ellipsoid.
Returns:
The transformation.

getGeographicTransformation

private CoordinateTransformation getGeographicTransformation(CoordinateSystem CS)
                                                      throws CannotCreateTransformException
Returns a transformation from CS to a geographic coordinate system. If CS is already an instance of {GeographicCoordinateSystem}, then this method returns the identity transform. Otherwise, if CS is an instance of ProjectedCoordinateSystem, then this method returns an inverse map projection. Otherwise, this method returns null.

Throws:
CannotCreateTransformException - if the transform can't be created.

concatenate

private CoordinateTransformation concatenate(CoordinateTransformation step1,
                                             CoordinateTransformation step2)
Concatenate two transformation steps.

Parameters:
step1 - The first step, or null for the identity transform.
step2 - The second step, or null for the identity transform.
Returns:
A concatenated transform, or null if all arguments was nul.

concatenate

private CoordinateTransformation concatenate(CoordinateTransformation step1,
                                             CoordinateTransformation step2,
                                             CoordinateTransformation step3)
Concatenate three transformation steps.

Parameters:
step1 - The first step, or null for the identity transform.
step2 - The second step, or null for the identity transform.
step3 - The third step, or null for the identity transform.
Returns:
A concatenated transform, or null if all arguments was nul.

createFromMathTransform

private static CoordinateTransformation createFromMathTransform(CoordinateSystem sourceCS,
                                                                CoordinateSystem targetCS,
                                                                TransformType type,
                                                                MathTransform transform)
Create a coordinate transform from a math transform. If the specified math transform is already a coordinate transform, and if source and target coordinate systems match, then transform is returned with no change. Otherwise, a new coordinate transform is created.

Parameters:
sourceCS - The source coordinate system.
targetCS - The destination coordinate system.
type - The transform type.
transform - The math transform.
Returns:
A coordinate transform using the specified math transform.

swapAndScaleAxis

private Matrix swapAndScaleAxis(CoordinateSystem sourceCS,
                                CoordinateSystem targetCS)
                         throws CannotCreateTransformException
Returns an affine transform between two coordinate systems. Only units and axis order (e.g. transforming from (NORTH,WEST) to (EAST,NORTH)) are taken in account. Other attributes (especially the datum) must be checked before invoking this method.

Parameters:
sourceCS - The source coordinate system. If null, then (x,y,z,t) axis order is assumed.
targetCS - The target coordinate system. If null, then (x,y,z,t) axis order is assumed.
Throws:
CannotCreateTransformException

swapAndScaleGeoAxis

private Matrix swapAndScaleGeoAxis(GeographicCoordinateSystem sourceCS,
                                   GeographicCoordinateSystem targetCS)
                            throws CannotCreateTransformException
Returns an affine transform between two geographic coordinate systems. Only units, axis order (e.g. transforming from (NORTH,WEST) to (EAST,NORTH)) and prime meridian are taken in account. Other attributes (especially the datum) must be checked before invoking this method.

Parameters:
sourceCS - The source coordinate system.
targetCS - The target coordinate system.
Throws:
CannotCreateTransformException

getAxisOrientations

private static AxisOrientation[] getAxisOrientations(CoordinateSystem cs,
                                                     Dimensioned dim)
Returns the axis orientation for the specified coordinate system. If cs is null, then an array of length dim.getDimension() is created and filled with (x,y,z,t) axis orientations.


normalize

private static GeographicCoordinateSystem normalize(GeographicCoordinateSystem cs,
                                                    Projection projection)
Makes sure that the specified GeographicCoordinateSystem use standard axis (longitude and latitude in degrees), Greenwich prime meridian and an ellipsoid matching projection's parameters. If cs already meets all those conditions, then it is returned unchanged. Otherwise, a new normalized geographic coordinate system is created and returned.


normalize

private static ProjectedCoordinateSystem normalize(ProjectedCoordinateSystem cs)
Makes sure that a ProjectedCoordinateSystem use standard axis (x and y in metres) and a normalized GeographicCoordinateSystem. If cs already meets all those conditions, then it is returned unchanged. Otherwise, a new normalized projected coordinate system is created and returned.


hasStandardAxis

private static boolean hasStandardAxis(HorizontalCoordinateSystem cs,
                                       Unit unit)
Returns true if the specified coordinate system use standard axis and standard units.

Parameters:
cs - The coordinate system to test.

getTemporaryName

private static java.lang.String getTemporaryName(CoordinateSystem source)
Returns a temporary name for generated objects. The first object has a name like "Temporary-1", the second is "Temporary-2", etc.

Parameters:
source - The coordinate system to base name on, or null if none.

toOpenGIS

final java.lang.Object toOpenGIS(java.lang.Object adapters)
Returns an OpenGIS interface for this transform factory. The returned object is suitable for RMI use. Note: The returned type is a generic Object in order to avoid too early class loading of OpenGIS interface.