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.AffineCS;
029: import org.opengis.referencing.cs.AxisDirection;
030: import org.opengis.referencing.cs.CoordinateSystemAxis;
031:
032: /**
033: * A two- or three-dimensional coordinate system with straight axes that are not necessarily
034: * orthogonal. An {@code AffineCS} shall have two or three {@linkplain #getAxis axis}.
035: *
036: * <TABLE CELLPADDING='6' BORDER='1'>
037: * <TR BGCOLOR="#EEEEFF"><TH NOWRAP>Used with CRS type(s)</TH></TR>
038: * <TR><TD>
039: * {@link org.geotools.referencing.crs.DefaultEngineeringCRS Engineering},
040: * {@link org.geotools.referencing.crs.DefaultImageCRS Image}
041: * </TD></TR></TABLE>
042: *
043: * @since 2.1
044: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/cs/DefaultAffineCS.java $
045: * @version $Id: DefaultAffineCS.java 24683 2007-03-06 06:02:15Z desruisseaux $
046: * @author Martin Desruisseaux
047: *
048: * @see DefaultCartesianCS
049: */
050: public class DefaultAffineCS extends AbstractCS implements AffineCS {
051: /**
052: * Serial number for interoperability with different versions.
053: */
054: private static final long serialVersionUID = 7977674229369042440L;
055:
056: /**
057: * Constructs a new coordinate system with the same values than the specified one.
058: * This copy constructor provides a way to wrap an arbitrary implementation into a
059: * Geotools one or a user-defined one (as a subclass), usually in order to leverage
060: * some implementation-specific API. This constructor performs a shallow copy,
061: * i.e. the properties are not cloned.
062: *
063: * @since 2.2
064: */
065: public DefaultAffineCS(final AffineCS cs) {
066: super (cs);
067: }
068:
069: /**
070: * Constructs a two-dimensional coordinate system from a name.
071: *
072: * @param name The coordinate system name.
073: * @param axis0 The first axis.
074: * @param axis1 The second axis.
075: */
076: public DefaultAffineCS(final String name,
077: final CoordinateSystemAxis axis0,
078: final CoordinateSystemAxis axis1) {
079: super (name, new CoordinateSystemAxis[] { axis0, axis1 });
080: }
081:
082: /**
083: * Constructs a three-dimensional coordinate system from a name.
084: *
085: * @param name The coordinate system name.
086: * @param axis0 The first axis.
087: * @param axis1 The second axis.
088: * @param axis2 The third axis.
089: */
090: public DefaultAffineCS(final String name,
091: final CoordinateSystemAxis axis0,
092: final CoordinateSystemAxis axis1,
093: final CoordinateSystemAxis axis2) {
094: super (name, new CoordinateSystemAxis[] { axis0, axis1, axis2 });
095: }
096:
097: /**
098: * Constructs a two-dimensional coordinate system from a set of properties.
099: * The properties map is given unchanged to the
100: * {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class constructor}.
101: *
102: * @param properties Set of properties. Should contains at least <code>"name"</code>.
103: * @param axis0 The first axis.
104: * @param axis1 The second axis.
105: */
106: public DefaultAffineCS(final Map properties,
107: final CoordinateSystemAxis axis0,
108: final CoordinateSystemAxis axis1) {
109: super (properties, new CoordinateSystemAxis[] { axis0, axis1 });
110: }
111:
112: /**
113: * Constructs a three-dimensional coordinate system from a set of properties.
114: * The properties map is given unchanged to the superclass constructor.
115: *
116: * @param properties Set of properties. Should contains at least <code>"name"</code>.
117: * @param axis0 The first axis.
118: * @param axis1 The second axis.
119: * @param axis2 The third axis.
120: */
121: public DefaultAffineCS(final Map properties,
122: final CoordinateSystemAxis axis0,
123: final CoordinateSystemAxis axis1,
124: final CoordinateSystemAxis axis2) {
125: super (properties, new CoordinateSystemAxis[] { axis0, axis1,
126: axis2 });
127: }
128:
129: /**
130: * For {@link #usingUnit} and {@link PredefinedCS#rightHanded} usage only.
131: */
132: DefaultAffineCS(final Map properties,
133: final CoordinateSystemAxis[] axis) {
134: super (properties, axis);
135: }
136:
137: /**
138: * Returns {@code true} if the specified axis direction is allowed for this coordinate
139: * system. The default implementation accepts all directions except temporal ones (i.e.
140: * {@link AxisDirection#FUTURE FUTURE} and {@link AxisDirection#PAST PAST}).
141: */
142: protected boolean isCompatibleDirection(
143: final AxisDirection direction) {
144: return !AxisDirection.FUTURE.equals(direction.absolute());
145: }
146:
147: /**
148: * Returns {@code true} if the specified unit is compatible with {@linkplain SI#METER meters}.
149: * In addition, this method also accepts {@link Unit#ONE}, which is used for coordinates in a
150: * grid. This method is invoked at construction time for checking units compatibility.
151: *
152: * @since 2.2
153: */
154: protected boolean isCompatibleUnit(final AxisDirection direction,
155: final Unit unit) {
156: return SI.METER.isCompatible(unit) || Unit.ONE.equals(unit);
157: // Note: this condition is also coded in PredefinedCS.rightHanded(AffineCS).
158: }
159:
160: // TODO: Uncomment when we will be allowed to compile for J2SE 1.5
161: /*
162: * Returns a new coordinate system with the same properties than the current one except for
163: * axis units.
164: *
165: * @param unit The unit for the new axis.
166: * @return A coordinate system with axis using the specified units.
167: * @throws IllegalArgumentException If the specified unit is incompatible with the expected one.
168: *
169: * @since 2.5
170: *
171: public DefaultAffineCS usingUnit(final Unit unit) throws IllegalArgumentException {
172: final CoordinateSystemAxis[] axis = axisUsingUnit(unit);
173: if (axis == null) {
174: return this;
175: }
176: return new DefaultAffineCS(getProperties(this, null), axis);
177: }
178: */
179: }
|