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