001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/cs/LocalCoordinateSystem.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.Arrays; 055 import java.util.Map; 056 057 import org.deegree.model.csct.resources.Utilities; 058 import org.deegree.model.csct.units.Unit; 059 060 /** 061 * A local coordinate system, with uncertain relationship to the world. In general, a local 062 * coordinate system cannot be related to other coordinate systems. However, if two objects 063 * supporting this interface have the same dimension, axes, units and datum then client code is 064 * permitted to assume that the two coordinate systems are identical. This allows several datasets 065 * from a common source (e.g. a CAD system) to be overlaid. In addition, some implementations of the 066 * Coordinate Transformation (CT) package may have a mechanism for correlating local datums. (E.g. 067 * from a database of transformations, which is created and maintained from real-world 068 * measurements.) 069 * 070 * @version 1.00 071 * @author OpenGIS (www.opengis.org) 072 * @author Martin Desruisseaux 073 * 074 * @author last edited by: $Author: bezema $ 075 * 076 * @version $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $ 077 * 078 * @see "org.opengis.cs.CS_LocalCoordinateSystem" 079 */ 080 public class LocalCoordinateSystem extends CoordinateSystem { 081 /** 082 * Serial number for interoperability with different versions. 083 */ 084 private static final long serialVersionUID = -2067954038057402418L; 085 086 /** 087 * The local datum. 088 */ 089 private final LocalDatum datum; 090 091 /** 092 * Units used along all axis. 093 */ 094 private final Unit[] units; 095 096 /** 097 * Axes details. 098 */ 099 private final AxisInfo[] axes; 100 101 /** 102 * Creates a local coordinate system. The dimension of the local coordinate system is determined 103 * by the size of the axis array. All the axes will have the same units. If you want to make a 104 * coordinate system with mixed units, then you can make a compound coordinate system from 105 * different local coordinate systems. 106 * 107 * @param name 108 * Name to give new object. 109 * @param datum 110 * Local datum to use in created coordinate system. 111 * @param unit 112 * Units to use for all axes in created coordinate system. 113 * @param axes 114 * Axes to use in created coordinate system. 115 * 116 */ 117 public LocalCoordinateSystem( final String name, final LocalDatum datum, final Unit unit, 118 final AxisInfo[] axes ) { 119 super( name ); 120 ensureNonNull( "datum", datum ); 121 ensureNonNull( "unit", unit ); 122 ensureNonNull( "axes", axes ); 123 this.datum = datum; 124 this.units = new Unit[axes.length]; 125 this.axes = axes.clone(); 126 for ( int i = 0; i < this.axes.length; i++ ) { 127 this.units[i] = unit; 128 ensureNonNull( "axes", this.axes, i ); 129 } 130 checkAxis( datum.getDatumType() ); 131 } 132 133 /** 134 * Creates a local coordinate system. 135 * 136 * @param properties 137 * The set of properties (see {@link Info}). 138 * @param datum 139 * Local datum to use in created coordinate system. 140 * @param units 141 * Units to use in created coordinate system. 142 * @param axes 143 * Axes to use in created coordinate system. 144 */ 145 LocalCoordinateSystem( final Map properties, final LocalDatum datum, final Unit[] units, 146 final AxisInfo[] axes ) { 147 super( properties ); 148 this.datum = datum; 149 this.units = units; 150 this.axes = axes; 151 // Accept null values. 152 } 153 154 /** 155 * Override {@link CoordinateSystem#getDatum()}. 156 */ 157 final Datum getDatum() { 158 return getLocalDatum(); 159 } 160 161 /** 162 * Gets the local datum. 163 * 164 * @return the local datum. 165 * 166 * @see "org.opengis.cs.CS_LocalCoordinateSystem#getLocalDatum()" 167 */ 168 public LocalDatum getLocalDatum() { 169 return datum; 170 } 171 172 /** 173 * Dimension of the coordinate system. 174 * 175 * @return 176 * 177 * @see "org.opengis.cs.CS_LocalCoordinateSystem#getDimension()" 178 */ 179 public int getDimension() { 180 return axes.length; 181 } 182 183 /** 184 * Gets axis details for dimension within coordinate system. 185 * 186 * @param dimension 187 * Zero based index of axis. 188 * @return axis details for dimension within coordinate system. 189 * 190 * @see "org.opengis.cs.CS_LocalCoordinateSystem#getAxis(int)" 191 */ 192 public AxisInfo getAxis( final int dimension ) { 193 return axes[dimension]; 194 } 195 196 /** 197 * Gets units for dimension within coordinate system. 198 * 199 * @param dimension 200 * Zero based index of axis. 201 * @return units for dimension within coordinate system. 202 * 203 * @see "org.opengis.cs.CS_LocalCoordinateSystem#getUnits(int)" 204 */ 205 public Unit getUnits( final int dimension ) { 206 return units[dimension]; 207 } 208 209 /** 210 * Returns <code>true</code> if this coordinate system is equivalents to the specified 211 * coordinate system. Two coordinate systems are considered equivalent if the 212 * {@link org.deegree.model.csct.ct.CoordinateTransformation} from <code>this</code> to 213 * <code>cs</code> would be the identity transform. The default implementation compare datum, 214 * units and axis, but ignore name, alias and other meta-data informations. 215 * 216 * @param cs 217 * The coordinate system (may be <code>null</code>). 218 * @return <code>true</code> if both coordinate systems are equivalent. 219 */ 220 public boolean equivalents( final CoordinateSystem cs ) { 221 if ( cs == this ) 222 return true; 223 if ( super.equivalents( cs ) ) { 224 final LocalCoordinateSystem that = (LocalCoordinateSystem) cs; 225 return Utilities.equals( this.datum, that.datum ) 226 && Arrays.equals( this.units, that.units ) 227 && Arrays.equals( this.axes, that.axes ); 228 } 229 return false; 230 } 231 232 /** 233 * Fill the part inside "[...]". Used for formatting Well Know Text (WKT). 234 * 235 * @param buffer 236 * @return 237 */ 238 String addString( final StringBuffer buffer ) { 239 buffer.append( ", " ); 240 buffer.append( datum ); 241 buffer.append( ", " ); 242 addUnit( buffer, getUnits() ); 243 for ( int i = 0; i < axes.length; i++ ) { 244 buffer.append( ", " ); 245 buffer.append( axes[i] ); 246 } 247 return "LOCAL_CS"; 248 } 249 250 }