001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2001, 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.crs;
021:
022: // J2SE dependencies
023: import java.util.Map;
024:
025: // OpenGIS dependencies
026: import org.opengis.referencing.cs.CoordinateSystem;
027: import org.opengis.referencing.cs.CoordinateSystemAxis;
028: import org.opengis.referencing.crs.SingleCRS;
029: import org.opengis.referencing.datum.Datum;
030:
031: // Geotools dependencies
032: import org.geotools.referencing.AbstractIdentifiedObject;
033: import org.geotools.referencing.AbstractReferenceSystem;
034: import org.geotools.referencing.wkt.Formatter;
035:
036: /**
037: * Abstract coordinate reference system, consisting of a single
038: * {@linkplain CoordinateSystem coordinate system} and a single
039: * {@linkplain Datum datum} (as opposed to {@linkplain DefaultCompoundCRS compound CRS}).
040: * <p>
041: * A coordinate reference system consists of an ordered sequence of coordinate system
042: * axes that are related to the earth through a datum. A coordinate reference system
043: * is defined by one datum and by one coordinate system. Most coordinate reference system
044: * do not move relative to the earth, except for engineering coordinate reference systems
045: * defined on moving platforms such as cars, ships, aircraft, and spacecraft.
046: * <p>
047: * Coordinate reference systems are commonly divided into sub-types. The common classification
048: * criterion for sub-typing of coordinate reference systems is the way in which they deal with
049: * earth curvature. This has a direct effect on the portion of the earth's surface that can be
050: * covered by that type of CRS with an acceptable degree of error. The exception to the rule is
051: * the subtype "Temporal" which has been added by analogy.
052: * <p>
053: * This class is conceptually <cite>abstract</cite>, even if it is technically possible to
054: * instantiate it. Typical applications should create instances of the most specific subclass with
055: * {@code Default} prefix instead. An exception to this rule may occurs when it is not possible to
056: * identify the exact type.
057: *
058: * @since 2.1
059: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/crs/AbstractSingleCRS.java $
060: * @version $Id: AbstractSingleCRS.java 24609 2007-02-26 23:35:53Z desruisseaux $
061: * @author Martin Desruisseaux
062: *
063: * @see org.geotools.referencing.cs.AbstractCS
064: * @see org.geotools.referencing.datum.AbstractDatum
065: */
066: public class AbstractSingleCRS extends AbstractCRS implements SingleCRS {
067: /**
068: * Serial number for interoperability with different versions.
069: */
070: private static final long serialVersionUID = 1815712797774273L;
071:
072: /**
073: * The datum.
074: */
075: protected final Datum datum;
076:
077: /**
078: * Constructs a new coordinate reference system with the same values than the specified one.
079: * This copy constructor provides a way to wrap an arbitrary implementation into a
080: * Geotools one or a user-defined one (as a subclass), usually in order to leverage
081: * some implementation-specific API. This constructor performs a shallow copy,
082: * i.e. the properties are not cloned.
083: *
084: * @since 2.2
085: */
086: public AbstractSingleCRS(final SingleCRS crs) {
087: super (crs);
088: datum = crs.getDatum();
089: }
090:
091: /**
092: * Constructs a coordinate reference system from a set of properties. The properties are given
093: * unchanged to the {@linkplain AbstractReferenceSystem#AbstractReferenceSystem(Map) super-class
094: * constructor}.
095: *
096: * @param properties Set of properties. Should contains at least <code>"name"</code>.
097: * @param datum The datum.
098: * @param cs The coordinate system.
099: */
100: public AbstractSingleCRS(final Map properties, final Datum datum,
101: final CoordinateSystem cs) {
102: super (properties, cs);
103: this .datum = datum;
104: ensureNonNull("datum", datum);
105: }
106:
107: /**
108: * Returns the datum.
109: *
110: * @return The datum.
111: */
112: public Datum getDatum() {
113: return datum;
114: }
115:
116: /**
117: * Returns the dimension of the underlying {@linkplain CoordinateSystem coordinate system}.
118: * This is equivalent to <code>{@linkplain #coordinateSystem}.{@linkplain
119: * CoordinateSystem#getDimension getDimension}()</code>.
120: *
121: * @return The dimension of this coordinate reference system.
122: */
123: public int getDimension() {
124: return coordinateSystem.getDimension();
125: }
126:
127: /**
128: * Returns the axis for the underlying {@linkplain CoordinateSystem coordinate system} at
129: * the specified dimension. This is equivalent to
130: * <code>{@linkplain #coordinateSystem}.{@linkplain CoordinateSystem#getAxis getAxis}(dimension)</code>.
131: *
132: * @param dimension The zero based index of axis.
133: * @return The axis at the specified dimension.
134: * @throws IndexOutOfBoundsException if {@code dimension} is out of bounds.
135: */
136: public CoordinateSystemAxis getAxis(int dimension)
137: throws IndexOutOfBoundsException {
138: return coordinateSystem.getAxis(dimension);
139: }
140:
141: /**
142: * Compare this coordinate reference system with the specified object for equality.
143: * If {@code compareMetadata} is {@code true}, then all available properties are
144: * compared including {@linkplain #getValidArea valid area} and {@linkplain #getScope scope}.
145: *
146: * @param object The object to compare to {@code this}.
147: * @param compareMetadata {@code true} for performing a strict comparaison, or
148: * {@code false} for comparing only properties relevant to transformations.
149: * @return {@code true} if both objects are equal.
150: */
151: public boolean equals(final AbstractIdentifiedObject object,
152: final boolean compareMetadata) {
153: if (super .equals(object, compareMetadata)) {
154: final AbstractSingleCRS that = (AbstractSingleCRS) object;
155: return equals(this .datum, that.datum, compareMetadata);
156: }
157: return false;
158: }
159:
160: /**
161: * Returns a hash value for this CRS. {@linkplain #getName Name},
162: * {@linkplain #getIdentifiers identifiers} and {@linkplain #getRemarks remarks}
163: * are not taken in account. In other words, two CRS objects will return the same
164: * hash value if they are equal in the sense of
165: * <code>{@link #equals(AbstractIdentifiedObject,boolean) equals}(AbstractIdentifiedObject,
166: * <strong>false</strong>)</code>.
167: *
168: * @return The hash code value. This value doesn't need to be the same
169: * in past or future versions of this class.
170: */
171: public int hashCode() {
172: return super .hashCode() ^ datum.hashCode();
173: }
174:
175: /**
176: * {@inheritDoc}
177: */
178: //@Override
179: final void formatDefaultWKT(final Formatter formatter) {
180: formatter.append(datum);
181: super.formatDefaultWKT(formatter);
182: }
183: }
|