001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/cs/VerticalCoordinateSystem.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 import org.deegree.model.csct.units.Unit; 060 061 /** 062 * A one-dimensional coordinate system suitable for vertical measurements. 063 * 064 * @version 1.00 065 * @author OpenGIS (www.opengis.org) 066 * @author Martin Desruisseaux 067 * 068 * @author last edited by: $Author: bezema $ 069 * 070 * @version $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $ 071 * 072 * @see "org.opengis.cs.CS_VerticalCoordinateSystem" 073 */ 074 public class VerticalCoordinateSystem extends CoordinateSystem { 075 /** 076 * Serial number for interoperability with different versions. 077 */ 078 private static final long serialVersionUID = -8629573233560414552L; 079 080 /** 081 * Default vertical coordinate system using ellipsoidal datum. Ellipsoidal heights are measured 082 * along the normal to the ellipsoid used in the definition of horizontal datum. 083 */ 084 public static final VerticalCoordinateSystem ELLIPSOIDAL = (VerticalCoordinateSystem) pool.intern( new VerticalCoordinateSystem( 085 "Ellipsoidal", 086 VerticalDatum.ELLIPSOIDAL ) ); 087 088 /** 089 * The vertical datum. 090 */ 091 private final VerticalDatum datum; 092 093 /** 094 * Units used along the vertical axis. 095 */ 096 private final Unit unit; 097 098 /** 099 * Axis details for vertical dimension within coordinate system. 100 */ 101 private final AxisInfo axis; 102 103 /** 104 * Creates a vertical coordinate system from a datum. Units will be metres and values will be 105 * increasing upward. 106 * 107 * @param name 108 * Name to give new object. 109 * @param datum 110 * Datum to use for new coordinate system. 111 */ 112 public VerticalCoordinateSystem( final String name, final VerticalDatum datum ) { 113 this( name, datum, Unit.METRE, AxisInfo.ALTITUDE ); 114 } 115 116 /** 117 * Creates a vertical coordinate system from a datum and linear units. 118 * 119 * @param name 120 * Name to give new object. 121 * @param datum 122 * Datum to use for new coordinate system. 123 * @param unit 124 * Units to use for new coordinate system. 125 * @param axis 126 * Axis to use for new coordinate system. 127 * 128 */ 129 public VerticalCoordinateSystem( final String name, final VerticalDatum datum, final Unit unit, 130 final AxisInfo axis ) { 131 super( name ); 132 this.datum = datum; 133 this.unit = unit; 134 this.axis = axis; 135 ensureNonNull( "datum", datum ); 136 ensureNonNull( "unit", unit ); 137 ensureNonNull( "axis", axis ); 138 ensureLinearUnit( unit ); 139 checkAxis( datum.getDatumType() ); 140 } 141 142 /** 143 * Creates a vertical coordinate system from a datum and linear units. 144 * 145 * @param properties 146 * The set of properties (see {@link Info}). 147 * @param datum 148 * Datum to use for new coordinate system. 149 * @param unit 150 * Units to use for new coordinate system. 151 * @param axis 152 * Axis to use for new coordinate system. 153 */ 154 VerticalCoordinateSystem( final Map properties, final VerticalDatum datum, final Unit unit, 155 final AxisInfo axis ) { 156 super( properties ); 157 this.datum = datum; 158 this.unit = unit; 159 this.axis = axis; 160 // Accept null values. 161 } 162 163 /** 164 * Returns the dimension of this coordinate system, which is 1. 165 * 166 * @return the dimension of this coordinate system, which is 1. 167 * 168 * @see "org.opengis.cs.CS_VerticalCoordinateSystem#getDimension()" 169 */ 170 public final int getDimension() { 171 return 1; 172 } 173 174 /** 175 * Override {@link CoordinateSystem#getDatum()}. 176 */ 177 final Datum getDatum() { 178 return getVerticalDatum(); 179 } 180 181 /** 182 * Gets the vertical datum, which indicates the measurement method. 183 * 184 * @return the vertical datum, which indicates the measurement method. 185 * 186 * @see "org.opengis.cs.CS_VerticalCoordinateSystem#getVerticalDatum()" 187 */ 188 public VerticalDatum getVerticalDatum() { 189 return datum; 190 } 191 192 /** 193 * Gets axis details for vertical dimension within coordinate system. A vertical coordinate 194 * system have only one axis, always at index 0. 195 * 196 * @param dimension 197 * Zero based index of axis. 198 * @return axis details for vertical dimension within coordinate system. A vertical coordinate 199 * system have only one axis, always at index 0. 200 * 201 * @see "org.opengis.cs.CS_VerticalCoordinateSystem#getAxis(int)" 202 */ 203 public AxisInfo getAxis( final int dimension ) { 204 final int maxDim = getDimension(); 205 if ( dimension >= 0 && dimension < maxDim ) 206 return axis; 207 throw new IndexOutOfBoundsException( 208 Resources.format( 209 ResourceKeys.ERROR_INDEX_OUT_OF_BOUNDS_$1, 210 new Integer( dimension ) ) ); 211 } 212 213 /** 214 * Gets units for dimension within coordinate system. A vertical coordinate system have only one 215 * unit, always at index 0. 216 * 217 * @param dimension 218 * Must be 0. 219 * @return units for dimension within coordinate system. A vertical coordinate system have only 220 * one unit, always at index 0. 221 * 222 * @see "org.opengis.cs.CS_VerticalCoordinateSystem#getUnits(int)" 223 * @see "org.opengis.cs.CS_VerticalCoordinateSystem#getVerticalUnit()" 224 */ 225 public Unit getUnits( final int dimension ) { 226 final int maxDim = getDimension(); 227 if ( dimension >= 0 && dimension < maxDim ) 228 return unit; 229 throw new IndexOutOfBoundsException( 230 Resources.format( 231 ResourceKeys.ERROR_INDEX_OUT_OF_BOUNDS_$1, 232 new Integer( dimension ) ) ); 233 } 234 235 /** 236 * Returns <code>true</code> if this coordinate system is equivalents to the specified 237 * coordinate system. Two coordinate systems are considered equivalent if the 238 * {@link org.deegree.model.csct.ct.CoordinateTransformation} from <code>this</code> to 239 * <code>cs</code> would be the identity transform. The default implementation compare datum, 240 * units and axis, but ignore name, alias and other meta-data informations. 241 * 242 * @param cs 243 * The coordinate system (may be <code>null</code>). 244 * @return <code>true</code> if both coordinate systems are equivalent. 245 */ 246 public boolean equivalents( final CoordinateSystem cs ) { 247 if ( cs == this ) 248 return true; 249 if ( super.equivalents( cs ) ) { 250 final VerticalCoordinateSystem that = (VerticalCoordinateSystem) cs; 251 return Utilities.equals( this.datum, that.datum ) 252 && Utilities.equals( this.unit, that.unit ) 253 && Utilities.equals( this.axis, that.axis ); 254 } 255 return false; 256 } 257 258 /** 259 * Fill the part inside "[...]". Used for formatting Well Know Text (WKT). 260 * 261 * @param buffer 262 * @return 263 */ 264 String addString( final StringBuffer buffer ) { 265 buffer.append( ", " ); 266 buffer.append( datum ); 267 buffer.append( ", " ); 268 addUnit( buffer, unit ); 269 buffer.append( ", " ); 270 buffer.append( axis ); 271 return "VERT_CS"; 272 } 273 274 }