source: josm/trunk/src/org/openstreetmap/josm/data/osm/Node.java@ 1200

Last change on this file since 1200 was 1200, checked in by stoecker, 15 years ago

add error handling for multipolygon drawing

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import java.text.DecimalFormat;
6import java.text.NumberFormat;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.data.coor.LatLon;
10import org.openstreetmap.josm.data.coor.EastNorth;
11import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;
12import org.openstreetmap.josm.data.osm.visitor.Visitor;
13
14
15/**
16 * One node data, consisting of one world coordinate waypoint.
17 *
18 * @author imi
19 */
20public final class Node extends OsmPrimitive {
21
22 public LatLon coor;
23 public volatile EastNorth eastNorth;
24
25 private static CoordinateFormat mCord;
26
27 static {
28 try {
29 mCord = LatLon.CoordinateFormat.valueOf(Main.pref.get("coordinates"));
30 } catch (IllegalArgumentException iae) {
31 mCord =LatLon.CoordinateFormat.DECIMAL_DEGREES;
32 }
33 }
34
35 /**
36 * Create an incomplete Node object
37 */
38 public Node(long id) {
39 this.id = id;
40 incomplete = true;
41 }
42
43 /**
44 * Create an identical clone of the argument (including the id)
45 */
46 public Node(Node clone) {
47 cloneFrom(clone);
48 }
49
50 public Node(LatLon latlon) {
51 this.coor = latlon;
52 eastNorth = Main.proj.latlon2eastNorth(latlon);
53 }
54
55 @Override public void visit(Visitor visitor) {
56 visitor.visit(this);
57 }
58
59 @Override public void cloneFrom(OsmPrimitive osm) {
60 super.cloneFrom(osm);
61 coor = ((Node)osm).coor;
62 eastNorth = ((Node)osm).eastNorth;
63 }
64
65 @Override public String toString() {
66 if (coor == null) return "{Node id="+id+"}";
67 return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
68 }
69
70 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
71 if (osm instanceof Node) {
72 if (super.realEqual(osm, semanticOnly)) {
73 if ((coor == null) && ((Node)osm).coor == null)
74 return true;
75 if (coor != null)
76 return coor.equals(((Node)osm).coor);
77 }
78 }
79 return false;
80 }
81
82 public int compareTo(OsmPrimitive o) {
83 return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
84 }
85
86 public String getName() {
87 String name;
88 if (incomplete) {
89 name = tr("incomplete");
90 } else {
91 name = get("name");
92 if (name == null)
93 name = id == 0 ? tr("node") : ""+id;
94 name += " (" + coor.latToString(mCord) + ", " + coor.lonToString(mCord) + ")";
95 }
96 return name;
97 }
98}
Note: See TracBrowser for help on using the repository browser.