001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2004, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * This package contains documentation from OpenGIS specifications.
018: * OpenGIS consortium's work is fully acknowledged here.
019: */
020: package org.geotools.referencing.cs;
021:
022: // J2SE dependencies and extensions
023: import java.util.Map;
024: import javax.units.SI;
025: import javax.units.Unit;
026:
027: // OpenGIS dependencies
028: import org.opengis.referencing.cs.TimeCS;
029: import org.opengis.referencing.cs.AxisDirection;
030: import org.opengis.referencing.cs.CoordinateSystemAxis;
031: import org.opengis.geometry.MismatchedDimensionException;
032:
033: // Geotools dependencies
034: import org.geotools.measure.Measure;
035: import org.geotools.resources.i18n.VocabularyKeys;
036:
037: /**
038: * A one-dimensional coordinate system containing a single time axis, used to describe the
039: * temporal position of a point in the specified time units from a specified time origin.
040: * A {@code TimeCS} shall have one {@linkplain #getAxis axis}.
041: *
042: * <TABLE CELLPADDING='6' BORDER='1'>
043: * <TR BGCOLOR="#EEEEFF"><TH NOWRAP>Used with CRS type(s)</TH></TR>
044: * <TR><TD>
045: * {@link org.geotools.referencing.crs.DefaultTemporalCRS Temporal}
046: * </TD></TR></TABLE>
047: *
048: * @since 2.1
049: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/cs/DefaultTimeCS.java $
050: * @version $Id: DefaultTimeCS.java 24925 2007-03-27 20:12:08Z jgarnett $
051: * @author Martin Desruisseaux
052: */
053: public class DefaultTimeCS extends AbstractCS implements TimeCS {
054: /**
055: * Serial number for interoperability with different versions.
056: */
057: private static final long serialVersionUID = 5222911412381303989L;
058:
059: /**
060: * A one-dimensional temporal CS with
061: * <var>{@linkplain DefaultCoordinateSystemAxis#TIME time}</var>,
062: * axis in days.
063: */
064: public static DefaultTimeCS DAYS = new DefaultTimeCS(
065: name(VocabularyKeys.TEMPORAL),
066: DefaultCoordinateSystemAxis.TIME);
067:
068: /**
069: * Constructs a new coordinate system with the same values than the specified one.
070: * This copy constructor provides a way to wrap an arbitrary implementation into a
071: * Geotools one or a user-defined one (as a subclass), usually in order to leverage
072: * some implementation-specific API. This constructor performs a shallow copy,
073: * i.e. the properties are not cloned.
074: *
075: * @since 2.2
076: */
077: public DefaultTimeCS(final TimeCS cs) {
078: super (cs);
079: }
080:
081: /**
082: * Constructs a coordinate system from a name.
083: *
084: * @param name The coordinate system name.
085: * @param axis The axis.
086: */
087: public DefaultTimeCS(final String name,
088: final CoordinateSystemAxis axis) {
089: super (name, new CoordinateSystemAxis[] { axis });
090: ensureTimeUnit(getAxis(0).getUnit());
091: }
092:
093: /**
094: * Constructs a coordinate system from a set of properties.
095: * The properties map is given unchanged to the
096: * {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class constructor}.
097: *
098: * @param properties Set of properties. Should contains at least <code>"name"</code>.
099: * @param axis The axis.
100: */
101: public DefaultTimeCS(final Map properties,
102: final CoordinateSystemAxis axis) {
103: super (properties, new CoordinateSystemAxis[] { axis });
104: ensureTimeUnit(getAxis(0).getUnit());
105: }
106:
107: /**
108: * Returns {@code true} if the specified axis direction is allowed for this coordinate
109: * system. The default implementation accepts only temporal directions (i.e.
110: * {@link AxisDirection#FUTURE FUTURE} and {@link AxisDirection#PAST PAST}).
111: */
112: protected boolean isCompatibleDirection(
113: final AxisDirection direction) {
114: return AxisDirection.FUTURE.equals(direction.absolute());
115: }
116:
117: /**
118: * Returns {@code true} if the specified unit is compatible with {@linkplain SI#SECOND seconds}.
119: * This method is invoked at construction time for checking units compatibility.
120: *
121: * @since 2.2
122: */
123: protected boolean isCompatibleUnit(final AxisDirection direction,
124: final Unit unit) {
125: return SI.SECOND.isCompatible(unit);
126: }
127:
128: /**
129: * Computes the time difference between two points.
130: *
131: * @param coord1 Coordinates of the first point.
132: * @param coord2 Coordinates of the second point.
133: * @return The time difference between {@code coord1} and {@code coord2}.
134: * @throws MismatchedDimensionException if a coordinate doesn't have the expected dimension.
135: */
136: public Measure distance(final double[] coord1, final double[] coord2)
137: throws MismatchedDimensionException {
138: ensureDimensionMatch("coord1", coord1);
139: ensureDimensionMatch("coord2", coord2);
140: return new Measure(Math.abs(coord1[0] - coord2[0]),
141: getDistanceUnit());
142: }
143: }
|