001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/cs/PrimeMeridian.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.units.Unit; 058 059 /** 060 * A meridian used to take longitude measurements from. 061 * 062 * @version 1.00 063 * @author OpenGIS (www.opengis.org) 064 * @author Martin Desruisseaux 065 * 066 * @author last edited by: $Author: bezema $ 067 * 068 * @version $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $ 069 * 070 * @see "org.opengis.cs.CS_PrimeMeridian" 071 */ 072 public class PrimeMeridian extends Info { 073 /** 074 * Serial number for interoperability with different versions. 075 */ 076 private static final long serialVersionUID = 7570594768127669147L; 077 078 /** 079 * The Greenwich meridian, with angular measures in degrees. 080 */ 081 public static final PrimeMeridian GREENWICH = (PrimeMeridian) pool.intern( new PrimeMeridian( 082 "Greenwich", 083 Unit.DEGREE, 084 0 ) ); 085 086 /** 087 * The angular units. 088 */ 089 private final Unit unit; 090 091 /** 092 * The longitude value relative to the Greenwich Meridian. 093 */ 094 private final double longitude; 095 096 /** 097 * Creates a prime meridian, relative to Greenwich. 098 * 099 * @param name 100 * Name to give new object. 101 * @param unit 102 * Angular units of longitude. 103 * @param longitude 104 * Longitude of prime meridian in supplied angular units East of Greenwich. 105 * 106 */ 107 public PrimeMeridian( final String name, final Unit unit, final double longitude ) { 108 super( name ); 109 this.unit = unit; 110 this.longitude = longitude; 111 ensureNonNull( "unit", unit ); 112 ensureAngularUnit( unit ); 113 } 114 115 /** 116 * Creates a prime meridian, relative to Greenwich. 117 * 118 * @param properties 119 * The set of properties (see {@link Info}). 120 * @param unit 121 * Angular units of longitude. 122 * @param longitude 123 * Longitude of prime meridian in supplied angular units East of Greenwich. 124 */ 125 PrimeMeridian( final Map properties, final Unit unit, final double longitude ) { 126 super( properties ); 127 this.unit = unit; 128 this.longitude = longitude; 129 // Accept null values. 130 } 131 132 /** 133 * Returns the longitude value relative to the Greenwich Meridian. The longitude is expressed in 134 * this objects angular units. 135 * 136 * @return the longitude value relative to the Greenwich Meridian. The longitude is expressed in 137 * this objects angular units. 138 * 139 * @see "org.opengis.cs.CS_PrimeMeridian#getLongitude()" 140 */ 141 public double getLongitude() { 142 return longitude; 143 } 144 145 /** 146 * Returns the longitude value relative to the Greenwich Meridian, expressed in the specified 147 * units. This convenience method make easier to obtains longitude in degrees (<code>getLongitude(Unit.DEGREE)</code>), 148 * no matter the underlying angular units of this prime meridian. 149 * 150 * @param targetUnit 151 * The unit in which to express longitude. 152 * @return the longitude value relative to the Greenwich Meridian, expressed in the specified 153 * units. This convenience method make easier to obtains longitude in degrees (<code>getLongitude(Unit.DEGREE)</code>), 154 * no matter the underlying angular units of this prime meridian. 155 */ 156 public double getLongitude( final Unit targetUnit ) { 157 return targetUnit.convert( getLongitude(), getAngularUnit() ); 158 } 159 160 /** 161 * Returns the angular units. 162 * 163 * @return the angular units. 164 * 165 * @see "org.opengis.cs.CS_PrimeMeridian#getAngularUnit()" 166 */ 167 public Unit getAngularUnit() { 168 return unit; 169 } 170 171 /** 172 * Returns a hash value for this prime meridian. 173 * 174 * @return a hash value for this prime meridian. 175 */ 176 public int hashCode() { 177 final long code = Double.doubleToLongBits( longitude ); 178 return super.hashCode() * 37 + ( (int) ( code >>> 32 ) ^ (int) code ); 179 } 180 181 /** 182 * Compares the specified object with this prime meridian for equality. 183 * 184 * @return 185 */ 186 public boolean equals( final Object object ) { 187 if ( super.equals( object ) ) { 188 final PrimeMeridian that = (PrimeMeridian) object; 189 return Double.doubleToLongBits( this.longitude ) == Double.doubleToLongBits( that.longitude ) 190 && Utilities.equals( this.unit, that.unit ); 191 } 192 return false; 193 } 194 195 /** 196 * Fill the part inside "[...]". Used for formatting Well Know Text (WKT). 197 * 198 * @param buffer 199 * @return 200 */ 201 String addString( final StringBuffer buffer ) { 202 buffer.append( ", " ); 203 buffer.append( Unit.DEGREE.convert( longitude, unit ) ); 204 return "PRIMEM"; 205 } 206 207 }