001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/cs/HorizontalCoordinateSystem.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001 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 import org.deegree.model.csct.resources.css.ResourceKeys;
058 import org.deegree.model.csct.resources.css.Resources;
059
060 /**
061 * A 2D coordinate system suitable for positions on the Earth's surface.
062 *
063 * @version 1.00
064 * @author OpenGIS (www.opengis.org)
065 * @author Martin Desruisseaux
066 *
067 * @author last edited by: $Author: bezema $
068 *
069 * @version $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
070 *
071 * @see "org.opengis.cs.CS_HorizontalCoordinateSystem"
072 */
073 public abstract class HorizontalCoordinateSystem extends CoordinateSystem {
074 /**
075 * Serial number for interoperability with different versions.
076 */
077 private static final long serialVersionUID = 350661821531782559L;
078
079 /**
080 * The horizontal datum.
081 */
082 private final HorizontalDatum datum;
083
084 /**
085 * Details of 0th ordinates.
086 */
087 private final AxisInfo axis0;
088
089 /**
090 * Details of 1th ordinates.
091 */
092 private final AxisInfo axis1;
093
094 /**
095 * Construct a coordinate system.
096 *
097 * @param name
098 * The coordinate system name.
099 * @param datum
100 * The horizontal datum.
101 * @param axis0
102 * Details of 0th ordinates in created coordinate system.
103 * @param axis1
104 * Details of 1st ordinates in created coordinate system.
105 */
106 public HorizontalCoordinateSystem( final String name, final HorizontalDatum datum,
107 final AxisInfo axis0, final AxisInfo axis1 ) {
108 super( name );
109 this.datum = datum;
110 this.axis0 = axis0;
111 this.axis1 = axis1;
112 ensureNonNull( "datum", datum );
113 ensureNonNull( "axis0", axis0 );
114 ensureNonNull( "axis1", axis1 );
115 checkAxis( datum.getDatumType() );
116 }
117
118 /**
119 * Construct a coordinate system.
120 *
121 * @param properties
122 * The set of properties (see {@link Info}).
123 * @param datum
124 * The horizontal datum.
125 * @param axis0
126 * Details of 0th ordinates in created coordinate system.
127 * @param axis1
128 * Details of 1st ordinates in created coordinate system.
129 */
130 HorizontalCoordinateSystem( final Map properties, final HorizontalDatum datum,
131 final AxisInfo axis0, final AxisInfo axis1 ) {
132 super( properties );
133 this.datum = datum;
134 this.axis0 = axis0;
135 this.axis1 = axis1;
136 // Accept null values
137 }
138
139 /**
140 * Returns the dimension of this coordinate system, which is 2.
141 *
142 * @return the dimension of this coordinate system, which is 2.
143 *
144 * @see "org.opengis.cs.CS_HorizontalCoordinateSystem#getDimension()"
145 */
146 public final int getDimension() {
147 return 2;
148 }
149
150 /**
151 * Override {@link CoordinateSystem#getDatum()}.
152 */
153 final Datum getDatum() {
154 return getHorizontalDatum();
155 }
156
157 /**
158 * Returns the horizontal datum.
159 *
160 * @return the horizontal datum.
161 *
162 * @see "org.opengis.cs.CS_HorizontalCoordinateSystem#getHorizontalDatum()"
163 */
164 public HorizontalDatum getHorizontalDatum() {
165 return datum;
166 }
167
168 /**
169 * Gets axis details for dimension within coordinate system.
170 *
171 * @param dimension
172 * Zero based index of axis.
173 * @return
174 *
175 * @see "org.opengis.cs.CS_HorizontalCoordinateSystem#getAxis(int)"
176 */
177 public AxisInfo getAxis( final int dimension ) {
178 switch ( dimension ) {
179 case 0:
180 return axis0;
181 case 1:
182 return axis1;
183 default:
184 throw new IndexOutOfBoundsException(
185 Resources.format(
186 ResourceKeys.ERROR_INDEX_OUT_OF_BOUNDS_$1,
187 new Integer( dimension ) ) );
188 }
189 }
190
191 /**
192 * Returns <code>true</code> if this coordinate system is equivalents to the specified
193 * coordinate system. Two coordinate systems are considered equivalent if the
194 * {@link org.deegree.model.csct.ct.CoordinateTransformation} from <code>this</code> to
195 * <code>cs</code> would be the identity transform. The default implementation compare datum,
196 * units and axis, but ignore name, alias and other meta-data informations.
197 *
198 * @param cs
199 * The coordinate system (may be <code>null</code>).
200 * @return <code>true</code> if both coordinate systems are equivalent.
201 */
202 public boolean equivalents( final CoordinateSystem cs ) {
203 if ( cs == this )
204 return true;
205 if ( super.equivalents( cs ) ) {
206 final HorizontalCoordinateSystem that = (HorizontalCoordinateSystem) cs;
207 return Utilities.equals( this.datum, that.datum )
208 && Utilities.equals( this.axis0, that.axis0 )
209 && Utilities.equals( this.axis1, that.axis1 );
210 }
211 return false;
212 }
213
214 /**
215 * Fill the part inside "[...]". Used for formatting Well Know Text (WKT).
216 *
217 * @param buffer
218 * @return
219 */
220 String addString( final StringBuffer buffer ) {
221 buffer.append( ", " );
222 buffer.append( datum );
223 buffer.append( ", " );
224 buffer.append( axis0 );
225 buffer.append( ", " );
226 buffer.append( axis1 );
227 return "HORZ_CS";
228 }
229
230 }