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.LinearCS;
027: import org.opengis.referencing.cs.CoordinateSystemAxis;
028: import org.opengis.geometry.MismatchedDimensionException;
029:
030: // Geotools dependencies
031: import org.geotools.measure.Measure;
032:
033: /**
034: * A one-dimensional coordinate system that consists of the points that lie on the single axis
035: * described. The associated ordinate is the distance from the specified origin to the point
036: * along the axis. Example: usage of the line feature representing a road to describe points
037: * on or along that road. A {@code LinearCS} shall have one
038: * {@linkplain #getAxis axis}.
039: *
040: * <TABLE CELLPADDING='6' BORDER='1'>
041: * <TR BGCOLOR="#EEEEFF"><TH NOWRAP>Used with CRS type(s)</TH></TR>
042: * <TR><TD>
043: * {@link org.geotools.referencing.crs.DefaultEngineeringCRS Engineering}
044: * </TD></TR></TABLE>
045: *
046: * @since 2.1
047: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/cs/DefaultLinearCS.java $
048: * @version $Id: DefaultLinearCS.java 24925 2007-03-27 20:12:08Z jgarnett $
049: * @author Martin Desruisseaux
050: */
051: public class DefaultLinearCS extends AbstractCS implements LinearCS {
052: /**
053: * Serial number for interoperability with different versions.
054: */
055: private static final long serialVersionUID = -6890723478287625763L;
056:
057: /**
058: * Constructs a new coordinate system with the same values than the specified one.
059: * This copy constructor provides a way to wrap an arbitrary implementation into a
060: * Geotools one or a user-defined one (as a subclass), usually in order to leverage
061: * some implementation-specific API. This constructor performs a shallow copy,
062: * i.e. the properties are not cloned.
063: *
064: * @since 2.2
065: */
066: public DefaultLinearCS(final LinearCS cs) {
067: super (cs);
068: }
069:
070: /**
071: * Constructs a coordinate system from a name.
072: *
073: * @param name The coordinate system name.
074: * @param axis The axis.
075: */
076: public DefaultLinearCS(final String name,
077: final CoordinateSystemAxis axis) {
078: super (name, new CoordinateSystemAxis[] { axis });
079: }
080:
081: /**
082: * Constructs a coordinate system from a set of properties.
083: * The properties map is given unchanged to the
084: * {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class constructor}.
085: *
086: * @param properties Set of properties. Should contains at least <code>"name"</code>.
087: * @param axis The axis.
088: */
089: public DefaultLinearCS(final Map properties,
090: final CoordinateSystemAxis axis) {
091: super (properties, new CoordinateSystemAxis[] { axis });
092: }
093:
094: /**
095: * Computes the distance between two points.
096: *
097: * @param coord1 Coordinates of the first point.
098: * @param coord2 Coordinates of the second point.
099: * @return The distance between {@code coord1} and {@code coord2}.
100: * @throws MismatchedDimensionException if a coordinate doesn't have the expected dimension.
101: */
102: public Measure distance(final double[] coord1, final double[] coord2)
103: throws MismatchedDimensionException {
104: ensureDimensionMatch("coord1", coord1);
105: ensureDimensionMatch("coord2", coord2);
106: return new Measure(Math.abs(coord1[0] - coord2[0]),
107: getDistanceUnit());
108: }
109: }
|