Changeset 1724 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2009-07-03T22:19:22+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 1 added
- 14 edited
-
Bounds.java (modified) (2 diffs)
-
ProjectionBounds.java (modified) (2 diffs)
-
coor/CachedLatLon.java (added)
-
coor/EastNorth.java (modified) (1 diff)
-
coor/LatLon.java (modified) (1 diff)
-
gpx/GpxData.java (modified) (5 diffs)
-
gpx/WayPoint.java (modified) (3 diffs)
-
osm/Node.java (modified) (4 diffs)
-
osm/visitor/BoundingXYVisitor.java (modified) (5 diffs)
-
projection/Epsg4326.java (modified) (2 diffs)
-
projection/Lambert.java (modified) (1 diff)
-
projection/LambertEST.java (modified) (1 diff)
-
projection/Mercator.java (modified) (1 diff)
-
projection/SwissGrid.java (modified) (1 diff)
-
projection/UTM.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r1722 r1724 27 27 } 28 28 29 public Bounds(LatLon b) { 30 this.min = b; 31 this.max = b; 32 } 33 29 34 @Override public String toString() { 30 35 return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]"; … … 34 39 * @return Center of the bounding box. 35 40 */ 36 public LatLon center() { 37 // FIXME: not sure whether this calculation is right; maybe there is some 38 // more complex calculation needed to get a center of a spherical 39 // dimension? 40 return new LatLon((min.lat()+max.lat())/2, (min.lon()+max.lon())/2); 41 public LatLon getCenter() 42 { 43 return min.getCenter(max); 41 44 } 42 45 -
trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java
r1722 r1724 25 25 this.max = max; 26 26 } 27 public ProjectionBounds(EastNorth p) { 28 this.min = p; 29 this.max = p; 30 } 27 31 public ProjectionBounds(EastNorth center, double east, double north) { 28 32 this.min = new EastNorth(center.east()-east/2.0, center.north()-north/2.0); … … 32 36 { 33 37 if (e.east() < min.east() || e.north() < min.north()) 34 min = e;35 elseif (e.east() > max.east() || e.north() > max.north())36 max = e;38 min = new EastNorth(Math.min(e.east(), min.east()), Math.min(e.north(), min.north())); 39 if (e.east() > max.east() || e.north() > max.north()) 40 max = new EastNorth(Math.max(e.east(), max.east()), Math.max(e.north(), max.north())); 37 41 } 38 42 public EastNorth getCenter() 39 43 { 40 return new EastNorth(min.east()/2+max.east()/2, min.north()/2+max.north()/2); 44 return min.getCenter(max); 45 } 46 47 @Override public String toString() { 48 return "ProjectionBounds["+min.east()+","+min.north()+","+max.east()+","+max.north()+"]"; 41 49 } 42 50 } -
trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java
r1209 r1724 30 30 return new EastNorth(this.x + proportion * (en2.x - this.x), 31 31 this.y + proportion * (en2.y - this.y)); 32 } 33 34 public EastNorth getCenter(EastNorth en2) { 35 return new EastNorth((this.x + en2.x)/2.0, (this.y + en2.y)/2.0); 32 36 } 33 37 -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r1722 r1724 143 143 } 144 144 145 public LatLon interpolate(LatLon ll2, double proportion) { 146 return new LatLon(this.x + proportion * (ll2.x - this.x), 147 this.y + proportion * (ll2.y - this.y)); 148 } 149 150 public LatLon getCenter(LatLon ll2) { 151 return new LatLon((this.x + ll2.x)/2.0, (this.y + ll2.y)/2.0); 152 } 153 145 154 @Override public String toString() { 146 155 return "LatLon[lat="+lat()+",lon="+lon()+"]"; -
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r1722 r1724 84 84 for (WayPoint wpt : waypoints) { 85 85 if (bounds == null) { 86 bounds = new Bounds(wpt. latlon, wpt.latlon);86 bounds = new Bounds(wpt.getCoor()); 87 87 } else { 88 bounds.extend(wpt. latlon);88 bounds.extend(wpt.getCoor()); 89 89 } 90 90 } … … 92 92 for (WayPoint wpt : rte.routePoints) { 93 93 if (bounds == null) { 94 bounds = new Bounds(wpt. latlon, wpt.latlon);94 bounds = new Bounds(wpt.getCoor()); 95 95 } else { 96 bounds.extend(wpt. latlon);96 bounds.extend(wpt.getCoor()); 97 97 } 98 98 } … … 102 102 for (WayPoint wpt : trkseg) { 103 103 if (bounds == null) { 104 bounds = new Bounds(wpt. latlon, wpt.latlon);104 bounds = new Bounds(wpt.getCoor()); 105 105 } else { 106 bounds.extend(wpt. latlon);106 bounds.extend(wpt.getCoor()); 107 107 } 108 108 } … … 123 123 for (WayPoint tpt : trkseg) { 124 124 if(last != null){ 125 result += calcDistance(last.latlon, tpt.latlon);125 result += last.getCoor().greatCircleDistance(tpt.getCoor()); 126 126 } 127 127 last = tpt; … … 132 132 return result; 133 133 } 134 135 /**136 * returns the distance in meters between two LatLons137 */138 public static double calcDistance(LatLon p1, LatLon p2){139 double lat1, lon1, lat2, lon2;140 double dlon, dlat;141 142 lat1 = p1.lat() * Math.PI / 180.0;143 lon1 = p1.lon() * Math.PI / 180.0;144 lat2 = p2.lat() * Math.PI / 180.0;145 lon2 = p2.lon() * Math.PI / 180.0;146 147 dlon = lon2 - lon1;148 dlat = lat2 - lat1;149 150 double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2));151 double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));152 return 6367000 * c;153 }154 155 134 } -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r1721 r1724 4 4 package org.openstreetmap.josm.data.gpx; 5 5 6 import java.text.ParsePosition;7 import java.text.SimpleDateFormat;8 6 import java.util.Date; 9 import java.util.regex.Pattern;10 7 import java.awt.Color; 11 8 12 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.data.coor.CachedLatLon; 13 11 import org.openstreetmap.josm.data.coor.EastNorth; 14 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.data.projection.Projection; 14 import org.openstreetmap.josm.tools.DateUtils; 15 15 16 16 public class WayPoint extends WithAttributes implements Comparable<WayPoint> 17 17 { 18 public final LatLon latlon;19 public final EastNorth eastNorth;20 18 public double time; 21 19 public Color customColoring; … … 23 21 public int dir; 24 22 23 private CachedLatLon coor; 24 25 public final LatLon getCoor() { 26 return coor; 27 } 28 29 public final EastNorth getEastNorth() { 30 return coor.getEastNorth(); 31 } 32 25 33 public WayPoint(LatLon ll) { 26 latlon = ll; 27 eastNorth = Main.proj.latlon2eastNorth(ll); 34 coor = new CachedLatLon(ll); 28 35 } 29 36 30 37 @Override 31 38 public String toString() { 32 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + latlon.toString() + ", " + attr + ")";39 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + coor.toString() + ", " + attr + ")"; 33 40 } 34 41 … … 36 43 * Convert the time stamp of the waypoint into seconds from the epoch 37 44 */ 38 public final static SimpleDateFormat GPXTIMEFMT = 39 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); 40 public final static SimpleDateFormat GPXTIMEFMT_nofrac = 41 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); 42 public final static SimpleDateFormat GPXTIMEFMT_tz = 43 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 44 public final static SimpleDateFormat GPXTIMEFMT_tz_nofrac = 45 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); 46 47 private final static Pattern colontz = Pattern.compile(".*[+-][0-9][0-9]:[0-9][0-9]\\z"); 48 private final static Pattern colontzreplacement = Pattern.compile("([+-][0-9][0-9]):([0-9][0-9])\\z"); 49 50 public void setTime() { 51 if (! attr.containsKey("time")) { 52 return; 53 } 54 String timestring = attr.get("time").toString(); 55 56 /* make the string timzeone be conanonical - unfortunately the allowed timezone in a 57 * GPX is Z or +/-hh:mm whereas in simpledateformat it is +/-hhmm only (no colon) 58 * If no timezone is given, the time will be interpreted as local time by parse. */ 59 if (timestring.substring(timestring.length() - 1).equals("Z")) { 60 timestring = timestring.substring(0, timestring.length() - 1) + "+0000"; 61 } else if (colontz.matcher(timestring).matches()) { 62 timestring = colontzreplacement.matcher(timestring).replaceFirst("$1$2"); 63 } 64 Date d = GPXTIMEFMT_tz.parse(timestring, new ParsePosition(0)); 65 if (d == null) { 66 d = GPXTIMEFMT_tz_nofrac.parse(timestring, new ParsePosition(0)); 67 if (d == null) { 68 /* try without a zimezone indication */ 69 d = GPXTIMEFMT.parse(timestring, new ParsePosition(0)); 70 if (d == null) { 71 d = GPXTIMEFMT_nofrac.parse(timestring, new ParsePosition(0)); 72 } 73 // date has parsed in local time, and been adjusted to UTC by parse 45 public void setTime() { 46 for(String key : new String[]{"time", "cmt", "desc"}) 47 { 48 if(attr.containsKey("time")) 49 { 50 double t = DateUtils.fromString(attr.get("time").toString()).getTime(); 51 if(t != 0.0) 52 { 53 time = t / 1000.0; /* ms => seconds */ 54 break; 55 } 74 56 } 75 }76 if (d != null /* parsing ok */) {77 time = d.getTime() / 1000.0; /* ms => seconds */78 }79 }80 /**81 * Convert a time stamp of the waypoint from the <cmt> or <desc> field82 * into seconds from the epoch. Handles the date format as it is used by83 * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0).84 * A value of <time> fields overwrites values set with by method.85 * Does nothing if specified key does not exist or text cannot be parsed.86 *87 * @param key The key that contains the text to convert.88 */89 public void setGarminCommentTime(String key) {90 // do not overwrite time if already set91 if (time != 0.0) {92 return;93 }94 if (! attr.containsKey(key)) {95 return;96 }97 // example date format "18-AUG-08 13:33:03"98 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone99 Date d = f.parse(attr.get(key).toString(), new ParsePosition(0));100 if (d != null /* parsing OK */) {101 time = d.getTime() / 1000.0; /* ms => seconds */102 57 } 103 58 } -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r1722 r1724 6 6 import org.openstreetmap.josm.Main; 7 7 import org.openstreetmap.josm.data.coor.EastNorth; 8 import org.openstreetmap.josm.data.coor.CachedLatLon; 8 9 import org.openstreetmap.josm.data.coor.LatLon; 9 10 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; … … 11 12 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 13 import org.openstreetmap.josm.data.osm.Node; 13 14 14 15 15 /** … … 20 20 public final class Node extends OsmPrimitive { 21 21 22 private LatLon coor; 23 24 private EastNorth eastNorth; 25 private Projection proj; 26 22 private CachedLatLon coor; 27 23 28 24 public final void setCoor(LatLon coor) { 29 this.coor = coor; 30 proj = null; 25 if(this.coor == null) 26 this.coor = new CachedLatLon(coor); 27 else 28 this.coor.setCoor(coor); 31 29 } 32 30 … … 36 34 37 35 public final void setEastNorth(EastNorth eastNorth) { 38 proj = Main.proj; 39 eastNorth = eastNorth; 40 this.coor = proj.eastNorth2latlon(eastNorth); 36 coor.setEastNorth(eastNorth); 41 37 } 42 38 43 39 public final EastNorth getEastNorth() { 44 if(proj != Main.proj) 45 { 46 proj = Main.proj; 47 eastNorth = proj.latlon2eastNorth(coor); 48 } 49 return eastNorth; 40 return coor.getEastNorth(); 50 41 } 51 42 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r1722 r1724 6 6 import org.openstreetmap.josm.data.ProjectionBounds; 7 7 import org.openstreetmap.josm.data.coor.EastNorth; 8 import org.openstreetmap.josm.data.coor.CachedLatLon; 8 9 import org.openstreetmap.josm.data.coor.LatLon; 9 10 import org.openstreetmap.josm.data.osm.Node; … … 42 43 if(b != null) 43 44 { 44 visit( Main.proj.latlon2eastNorth(b.min));45 visit( Main.proj.latlon2eastNorth(b.max));45 visit(b.min); 46 visit(b.max); 46 47 } 47 48 } … … 49 50 public void visit(ProjectionBounds b) { 50 51 if(b != null) 51 bounds = new ProjectionBounds(b.min, b.max); 52 { 53 visit(b.min); 54 visit(b.max); 55 } 56 } 57 58 public void visit(LatLon latlon) { 59 if(latlon != null) 60 { 61 if(latlon instanceof CachedLatLon) 62 visit(((CachedLatLon)latlon).getEastNorth()); 63 else 64 visit(Main.proj.latlon2eastNorth(latlon)); 65 } 52 66 } 53 67 … … 55 69 if (eastNorth != null) { 56 70 if (bounds == null) 57 bounds = new ProjectionBounds(eastNorth , eastNorth);71 bounds = new ProjectionBounds(eastNorth); 58 72 else 59 73 bounds.extend(eastNorth); … … 98 112 Main.proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree))); 99 113 } 114 115 @Override public String toString() { 116 return "BoundingXYVisitor["+bounds+"]"; 117 } 100 118 } -
trunk/src/org/openstreetmap/josm/data/projection/Epsg4326.java
r1722 r1724 25 25 26 26 @Override public String toString() { 27 return tr(" EPSG:4326");27 return tr("WGS84 Geographisch"); 28 28 } 29 29 … … 34 34 public String getCacheDirectoryName() { 35 35 return "epsg4326"; 36 }37 38 @Override public boolean equals(Object o) {39 return o instanceof Epsg4326;40 36 } 41 37 -
trunk/src/org/openstreetmap/josm/data/projection/Lambert.java
r1722 r1724 158 158 } 159 159 160 @Override161 public boolean equals(Object o) {162 return o instanceof Lambert;163 }164 165 160 /** 166 161 * Initializes from geographic coordinates. Note that reference ellipsoid -
trunk/src/org/openstreetmap/josm/data/projection/LambertEST.java
r1722 r1724 107 107 } 108 108 109 @Override110 public boolean equals(Object o) {111 return o instanceof LambertEST;112 }113 114 109 public ProjectionBounds getWorldBounds() 115 110 { -
trunk/src/org/openstreetmap/josm/data/projection/Mercator.java
r1722 r1724 47 47 } 48 48 49 @Override public boolean equals(Object o) {50 return o instanceof Mercator;51 }52 53 49 public ProjectionBounds getWorldBounds() 54 50 { -
trunk/src/org/openstreetmap/josm/data/projection/SwissGrid.java
r1722 r1724 101 101 } 102 102 103 @Override104 public boolean equals(Object o) {105 return o instanceof SwissGrid;106 }107 108 103 public ProjectionBounds getWorldBounds() 109 104 { -
trunk/src/org/openstreetmap/josm/data/projection/UTM.java
r1722 r1724 345 345 } 346 346 347 @Override public boolean equals(Object o) {348 return o instanceof UTM;349 }350 351 347 public ProjectionBounds getWorldBounds() 352 348 {
Note:
See TracChangeset
for help on using the changeset viewer.
