001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2004, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * This package contains documentation from OpenGIS specifications.
018: * OpenGIS consortium's work is fully acknowledged here.
019: */
020: package org.geotools.referencing.operation;
021:
022: // J2SE dependencies
023: import java.util.Map;
024:
025: // OpenGIS dependencies
026: import org.opengis.referencing.crs.CoordinateReferenceSystem;
027: import org.opengis.referencing.operation.MathTransform;
028: import org.opengis.referencing.operation.OperationMethod;
029: import org.opengis.referencing.operation.MathTransform;
030: import org.opengis.referencing.operation.Conversion;
031: import org.opengis.referencing.operation.Projection;
032: import org.opengis.referencing.operation.PlanarProjection;
033: import org.opengis.referencing.operation.CylindricalProjection;
034: import org.opengis.referencing.operation.ConicProjection;
035:
036: /**
037: * An operation on coordinates that does not include any change of Datum. The best-known
038: * example of a coordinate conversion is a map projection. The parameters describing
039: * coordinate conversions are defined rather than empirically derived. Note that some
040: * conversions have no parameters.
041: *
042: * @since 2.1
043: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/operation/DefaultConversion.java $
044: * @version $Id: DefaultConversion.java 24384 2007-02-14 00:23:05Z desruisseaux $
045: * @author Martin Desruisseaux
046: *
047: * @see DefaultTransformation
048: */
049: public class DefaultConversion extends DefaultOperation implements
050: Conversion {
051: /**
052: * Serial number for interoperability with different versions.
053: */
054: private static final long serialVersionUID = -2148164324805562793L;
055:
056: /**
057: * Constructs a new conversion with the same values than the specified one, together with the
058: * specified source and target CRS. While the source conversion can be an arbitrary one, it is
059: * typically a {@linkplain DefiningConversion defining conversion}.
060: *
061: * @param definition The defining conversion.
062: * @param sourceCRS The source CRS.
063: * @param targetCRS The target CRS.
064: * @param transform Transform from positions in the {@linkplain #getSourceCRS source CRS}
065: * to positions in the {@linkplain #getTargetCRS target CRS}.
066: */
067: public DefaultConversion(final Conversion definition,
068: final CoordinateReferenceSystem sourceCRS,
069: final CoordinateReferenceSystem targetCRS,
070: final MathTransform transform) {
071: super (definition, sourceCRS, targetCRS, transform);
072: }
073:
074: /**
075: * Constructs a conversion from a set of properties. The properties given in argument
076: * follow the same rules than for the {@link AbstractCoordinateOperation} constructor.
077: *
078: * @param properties Set of properties. Should contains at least <code>"name"</code>.
079: * @param sourceCRS The source CRS.
080: * @param targetCRS The target CRS.
081: * @param transform Transform from positions in the {@linkplain #getSourceCRS source CRS}
082: * to positions in the {@linkplain #getTargetCRS target CRS}.
083: * @param method The operation method.
084: */
085: public DefaultConversion(final Map properties,
086: final CoordinateReferenceSystem sourceCRS,
087: final CoordinateReferenceSystem targetCRS,
088: final MathTransform transform, final OperationMethod method) {
089: super (properties, sourceCRS, targetCRS, transform, method);
090: }
091:
092: /**
093: * Returns a conversion from the specified {@linkplain DefiningConversion defining conversion}.
094: * This method may constructs instance of {@link DefaultPlanarProjection} or
095: * {@link DefaultCylindricalProjection} among others.
096: *
097: * @param definition The defining conversion.
098: * @param sourceCRS The source CRS.
099: * @param targetCRS The target CRS.
100: * @param transform Transform from positions in the {@linkplain #getSourceCRS source CRS}
101: * to positions in the {@linkplain #getTargetCRS target CRS}.
102: *
103: * @see DefaultOperation#create
104: *
105: * @deprecated Replaced by {@link #create(Conversion, CoordinateReferenceSystem,
106: * CoordinateReferenceSystem, MathTransform, Class)}.
107: */
108: public static Conversion create(final Conversion definition,
109: final CoordinateReferenceSystem sourceCRS,
110: final CoordinateReferenceSystem targetCRS,
111: final MathTransform transform) {
112: return create(definition, sourceCRS, targetCRS, transform, null);
113: }
114:
115: /**
116: * Returns a conversion from the specified {@linkplain DefiningConversion defining conversion}.
117: * The new conversion will be a more specific type like a {@linkplain PlanarProjection planar},
118: * {@linkplain CylindricalProjection cylindrical} or {@linkplain ConicProjection conic
119: * projection}. This type is inferred from the {@code conversion} argument when possible.
120: * However the inferred type is not always the most accurate one, so an optional
121: * {@code typeHint} argument may be specified in order to get a more specific subclass.
122: * This later argument is just a hint: it may be {@code null} and will be ignored if it
123: * conflict with the automatically inferred type.
124: *
125: * @param definition The defining conversion.
126: * @param sourceCRS The source CRS.
127: * @param targetCRS The target CRS.
128: * @param transform Transform from positions in the {@linkplain #getSourceCRS source CRS}
129: * to positions in the {@linkplain #getTargetCRS target CRS}.
130: * @param typeHint One of <code>{@linkplain PlanarProjection}.class</code>,
131: * <code>{@linkplain CylindricalProjection}.class</code> or
132: * <code>{@linkplain ConicProjection}.class</code>, or {@code null}.
133: *
134: * @see DefaultOperation#create
135: *
136: * @since 2.4
137: */
138: public static Conversion create(final Conversion definition,
139: final CoordinateReferenceSystem sourceCRS,
140: final CoordinateReferenceSystem targetCRS,
141: final MathTransform transform,
142: final Class/*<? extends Conversion>*/typeHint) {
143: Class type = getType(definition);
144: final OperationMethod method = definition.getMethod();
145: if (method instanceof MathTransformProvider) {
146: final Class candidate = ((MathTransformProvider) method)
147: .getOperationType();
148: if (candidate != null) {
149: if (type.isAssignableFrom(candidate)) {
150: type = candidate;
151: }
152: }
153: }
154: if (typeHint != null && type.isAssignableFrom(typeHint)) {
155: type = typeHint;
156: }
157: if (ConicProjection.class.isAssignableFrom(type)) {
158: return new DefaultConicProjection(definition, sourceCRS,
159: targetCRS, transform);
160: }
161: if (CylindricalProjection.class.isAssignableFrom(type)) {
162: return new DefaultCylindricalProjection(definition,
163: sourceCRS, targetCRS, transform);
164: }
165: if (PlanarProjection.class.isAssignableFrom(type)) {
166: return new DefaultPlanarProjection(definition, sourceCRS,
167: targetCRS, transform);
168: }
169: if (Projection.class.isAssignableFrom(type)) {
170: return new DefaultProjection(definition, sourceCRS,
171: targetCRS, transform);
172: }
173: return new DefaultConversion(definition, sourceCRS, targetCRS,
174: transform);
175: }
176: }
|