001: //$HeadURL: $
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.crs.coordinatesystems;
040:
041: import org.deegree.crs.Identifiable;
042: import org.deegree.crs.components.Axis;
043: import org.deegree.crs.projections.Projection;
044:
045: /**
046: * A <code>ProjectedCRS</code> is a coordinatesystem defined with a projection and a geographic crs. It allows for
047: * transformation between projected coordinates (mostly in meters) and the lat/lon coordinates of the geographic crs and
048: * vice versa.
049: *
050: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
051: *
052: * @author last edited by: $Author:$
053: *
054: * @version $Revision:$, $Date:$
055: *
056: */
057:
058: public class ProjectedCRS extends CoordinateSystem {
059:
060: private final GeographicCRS underlyingCRS;
061:
062: private Projection projection;
063:
064: /**
065: * @param projection
066: * the projection which converts coordinates from this ProjectedCRS into the underlying GeographicCRS and
067: * vice versa.
068: * @param axisOrder
069: * of this projection.
070: * @param identity
071: */
072: public ProjectedCRS(Projection projection, Axis[] axisOrder,
073: Identifiable identity) {
074: super (projection.getGeographicCRS().getGeodeticDatum(),
075: axisOrder, identity);
076: this .underlyingCRS = projection.getGeographicCRS();
077: this .projection = projection;
078: }
079:
080: /**
081: * @param projection
082: * the projection which converts coordinates from this ProjectedCRS into the underlying GeographicCRS and
083: * vice versa.
084: * @param axisOrder
085: * of this projection.
086: * @param identifiers
087: * @param names
088: * @param versions
089: * @param descriptions
090: * @param areasOfUse
091: */
092: public ProjectedCRS(Projection projection, Axis[] axisOrder,
093: String[] identifiers, String[] names, String[] versions,
094: String[] descriptions, String[] areasOfUse) {
095: super (projection.getGeographicCRS().getGeodeticDatum(),
096: axisOrder, identifiers, names, versions, descriptions,
097: areasOfUse);
098: this .underlyingCRS = projection.getGeographicCRS();
099: this .projection = projection;
100: }
101:
102: /**
103: *
104: * @param projection
105: * the projection which converts coordinates from this ProjectedCRS into the underlying GeographicCRS and
106: * vice versa.
107: * @param axisOrder
108: * of this projection.
109: * @param identifiers
110: */
111: public ProjectedCRS(Projection projection, Axis[] axisOrder,
112: String[] identifiers) {
113: this (projection, axisOrder, identifiers, null, null, null, null);
114: }
115:
116: /**
117: * @param projection
118: * the projection which converts coordinates from this ProjectedCRS into the underlying GeographicCRS and
119: * vice versa.
120: * @param axisOrder
121: * of this projection.
122: * @param identifier
123: * @param name
124: * @param version
125: * @param description
126: * @param areaOfUse
127: */
128: public ProjectedCRS(Projection projection, Axis[] axisOrder,
129: String identifier, String name, String version,
130: String description, String areaOfUse) {
131: this (projection, axisOrder, new String[] { identifier },
132: new String[] { name }, new String[] { version },
133: new String[] { description },
134: new String[] { areaOfUse });
135: }
136:
137: /**
138: *
139: * @param projection
140: * the projection which converts coordinates from this ProjectedCRS into the underlying GeographicCRS and
141: * vice versa.
142: * @param axisOrder
143: * of this projection.
144: * @param identifier
145: */
146: public ProjectedCRS(Projection projection, Axis[] axisOrder,
147: String identifier) {
148: this (projection, axisOrder, identifier, null, null, null, null);
149: }
150:
151: /*
152: * (non-Javadoc)
153: *
154: * @see org.deegree.crs.coordinatesystems.CoordinateSystem#getDimension()
155: */
156: @Override
157: public int getDimension() {
158: return getAxis().length;
159: }
160:
161: /**
162: * @return the underlyingCRS.
163: */
164: public final GeographicCRS getGeographicCRS() {
165: return underlyingCRS;
166: }
167:
168: @Override
169: public final int getType() {
170: return PROJECTED_CRS;
171: }
172:
173: /**
174: * @return the projection.
175: */
176: public final Projection getProjection() {
177: return projection;
178: }
179:
180: @Override
181: public boolean equals(Object other) {
182: if (other != null && other instanceof ProjectedCRS) {
183: final ProjectedCRS that = (ProjectedCRS) other;
184: return super .equals(that)
185: && this .projection.equals(that.projection);
186: }
187: return false;
188: }
189:
190: @Override
191: public String toString() {
192: StringBuilder sb = new StringBuilder(super .toString());
193: sb.append("\n - Projection: ").append(projection);
194: return sb.toString();
195: }
196:
197: /**
198: * Implementation as proposed by Joshua Block in Effective Java (Addison-Wesley 2001), which supplies an even
199: * distribution and is relatively fast. It is created from field <b>f</b> as follows:
200: * <ul>
201: * <li>boolean -- code = (f ? 0 : 1)</li>
202: * <li>byte, char, short, int -- code = (int)f </li>
203: * <li>long -- code = (int)(f ^ (f >>>32))</li>
204: * <li>float -- code = Float.floatToIntBits(f);</li>
205: * <li>double -- long l = Double.doubleToLongBits(f); code = (int)(l ^ (l >>> 32))</li>
206: * <li>all Objects, (where equals( ) calls equals( ) for this field) -- code = f.hashCode( )</li>
207: * <li>Array -- Apply above rules to each element</li>
208: * </ul>
209: * <p>
210: * Combining the hash code(s) computed above: result = 37 * result + code;
211: * </p>
212: *
213: * @return (int) ( result >>> 32 ) ^ (int) result;
214: *
215: * @see java.lang.Object#hashCode()
216: */
217: @Override
218: public int hashCode() {
219: // the 2nd millionth prime, :-)
220: long code = 32452843;
221: code = code * 37 + super .hashCode();
222: if (projection != null) {
223: code = code * 37 + projection.hashCode();
224: }
225:
226: return (int) (code >>> 32) ^ (int) code;
227: }
228: }
|