001: /*
002: * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
003: * Copyright (C) 2006 - JScience (http://jscience.org/)
004: * All rights reserved.
005: *
006: * Permission to use, copy, modify, and distribute this software is
007: * freely granted, provided that this notice is preserved.
008: */
009: package org.jscience.geography.coordinates.crs;
010:
011: import java.util.Collection;
012: import java.util.Set;
013:
014: import javax.measure.quantity.Angle;
015: import javax.measure.quantity.Duration;
016: import javax.measure.quantity.Length;
017: import javax.measure.Measurable;
018: import javax.measure.unit.Unit;
019:
020: import javolution.util.FastSet;
021:
022: import org.jscience.geography.coordinates.Coordinates;
023: import org.opengis.metadata.Identifier;
024: import org.opengis.metadata.citation.Citation;
025: import org.opengis.metadata.extent.Extent;
026: import org.opengis.referencing.cs.AxisDirection;
027: import org.opengis.referencing.cs.CoordinateSystem;
028: import org.opengis.util.InternationalString;
029: import org.opengis.referencing.cs.CoordinateSystemAxis;
030:
031: /**
032: * This class represents an arbitrary system of reference for which
033: * {@link Coordinates coordinates} of same significance can be stated.
034: *
035: * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
036: * @version 3.0, February 13, 2006
037: */
038: public abstract class CoordinateReferenceSystem<C extends Coordinates<?>>
039: implements
040: org.opengis.referencing.crs.CoordinateReferenceSystem {
041:
042: /**
043: * This class represents an absolute position (can be be extended)
044: */
045: protected static class AbsolutePosition {
046:
047: /**
048: * Holds the Geodetic Latitude (WGS84 Ellipsoid).
049: */
050: public Measurable<Angle> latitudeWGS84;
051:
052: /**
053: * Holds the Geodetic Longitude (WGS84 Ellipsoid).
054: */
055: public Measurable<Angle> longitudeWGS84;
056:
057: /**
058: * Holds the WGS84 Ellipsoidal Height.
059: */
060: public Measurable<Length> heightWGS84;
061:
062: /**
063: * Holds the Time since midnight, January 1, 1970 UTC.
064: */
065: public Measurable<Duration> timeUTC;
066: }
067:
068: /**
069: * Returns the converter between this coordinate reference system
070: * and the one specified.
071: *
072: * @param that the coordinate reference system to convert to.
073: * @return the corresponding coordinates converter.
074: * @throws ConversionException if the conversion is not possible
075: * (e.g. geographic to temporal).
076: */
077: public <T extends Coordinates<?>> CoordinatesConverter<C, T> getConverterTo(
078: CoordinateReferenceSystem<T> that) {
079: return new GeneralConverter<T>(that);
080: }
081:
082: // General implementation using absolute position as intermediary.
083: private class GeneralConverter<T extends Coordinates<?>> implements
084: CoordinatesConverter<C, T> {
085: private final CoordinateReferenceSystem<T> _toCRS;
086:
087: private GeneralConverter(CoordinateReferenceSystem<T> toCRS) {
088: _toCRS = toCRS;
089: }
090:
091: public T convert(C source) {
092: AbsolutePosition position = positionOf(source,
093: new AbsolutePosition());
094: return _toCRS.coordinatesOf(position);
095: }
096: }
097:
098: /**
099: * Returns the coordinates in this reference system of the specified
100: * absolute position.
101: *
102: * @param position the absolute position for which the coordinates
103: * in this reference system is returned.
104: * @return the coordinates for the specified absolute position.
105: * @throws ConversionException if a conversion error occurs.
106: */
107: protected abstract C coordinatesOf(AbsolutePosition position);
108:
109: /**
110: * Returns the absolute position from the coordinates in
111: * this reference system. This update may require information already
112: * supplied by the position. For example, the height for a pressure
113: * altitude might depends upon the latitude/longitude and the time.
114: *
115: * @param coordinates the coordinates for which the absolute position
116: * is adjusted.
117: * @param position the position object to update.
118: * @return the corresponding absolute position.
119: * @throws ConversionException if a conversion error occurs.
120: */
121: protected abstract AbsolutePosition positionOf(C coordinates,
122: AbsolutePosition position);
123:
124: /**
125: * Returns the OpenGIS coordinate system associated to this
126: * coordinate reference system.
127: *
128: * @return the corresponding coordinate system.
129: */
130: public abstract CoordinateSystem getCoordinateSystem();
131:
132: /////////////
133: // OpenGIS //
134: /////////////
135:
136: /**
137: * OpenGIS® - Area for which the (coordinate) reference system is valid.
138: *
139: * @return coordinate reference system valid area,
140: * or {@code null} (default) if not available.
141: */
142: public Extent getValidArea() {
143: return null;
144: }
145:
146: /**
147: * OpenGIS® - Description of domain of usage, or limitations of usage,
148: * for which this (coordinate) reference system object is valid.
149: */
150: public InternationalString getScope() {
151: throw new UnsupportedOperationException();
152: }
153:
154: /**
155: * OpenGIS® - The primary name by which this object is identified.
156: *
157: * @return an identifier holding the class name.
158: */
159: public Identifier getName() {
160: return new Name(CoordinateReferenceSystem.this .getClass()
161: .getName());
162: }
163:
164: /**
165: * OpenGIS® - An alternative name by which this object is identified.
166: *
167: * @return The aliases, or an empty collection if there is none.
168: */
169: public Collection<String> getAlias() {
170: return EMPTY_SET;
171: }
172:
173: /**
174: * OpenGIS® - An identifier which references elsewhere the object's defining information.
175: * Alternatively an identifier by which this object can be referenced.
176: *
177: * @return This object identifiers, or an empty set if there is none.
178: */
179: public Set<String> getIdentifiers() {
180: return EMPTY_SET;
181: }
182:
183: /**
184: * OpenGIS® - Comments on or information about this object, including
185: * data source information.
186: *
187: * @return <code>null</code> (default).
188: */
189: public InternationalString getRemarks() {
190: return null;
191: }
192:
193: /**
194: * OpenGIS® - Returns a <cite>Well Known Text</cite> (WKT)</A> for
195: * this object. This operation may fails if an object is too complex for
196: * the WKT format capability (for example an engineering CRS} with different
197: * unit for each axis).
198: *
199: * @return The Well Know Text for this object.
200: * @throws UnsupportedOperationException If this object can't be formatted
201: * as WKT (default).
202: */
203: public String toWKT() throws UnsupportedOperationException {
204: throw new UnsupportedOperationException();
205: }
206:
207: // Default coordinates axis.
208: static class Axis implements CoordinateSystemAxis {
209:
210: private final Name _name;
211:
212: private final String _abbreviation;
213:
214: private final Unit<?> _unit;
215:
216: private final AxisDirection _direction;
217:
218: public Axis(final String name, String abbreviation,
219: Unit<?> unit, AxisDirection direction) {
220: _name = new Name(name);
221: _abbreviation = abbreviation;
222: _unit = unit;
223: _direction = direction;
224: }
225:
226: public final Identifier getName() {
227: return _name;
228: }
229:
230: public final String getAbbreviation() {
231: return _abbreviation;
232: }
233:
234: public final Unit<?> getUnit() {
235: return _unit;
236: }
237:
238: public final AxisDirection getDirection() {
239: return _direction;
240: }
241:
242: public Collection<String> getAlias() {
243: return EMPTY_SET;
244: }
245:
246: public Set<String> getIdentifiers() {
247: return EMPTY_SET;
248: }
249:
250: public InternationalString getRemarks() {
251: throw new UnsupportedOperationException();
252: }
253:
254: public String toWKT() throws UnsupportedOperationException {
255: throw new UnsupportedOperationException();
256: }
257:
258: }
259:
260: // Default coordinates axis.
261: static class Name implements Identifier {
262: final String _value;
263:
264: public Name(String value) {
265: _value = value;
266: }
267:
268: public String getCode() {
269: return _value;
270: }
271:
272: public Citation getAuthority() {
273: throw new UnsupportedOperationException();
274: }
275:
276: public String getVersion() {
277: throw new UnsupportedOperationException();
278: }
279: }
280:
281: static final FastSet<String> EMPTY_SET = new FastSet<String>();
282: }
|