Changeset 1108 in josm for trunk/src/org/openstreetmap/josm/data/coor
- Timestamp:
- 2008-12-07T20:38:10+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r655 r1108 2 2 package org.openstreetmap.josm.data.coor; 3 3 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 4 7 import org.openstreetmap.josm.data.Bounds; 5 8 import org.openstreetmap.josm.data.projection.Projection; 9 10 import java.text.DecimalFormat; 6 11 import java.text.NumberFormat; 7 12 … … 15 20 public class LatLon extends Coordinate { 16 21 17 public LatLon(double lat, double lon) { 18 super(lon, lat); 19 } 22 private static DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00"); 23 private static DecimalFormat cDmsSecondFormatter = new DecimalFormat("00.0"); 24 private static DecimalFormat cDdFormatter = new DecimalFormat("###0.0000"); 25 26 /** 27 * Possible ways to display coordinates 28 */ 29 public enum CoordinateFormat { 30 DECIMAL_DEGREES {public String toString() {return tr("Decimal Degrees");}}, 31 DEGREES_MINUTES_SECONDS {public String toString() {return tr("Degrees Minutes Seconds");}}; 32 } 33 34 public static String dms(double pCoordinate) { 20 35 21 public double lat() { 22 return y; 23 } 36 double tAbsCoord = Math.abs(pCoordinate); 37 int tDegree = (int) tAbsCoord; 38 double tTmpMinutes = (tAbsCoord - tDegree) * 60; 39 int tMinutes = (int) tTmpMinutes; 40 double tSeconds = (tTmpMinutes - tMinutes) * 60; 24 41 25 public double lon() { 26 return x;27 } 42 return tDegree + "\u00B0" + cDmsMinuteFormatter.format(tMinutes) + "\'" 43 + cDmsSecondFormatter.format(tSeconds) + "\""; 44 } 28 45 29 /** 30 * @return <code>true</code> if the other point has almost the same lat/lon 31 * values, only differing by no more than 32 * 1 / {@link org.openstreetmap.josm.data.projection.Projection#MAX_SERVER_PRECISION MAX_SERVER_PRECISION}. 33 */ 34 public boolean equalsEpsilon(LatLon other) { 35 final double p = 1/Projection.MAX_SERVER_PRECISION; 36 return Math.abs(lat()-other.lat()) <= p && Math.abs(lon()-other.lon()) <= p; 37 } 46 public LatLon(double lat, double lon) { 47 super(lon, lat); 48 } 38 49 39 /** 40 * @return <code>true</code>, if the coordinate is outside the world, compared 50 public double lat() { 51 return y; 52 } 53 54 public String latToString(CoordinateFormat d) { 55 switch(d) { 56 case DECIMAL_DEGREES: return cDdFormatter.format(y); 57 case DEGREES_MINUTES_SECONDS: return dms(y) + ((y < 0) ? tr("S") : tr("N")); 58 default: return "ERR"; 59 } 60 } 61 62 public double lon() { 63 return x; 64 } 65 66 public String lonToString(CoordinateFormat d) { 67 switch(d) { 68 case DECIMAL_DEGREES: return cDdFormatter.format(x); 69 case DEGREES_MINUTES_SECONDS: return dms(x) + ((x < 0) ? tr("W") : tr("E")); 70 default: return "ERR"; 71 } 72 } 73 74 75 76 /** 77 * @return <code>true</code> if the other point has almost the same lat/lon 78 * values, only differing by no more than 79 * 1 / {@link org.openstreetmap.josm.data.projection.Projection#MAX_SERVER_PRECISION MAX_SERVER_PRECISION}. 80 */ 81 public boolean equalsEpsilon(LatLon other) { 82 final double p = 1/Projection.MAX_SERVER_PRECISION; 83 return Math.abs(lat()-other.lat()) <= p && Math.abs(lon()-other.lon()) <= p; 84 } 85 86 /** 87 * @return <code>true</code>, if the coordinate is outside the world, compared 41 88 * by using lat/lon. 42 89 */
Note: See TracChangeset
for help on using the changeset viewer.