001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/cs/TemporalCoordinateSystem.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    // Time
054    import java.util.Date;
055    import java.util.Map;
056    
057    
058    import org.deegree.model.csct.resources.Utilities;
059    import org.deegree.model.csct.resources.css.ResourceKeys;
060    import org.deegree.model.csct.resources.css.Resources;
061    import org.deegree.model.csct.units.Unit;
062    
063    
064    /**
065     * A one-dimensional coordinate system suitable for time measurements.
066     *
067     * @version 1.0
068     * @author Martin Desruisseaux
069     */
070    public class TemporalCoordinateSystem extends CoordinateSystem
071    {
072        /**
073         * Serial number for interoperability with different versions.
074         */
075        private static final long serialVersionUID = 4436983518157910233L;
076    
077        /**
078         * The temporal datum.
079         */
080        private final TemporalDatum datum;
081    
082        /**
083         * Axis details for time dimension within coordinate system.
084         */
085        private final AxisInfo axis;
086    
087        /**
088         * Units used along the time axis.
089         */
090        private final Unit unit;
091    
092        /**
093         * The epoch, in milliseconds since January 1, 1970, 00:00:00 UTC.
094         */
095        private final long epoch;
096    
097        /**
098         * Creates a temporal coordinate system. Datum is UTC,
099         * units are days and values are increasing toward future.
100         *
101         * @param name  Name  to give new object.
102         * @param epoch The epoch (i.e. date of origin).
103         */
104        public TemporalCoordinateSystem(final String name, final Date epoch)
105        {this(name, TemporalDatum.UTC, Unit.DAY, epoch, AxisInfo.TIME);}
106    
107        /**
108         * Creates a temporal coordinate system from a datum and time units.
109         *
110         * @param name  Name  to give new object.
111         * @param datum Datum to use for new coordinate system.
112         * @param unit  Units to use for new coordinate system.
113         * @param epoch The epoch (i.e. date of origin).
114         * @param axis  Axis  to use for new coordinate system.
115         */
116        public TemporalCoordinateSystem(final String name, final TemporalDatum datum, final Unit unit, final Date epoch, final AxisInfo axis)
117        {
118            super(name);
119            ensureNonNull("datum", datum);
120            ensureNonNull("unit",  unit );
121            ensureNonNull("epoch", epoch);
122            ensureNonNull("axis",  axis );
123            this.datum    = datum;
124            this.unit     = unit;
125            this.epoch    = epoch.getTime();
126            this.axis     = axis;
127            ensureTimeUnit(unit);
128            checkAxis(datum.getDatumType());
129        }
130    
131        /**
132         * Creates a temporal coordinate system from a datum and time units.
133         *
134         * @param properties The set of properties (see {@link Info}).
135         * @param datum Datum to use for new coordinate system.
136         * @param unit  Units to use for new coordinate system.
137         * @param epoch The epoch (i.e. date of origin).
138         * @param axis  Axis  to use for new coordinate system.
139         */
140        TemporalCoordinateSystem(final Map properties, final TemporalDatum datum, final Unit unit, final Date epoch, final AxisInfo axis)
141        {
142            super(properties);
143            this.datum = datum;
144            this.unit  = unit;
145            this.epoch = epoch.getTime();
146            this.axis  = axis;
147            // Accept null values.
148        }
149    
150        /**
151         * Returns the dimension of this coordinate system, which is 1.
152         */
153        public final int getDimension()
154        {return 1;}
155    
156        /**
157         * Override {@link CoordinateSystem#getDatum()}.
158         */
159        final Datum getDatum()
160        {return getTemporalDatum();}
161    
162        /**
163         * Gets the temporal datum, which indicates the measurement method.
164         */
165        public TemporalDatum getTemporalDatum()
166        {return datum;}
167    
168        /**
169         * Returns the epoch. The epoch is the origin of
170         * the time axis, i.e. the date for value zero.
171         */
172        public Date getEpoch()
173        {return new Date(epoch);}
174    
175        /**
176         * Gets axis details for temporal dimension within coordinate system.
177         * A temporal coordinate system have only one axis, always at index 0.
178         *
179         * @param dimension Zero based index of axis.
180         */
181        public AxisInfo getAxis(final int dimension)
182        {
183            final int maxDim = getDimension();
184            if (dimension>=0 && dimension<maxDim) return axis;
185            throw new IndexOutOfBoundsException(Resources.format(ResourceKeys.ERROR_INDEX_OUT_OF_BOUNDS_$1, new Integer(dimension)));
186        }
187    
188        /**
189         * Gets units for dimension within coordinate system.
190         * A temporal coordinate system have only one unit,
191         * always at index 0.
192         *
193         * @param dimension Must be 0.
194         */
195        public Unit getUnits(final int dimension)
196        {
197            final int maxDim = getDimension();
198            if (dimension>=0 && dimension<maxDim) return unit;
199            throw new IndexOutOfBoundsException(Resources.format(ResourceKeys.ERROR_INDEX_OUT_OF_BOUNDS_$1, new Integer(dimension)));
200        }
201    
202        /**
203         * Returns  <code>true</code> if this coordinate system is equivalents to
204         * the specified coordinate system. Two coordinate systems are considered
205         * equivalent if the {@link org.deegree.model.csct.ct.CoordinateTransformation} from
206         * <code>this</code> to <code>cs</code> would be the identity transform.
207         * The default implementation compare datum, units and axis, but ignore
208         * name, alias and other meta-data informations.
209         *
210         * @param  cs The coordinate system (may be <code>null</code>).
211         * @return <code>true</code> if both coordinate systems are equivalent.
212         */
213        public boolean equivalents(final CoordinateSystem cs)
214        {
215            if (cs==this) return true;
216            if (super.equivalents(cs))
217            {
218                final TemporalCoordinateSystem that = (TemporalCoordinateSystem) cs;
219                return Utilities.equals(this.datum, that.datum) &&
220                       Utilities.equals(this.unit , that.unit ) &&
221                       Utilities.equals(this.axis , that.axis );
222            }
223            return false;
224        }
225    
226        /**
227         * Fill the part inside "[...]".
228         * Used for formatting Well Know Text (WKT).
229         */
230        String addString(final StringBuffer buffer)
231        {
232            buffer.append(", ");
233            buffer.append(datum);
234            buffer.append(", ");
235            addUnit(buffer, unit);
236            buffer.append(", ");
237            buffer.append(axis);
238            return "TEMPORAL_CS";
239        }
240    }