1 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 31 public class Altitude extends Coordinates<VerticalCRS> implements 32 Quantity<Length> { 33 34 37 public static final VerticalCRS<Altitude> CRS = new VerticalCRS<Altitude>() { 38 39 @Override 40 protected Altitude coordinatesOf(AbsolutePosition position) { 41 return Altitude.valueOf(position.heightWGS84.doubleValue(SI.METER), 42 SI.METER); 43 } 44 45 @Override 46 protected AbsolutePosition positionOf(Altitude coordinates, 47 AbsolutePosition position) { 48 position.heightWGS84 = coordinates; 49 return position; 50 } 51 52 @Override 53 public CoordinateSystem getCoordinateSystem() { 54 return VerticalCRS.HEIGHT_CS; 55 } 56 }; 57 58 61 private double _altitudeInMeter; 62 63 70 public static Altitude valueOf(double value, Unit<Length> unit) { 71 return new Altitude(value, unit); 72 } 73 74 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 90 public VerticalCRS getCoordinateReferenceSystem() { 91 return Altitude.CRS; 92 } 93 94 public int getDimension() { 96 return 1; 97 } 98 99 public double getOrdinate(int dimension) throws IndexOutOfBoundsException { 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 (); 106 } 107 } 108 109 public final double doubleValue(Unit<Length> unit) { 111 return unit.equals(SI.METER) ? _altitudeInMeter : SI.METER 112 .getConverterTo(unit).convert(_altitudeInMeter); 113 } 114 115 public final long longValue(Unit<Length> unit) { 117 return Math.round(doubleValue(unit)); 118 } 119 120 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 |