KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jscience > geography > coordinates > crs > CoordinateReferenceSystem


1 /*
2  * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
3  * Copyright (C) 2006 - JScience (http://jscience.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package org.jscience.geography.coordinates.crs;
10
11 import java.util.Collection JavaDoc;
12 import java.util.Set JavaDoc;
13
14 import javax.measure.quantities.Angle;
15 import javax.measure.quantities.Duration;
16 import javax.measure.quantities.Length;
17 import javax.measure.quantities.Quantity;
18 import javax.measure.units.Unit;
19
20 import javolution.util.FastSet;
21
22 import org.jscience.geography.coordinates.Coordinates;
23 import org.opengis.metadata.Identifier;
24 import org.opengis.metadata.citation.Citation;
25 import org.opengis.metadata.extent.Extent;
26 import org.opengis.referencing.cs.AxisDirection;
27 import org.opengis.referencing.cs.CoordinateSystem;
28 import org.opengis.util.InternationalString;
29 import org.opengis.referencing.cs.CoordinateSystemAxis;
30
31 /**
32  * This class represents an arbitrary system of reference for which
33  * {@link Coordinates coordinates} of same significance can be stated.
34  *
35  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
36  * @version 3.0, February 13, 2006
37  */

38 public abstract class CoordinateReferenceSystem<C extends Coordinates>
39         implements org.opengis.referencing.crs.CoordinateReferenceSystem {
40
41     
42     /**
43      * This class represents an absolute position (can be be extended)
44      */

45     protected static class AbsolutePosition {
46
47         /**
48          * Holds the Geodetic Latitude (WGS84 Ellipsoid).
49          */

50         public Quantity<Angle> latitudeWGS84;
51
52         /**
53          * Holds the Geodetic Longitude (WGS84 Ellipsoid).
54          */

55         public Quantity<Angle> longitudeWGS84;
56
57         /**
58          * Holds the WGS84 Ellipsoidal Height.
59          */

60         public Quantity<Length> heightWGS84;
61
62         /**
63          * Holds the Time since midnight, January 1, 1970 UTC.
64          */

65         public Quantity<Duration> timeUTC;
66     }
67
68     /**
69      * Returns the converter between this coordinate reference system
70      * and the one specified.
71      *
72      * @param that the coordinate reference system to convert to.
73      * @return the corresponding coordinates converter.
74      * @throws ConversionException if the conversion is not possible
75      * (e.g. geographic to temporal).
76      */

77     public <T extends Coordinates> CoordinatesConverter<C, T> getConverterTo(
78             CoordinateReferenceSystem<T> that) {
79         return new GeneralConverter<T>(that);
80     }
81
82     // General implementation using absolute position as intermediary.
83
private class GeneralConverter<T extends Coordinates> implements
84             CoordinatesConverter<C, T> {
85         private final CoordinateReferenceSystem<T> _toCRS;
86
87         private GeneralConverter(CoordinateReferenceSystem<T> toCRS) {
88             _toCRS = toCRS;
89         }
90
91         public T convert(C source) {
92             AbsolutePosition position = positionOf(source,
93                     new AbsolutePosition());
94             return _toCRS.coordinatesOf(position);
95         }
96     }
97
98     /**
99      * 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&reg; - 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&reg; - 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 JavaDoc();
152     }
153
154     /**
155      * OpenGIS&reg; - 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().getName());
161     }
162
163     /**
164      * OpenGIS&reg; - An alternative name by which this object is identified.
165      *
166      * @return The aliases, or an empty collection if there is none.
167      */

168     public Collection JavaDoc getAlias() {
169         return EMPTY_SET;
170     }
171
172     /**
173      * OpenGIS&reg; - An identifier which references elsewhere the object's defining information.
174      * Alternatively an identifier by which this object can be referenced.
175      *
176      * @return This object identifiers, or an empty set if there is none.
177      */

178     public Set JavaDoc getIdentifiers() {
179         return EMPTY_SET;
180     }
181
182     /**
183      * OpenGIS&reg; - Comments on or information about this object, including
184      * data source information.
185      *
186      * @return <code>null</code> (default).
187      */

188     public InternationalString getRemarks() {
189         return null;
190     }
191
192     /**
193      * OpenGIS&reg; - Returns a <cite>Well Known Text</cite> (WKT)</A> for
194      * this object. This operation may fails if an object is too complex for
195      * the WKT format capability (for example an engineering CRS} with different
196      * unit for each axis).
197      *
198      * @return The Well Know Text for this object.
199      * @throws UnsupportedOperationException If this object can't be formatted
200      * as WKT (default).
201      */

202     public String JavaDoc toWKT() throws UnsupportedOperationException JavaDoc {
203         throw new UnsupportedOperationException JavaDoc();
204     }
205
206     // Default coordinates axis.
207
static class Axis implements CoordinateSystemAxis {
208
209         private final Name _name;
210
211         private final String JavaDoc _abbreviation;
212
213         private final Unit _unit;
214
215         private final AxisDirection _direction;
216
217         public Axis(final String JavaDoc name, String JavaDoc abbreviation, Unit unit,
218                 AxisDirection direction) {
219             _name = new Name(name);
220             _abbreviation = abbreviation;
221             _unit = unit;
222             _direction = direction;
223         }
224
225         public final Identifier getName() {
226             return _name;
227         }
228
229         public final String JavaDoc getAbbreviation() {
230             return _abbreviation;
231         }
232
233         public final Unit getUnit() {
234             return _unit;
235         }
236
237         public final AxisDirection getDirection() {
238             return _direction;
239         }
240
241         public Collection JavaDoc getAlias() {
242             return EMPTY_SET;
243         }
244
245         public Set JavaDoc getIdentifiers() {
246             return EMPTY_SET;
247         }
248
249         public InternationalString getRemarks() {
250             throw new UnsupportedOperationException JavaDoc();
251         }
252
253         public String JavaDoc toWKT() throws UnsupportedOperationException JavaDoc {
254             throw new UnsupportedOperationException JavaDoc();
255         }
256
257     }
258
259     // Default coordinates axis.
260
static class Name implements Identifier {
261         final String JavaDoc _value;
262
263         public Name(String JavaDoc value) {
264             _value = value;
265         }
266
267         public String JavaDoc getCode() {
268             return _value;
269         }
270
271         public Citation getAuthority() {
272             throw new UnsupportedOperationException JavaDoc();
273         }
274
275         public String JavaDoc getVersion() {
276             throw new UnsupportedOperationException JavaDoc();
277         }
278     }
279
280     static final FastSet<?> EMPTY_SET = new FastSet<Object JavaDoc>();
281 }
Popular Tags