1 9 package org.jscience.geography.coordinates; 10 11 import javolution.lang.Immutable; 12 import javolution.text.TextBuilder; 13 14 import org.jscience.geography.coordinates.crs.CoordinateReferenceSystem; 15 import org.opengis.referencing.cs.CoordinateSystem; 16 import org.opengis.spatialschema.geometry.DirectPosition; 17 18 27 public abstract class Coordinates<R extends CoordinateReferenceSystem> 28 implements DirectPosition, Immutable { 29 30 33 protected Coordinates() { 34 } 35 36 41 public abstract R getCoordinateReferenceSystem(); 42 43 47 54 public abstract int getDimension(); 55 56 65 public abstract double getOrdinate(int dimension) 66 throws IndexOutOfBoundsException ; 67 68 72 public final void setOrdinate(int dimension, double value) 73 throws IndexOutOfBoundsException { 74 throw new UnsupportedOperationException ("Immutable coordinates"); 75 } 76 77 84 public final double[] getCoordinates() { 85 double[] coordinates = new double[getDimension()]; 86 for (int i = 0; i < coordinates.length; i++) { 87 coordinates[i] = getOrdinate(i); 88 } 89 return coordinates; 90 } 91 92 97 public final DirectPosition getPosition() { 98 return this; 99 } 100 101 106 public final Coordinates<R> clone() { 107 return this.clone(); 108 } 109 110 115 public String toString() { 116 double[] coordinates = getCoordinates(); 117 CoordinateSystem cs = this.getCoordinateReferenceSystem().getCoordinateSystem(); 118 TextBuilder tb = TextBuilder.newInstance(); 119 tb.append('['); 120 for (int i=0; i < coordinates.length; i++) { 121 if (i != 0) { 122 tb.append(", "); 123 } 124 tb.append(getOrdinate(i)); 125 tb.append(' '); 126 tb.append(cs.getAxis(i).getUnit()); 127 } 128 tb.append(']'); 129 return tb.toString(); 130 } 131 } | Popular Tags |