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
023: import java.util.Map;
024:
025: // OpenGIS dependencies
026: import org.opengis.referencing.cs.VerticalCS;
027: import org.opengis.referencing.cs.AxisDirection;
028: import org.opengis.referencing.cs.CoordinateSystemAxis;
029: import org.opengis.geometry.MismatchedDimensionException;
030:
031: // Geotools dependencies
032: import org.geotools.measure.Measure;
033: import org.geotools.resources.i18n.VocabularyKeys;
034:
035: /**
036: * A one-dimensional coordinate system used to record the heights (or depths) of points. Such a
037: * coordinate system is usually dependent on the Earth's gravity field, perhaps loosely as when
038: * atmospheric pressure is the basis for the vertical coordinate system axis. An exact definition
039: * is deliberately not provided as the complexities of the subject fall outside the scope of this
040: * specification. A {@code VerticalCS} 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.DefaultVerticalCRS Vertical},
046: * {@link org.geotools.referencing.crs.DefaultEngineeringCRS Engineering}
047: * </TD></TR></TABLE>
048: *
049: * @since 2.1
050: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/cs/DefaultVerticalCS.java $
051: * @version $Id: DefaultVerticalCS.java 24925 2007-03-27 20:12:08Z jgarnett $
052: * @author Martin Desruisseaux
053: */
054: public class DefaultVerticalCS extends AbstractCS implements VerticalCS {
055: /**
056: * Serial number for interoperability with different versions.
057: */
058: private static final long serialVersionUID = 1201155778896630499L;;
059:
060: /**
061: * A one-dimensional vertical CS with
062: * <var>{@linkplain DefaultCoordinateSystemAxis#ELLIPSOIDAL_HEIGHT
063: * ellipsoidal height}</var> axis in metres.
064: */
065: public static DefaultVerticalCS ELLIPSOIDAL_HEIGHT = new DefaultVerticalCS(
066: name(VocabularyKeys.ELLIPSOIDAL_HEIGHT),
067: DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT);
068:
069: /**
070: * A one-dimensional vertical CS with
071: * <var>{@linkplain DefaultCoordinateSystemAxis#GRAVITY_RELATED_HEIGHT
072: * gravity-related height}</var> axis in metres.
073: */
074: public static DefaultVerticalCS GRAVITY_RELATED = new DefaultVerticalCS(
075: name(VocabularyKeys.GRAVITY_RELATED_HEIGHT),
076: DefaultCoordinateSystemAxis.GRAVITY_RELATED_HEIGHT);
077:
078: /**
079: * A one-dimensional vertical CS with
080: * <var>{@linkplain DefaultCoordinateSystemAxis#DEPTH depth}</var>
081: * axis in metres.
082: */
083: public static DefaultVerticalCS DEPTH = new DefaultVerticalCS(
084: name(VocabularyKeys.DEPTH),
085: DefaultCoordinateSystemAxis.DEPTH);
086:
087: /**
088: * Constructs a new coordinate system with the same values than the specified one.
089: * This copy constructor provides a way to wrap an arbitrary implementation into a
090: * Geotools one or a user-defined one (as a subclass), usually in order to leverage
091: * some implementation-specific API. This constructor performs a shallow copy,
092: * i.e. the properties are not cloned.
093: *
094: * @since 2.2
095: */
096: public DefaultVerticalCS(final VerticalCS cs) {
097: super (cs);
098: }
099:
100: /**
101: * Constructs a coordinate system from a name.
102: *
103: * @param name The coordinate system name.
104: * @param axis The axis.
105: */
106: public DefaultVerticalCS(final String name,
107: final CoordinateSystemAxis axis) {
108: super (name, new CoordinateSystemAxis[] { axis });
109: }
110:
111: /**
112: * Constructs a coordinate system from a set of properties. The properties map is given unchanged
113: * to the {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class constructor}.
114: *
115: * @param properties Set of properties. Should contains at least <code>"name"</code>.
116: * @param axis The axis.
117: */
118: public DefaultVerticalCS(final Map properties,
119: final CoordinateSystemAxis axis) {
120: super (properties, new CoordinateSystemAxis[] { axis });
121: }
122:
123: /**
124: * Returns {@code true} if the specified axis direction is allowed for this coordinate
125: * system. The default implementation accepts only vertical directions (i.e.
126: * {@link AxisDirection#UP UP} and {@link AxisDirection#DOWN DOWN}).
127: */
128: protected boolean isCompatibleDirection(
129: final AxisDirection direction) {
130: return AxisDirection.UP.equals(direction.absolute());
131: }
132:
133: /**
134: * Computes the distance between two points.
135: *
136: * @param coord1 Coordinates of the first point.
137: * @param coord2 Coordinates of the second point.
138: * @return The distance between {@code coord1} and {@code coord2}.
139: * @throws MismatchedDimensionException if a coordinate doesn't have the expected dimension.
140: */
141: public Measure distance(final double[] coord1, final double[] coord2)
142: throws MismatchedDimensionException {
143: ensureDimensionMatch("coord1", coord1);
144: ensureDimensionMatch("coord2", coord2);
145: return new Measure(Math.abs(coord1[0] - coord2[0]),
146: getDistanceUnit());
147: }
148: }
|