KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jscience > geography > coordinates > Altitude


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;
10
11 import javax.measure.converters.UnitConverter;
12 import javax.measure.quantities.Length;
13 import javax.measure.quantities.Quantity;
14 import javax.measure.units.SI;
15 import javax.measure.units.Unit;
16
17 import org.jscience.geography.coordinates.crs.VerticalCRS;
18 import org.opengis.referencing.cs.CoordinateSystem;
19
20 /**
21  * This class represents the Mean-Sea-Level {@link VerticalCRS vertical}
22  * altitude (MSL).
23  *
24  * <p> Note: The current implementation approximates the MSL altitude to
25  * the WGS-86 Ellipsoid Height. Future implementations will use
26  * lookup tables in order to correct for regional discrepencies.</p>
27  *
28  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
29  * @version 3.0, February 26, 2006
30  */

31 public class Altitude extends Coordinates<VerticalCRS> implements
32         Quantity<Length> {
33
34     /**
35      * Holds the coordinate reference system for all instances of this class.
36      */

37     public static final VerticalCRS<Altitude> CRS = new VerticalCRS<Altitude>() {
38
39         @Override JavaDoc
40         protected Altitude coordinatesOf(AbsolutePosition position) {
41             return Altitude.valueOf(position.heightWGS84.doubleValue(SI.METER),
42                     SI.METER);
43         }
44
45         @Override JavaDoc
46         protected AbsolutePosition positionOf(Altitude coordinates,
47                 AbsolutePosition position) {
48             position.heightWGS84 = coordinates;
49             return position;
50         }
51
52         @Override JavaDoc
53         public CoordinateSystem getCoordinateSystem() {
54             return VerticalCRS.HEIGHT_CS;
55         }
56     };
57
58     /**
59      * Holds the altitude in meters.
60      */

61     private double _altitudeInMeter;
62
63     /**
64      * Returns the vertical position corresponding to the specified coordinates.
65      *
66      * @param value the mean sea level altitude stated in the specified unit.
67      * @param unit the length unit in which the altitude is stated.
68      * @return the corresponding vertical position.
69      */

70     public static Altitude valueOf(double value, Unit<Length> unit) {
71         return new Altitude(value, unit);
72     }
73
74     /**
75      * Creates a vertical position corresponding to the specified coordinates.
76      *
77      * @param value the mean sea level altitude stated in the specified unit.
78      * @param unit the length unit in which the altitude is stated.
79      */

80     public Altitude(double value, Unit<Length> unit) {
81         if (unit == SI.METER) {
82             _altitudeInMeter = value;
83         } else {
84             UnitConverter toMeter = unit.getConverterTo(SI.METER);
85             _altitudeInMeter = toMeter.convert(value);
86         }
87     }
88
89     @Override JavaDoc
90     public VerticalCRS getCoordinateReferenceSystem() {
91         return Altitude.CRS;
92     }
93
94     // OpenGIS Interface.
95
public int getDimension() {
96         return 1;
97     }
98
99     // OpenGIS Interface.
100
public double getOrdinate(int dimension) throws IndexOutOfBoundsException JavaDoc {
101         if (dimension == 0) {
102             Unit u = VerticalCRS.HEIGHT_CS.getAxis(0).getUnit();
103             return SI.METER.getConverterTo(u).convert(_altitudeInMeter);
104         } else {
105             throw new IndexOutOfBoundsException JavaDoc();
106         }
107     }
108
109     // Implements Quantity<Length>
110
public final double doubleValue(Unit<Length> unit) {
111         return unit.equals(SI.METER) ? _altitudeInMeter : SI.METER
112                 .getConverterTo(unit).convert(_altitudeInMeter);
113     }
114
115     // Implements Quantity<Length>
116
public final long longValue(Unit<Length> unit) {
117         return Math.round(doubleValue(unit));
118     }
119
120     // Implements Quantity<Length>
121
public int compareTo(Quantity<Length> arg0) {
122         double arg0InMeter = arg0.doubleValue(SI.METER);
123         return (_altitudeInMeter > arg0InMeter) ? 1
124                 : (_altitudeInMeter < arg0InMeter) ? -1 : 0;
125     }
126
127 }
Popular Tags