001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/cs/HorizontalDatum.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2007 by:
006     EXSE, Department of Geography, University of Bonn
007     http://www.giub.uni-bonn.de/exse/
008     lat/lon GmbH
009     http://www.lat-lon.de
010    
011     It has been implemented within SEAGIS - An OpenSource implementation of OpenGIS specification
012     (C) 2001, Institut de Recherche pour le D�veloppement (http://sourceforge.net/projects/seagis/)
013     SEAGIS Contacts:  Surveillance de l'Environnement Assist�e par Satellite
014     Institut de Recherche pour le D�veloppement / US-Espace
015     mailto:seasnet@teledetection.fr
016    
017    
018     This library is free software; you can redistribute it and/or
019     modify it under the terms of the GNU Lesser General Public
020     License as published by the Free Software Foundation; either
021     version 2.1 of the License, or (at your option) any later version.
022    
023     This library is distributed in the hope that it will be useful,
024     but WITHOUT ANY WARRANTY; without even the implied warranty of
025     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
026     Lesser General Public License for more details.
027    
028     You should have received a copy of the GNU Lesser General Public
029     License along with this library; if not, write to the Free Software
030     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031    
032     Contact:
033    
034     Andreas Poth
035     lat/lon GmbH
036     Aennchenstr. 19
037     53115 Bonn
038     Germany
039     E-Mail: poth@lat-lon.de
040    
041     Klaus Greve
042     Department of Geography
043     University of Bonn
044     Meckenheimer Allee 166
045     53115 Bonn
046     Germany
047     E-Mail: klaus.greve@uni-bonn.de
048    
049     
050     ---------------------------------------------------------------------------*/
051    package org.deegree.model.csct.cs;
052    
053    // OpenGIS dependencies
054    import java.util.Map;
055    
056    import org.deegree.model.csct.resources.Utilities;
057    
058    /**
059     * Procedure used to measure positions on the surface of the Earth.
060     * 
061     * @version 1.00
062     * @author OpenGIS (www.opengis.org)
063     * @author Martin Desruisseaux
064     * 
065     * @author last edited by: $Author: apoth $
066     * 
067     * @version $Revision: 7056 $, $Date: 2007-05-10 09:27:49 +0200 (Do, 10 Mai 2007) $
068     * 
069     * @see "org.opengis.cs.CS_HorizontalDatum"
070     */
071    public class HorizontalDatum extends Datum {
072        /**
073         * Serial number for interoperability with different versions.
074         */
075        private static final long serialVersionUID = -1424482162002300865L;
076    
077        /**
078         * The default WGS 1984 datum.
079         */
080        public static final HorizontalDatum WGS84 = (HorizontalDatum) pool.intern( new HorizontalDatum(
081                                                                                                        "WGS84",
082                                                                                                        DatumType.GEOCENTRIC,
083                                                                                                        Ellipsoid.WGS84,
084                                                                                                        null ) );
085    
086        /**
087         * The ellipsoid for this datum.
088         */
089        private final Ellipsoid ellipsoid;
090    
091        /**
092         * Preferred parameters for a Bursa Wolf transformation.
093         */
094        private final WGS84ConversionInfo parameters;
095    
096        /**
097         * Creates horizontal datum from an ellipsoid. The datum type will be
098         * {@link DatumType.Horizontal#OTHER}.
099         * 
100         * @param name
101         *            Name to give new object.
102         * @param ellipsoid
103         *            Ellipsoid to use in new horizontal datum.
104         */
105        public HorizontalDatum( final String name, final Ellipsoid ellipsoid ) {
106            this( name, DatumType.Horizontal.OTHER, ellipsoid, null );
107        }
108    
109        /**
110         * Creates horizontal datum from ellipsoid and Bursa-Wolf parameters.
111         * 
112         * @param name
113         *            Name to give new object.
114         * @param type
115         *            Type of horizontal datum to create.
116         * @param ellipsoid
117         *            Ellipsoid to use in new horizontal datum.
118         * @param parameters
119         *            Suggested approximate conversion from new datum to WGS84, or <code>null</code>
120         *            if there is none.
121         * 
122         */
123        public HorizontalDatum( final String name, final DatumType.Horizontal type,
124                                final Ellipsoid ellipsoid, final WGS84ConversionInfo parameters ) {
125            super( name, type );
126            this.ellipsoid = ellipsoid;
127            this.parameters = ( parameters != null ) ? (WGS84ConversionInfo) parameters.clone() : null;
128            ensureNonNull( "ellipsoid", ellipsoid );
129        }
130    
131        /**
132         * Creates horizontal datum from ellipsoid and Bursa-Wolf parameters.
133         * 
134         * @param properties
135         *            The set of properties (see {@link Info}).
136         * @param type
137         *            Type of horizontal datum to create.
138         * @param ellipsoid
139         *            Ellipsoid to use in new horizontal datum.
140         * @param parameters
141         *            Suggested approximate conversion from new datum to WGS84, or <code>null</code>
142         *            if there is none.
143         */
144        HorizontalDatum( final Map properties, final DatumType type, final Ellipsoid ellipsoid,
145                         final WGS84ConversionInfo parameters ) {
146            super( properties, type );
147            this.ellipsoid = ellipsoid;
148            this.parameters = parameters;
149            // Accept null values.
150        }
151    
152        /**
153         * Gets the type of the datum as an enumerated code.
154         * 
155         * Note: return type will be changed to {@link DatumType.Horizontal} when we will be able to use
156         * generic types (with JDK 1.5).
157         * 
158         * @return
159         * 
160         * @see "org.opengis.cs.CS_HorizontalDatum#getDatumType()"
161         */
162        public DatumType/* .Horizontal */getDatumType() {
163            return super.getDatumType();
164        }
165    
166        /**
167         * Returns the ellipsoid.
168         * 
169         * @return the ellipsoid.
170         * 
171         * @see "org.opengis.cs.CS_HorizontalDatum#getEllipsoid()"
172         */
173        public Ellipsoid getEllipsoid() {
174            return ellipsoid;
175        }
176    
177        /**
178         * Gets preferred parameters for a Bursa Wolf transformation into WGS84. The 7 returned values
179         * correspond to (dx,dy,dz) in meters, (ex,ey,ez) in arc-seconds, and scaling in
180         * parts-per-million. This method will always returns <code>null</code> for horizontal datums
181         * with type {@link DatumType.Horizontal#OTHER}. This method may also returns <code>null</code>
182         * if no suitable transformation is available.
183         * 
184         * @return
185         * 
186         * @see "org.opengis.cs.CS_HorizontalDatum#getWGS84Parameters()"
187         */
188        public WGS84ConversionInfo getWGS84Parameters() {
189            return ( parameters != null ) ? (WGS84ConversionInfo) parameters.clone() : null;
190        }
191    
192        /**
193         * Fill the part inside "[...]". Used for formatting Well Know Text (WKT).
194         * 
195         * @param buffer
196         * @return
197         */
198        String addString( final StringBuffer buffer ) {
199            super.addString( buffer );
200            buffer.append( ", " );
201            buffer.append( ellipsoid );
202            if ( parameters != null ) {
203                buffer.append( ", " );
204                buffer.append( parameters );
205            }
206            return "DATUM";
207        }
208    
209        /**
210         * Compares the specified object with this datum for equality.
211         * 
212         * @param object
213         * @return
214         */
215        public boolean equals( final Object object ) {
216            if ( super.equals( object ) ) {
217                final HorizontalDatum that = (HorizontalDatum) object;
218                return Utilities.equals( this.ellipsoid, that.ellipsoid )
219                       && Utilities.equals( this.parameters, that.parameters );
220            }
221            return false;
222        }
223    
224    }