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

Last change on this file since 2419 was 2419, checked in by jttt, 14 years ago

Reindex node or way in QuadBuckets after coordinates change

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm;
3
4import org.openstreetmap.josm.data.coor.CachedLatLon;
5import org.openstreetmap.josm.data.coor.EastNorth;
6import org.openstreetmap.josm.data.coor.LatLon;
7import org.openstreetmap.josm.data.osm.visitor.Visitor;
8
9/**
10 * One node data, consisting of one world coordinate waypoint.
11 *
12 * @author imi
13 */
14public final class Node extends OsmPrimitive {
15
16 private CachedLatLon coor;
17
18 public final void setCoor(LatLon coor) {
19 if(coor != null){
20 if(this.coor == null) {
21 this.coor = new CachedLatLon(coor);
22 } else {
23 this.coor.setCoor(coor);
24 }
25 if (getDataSet() != null) {
26 getDataSet().reindexNode(this);
27 }
28 }
29 }
30
31 public final LatLon getCoor() {
32 return coor;
33 }
34
35 public final void setEastNorth(EastNorth eastNorth) {
36 if(eastNorth != null)
37 {
38 if(coor != null) {
39 coor.setEastNorth(eastNorth);
40 } else {
41 coor = new CachedLatLon(eastNorth);
42 }
43 if (getDataSet() != null) {
44 getDataSet().reindexNode(this);
45 }
46 }
47 }
48
49 public final EastNorth getEastNorth() {
50 return coor != null ? coor.getEastNorth() : null;
51 }
52
53
54 protected Node(long id, boolean allowNegative) {
55 super(id, allowNegative);
56 }
57
58
59 /**
60 * Create a new local node.
61 *
62 */
63 public Node() {
64 this(0, false);
65 }
66
67
68 /**
69 * Create an incomplete Node object
70 */
71 public Node(long id) {
72 super(id, false);
73 }
74
75 /**
76 *
77 * @param clone
78 * @param clearId If true, set version to 0 and id to new unique value
79 */
80 public Node(Node clone, boolean clearId) {
81 super(clone.getUniqueId(), true);
82 cloneFrom(clone);
83 if (clearId) {
84 clearOsmId();
85 }
86 }
87
88 /**
89 * Create an identical clone of the argument (including the id)
90 */
91 public Node(Node clone) {
92 this(clone, false);
93 }
94
95 public Node(LatLon latlon) {
96 super(0, false);
97 setCoor(latlon);
98 }
99
100 public Node(EastNorth eastNorth) {
101 super(0, false);
102 setEastNorth(eastNorth);
103 }
104
105 @Override public void visit(Visitor visitor) {
106 visitor.visit(this);
107 }
108
109 @Override public void cloneFrom(OsmPrimitive osm) {
110 super.cloneFrom(osm);
111 setCoor(((Node)osm).coor);
112 }
113
114 /**
115 * Merges the technical and semantical attributes from <code>other</code> onto this.
116 *
117 * Both this and other must be new, or both must be assigned an OSM ID. If both this and <code>other</code>
118 * have an assigend OSM id, the IDs have to be the same.
119 *
120 * @param other the other primitive. Must not be null.
121 * @throws IllegalArgumentException thrown if other is null.
122 * @throws DataIntegrityProblemException thrown if either this is new and other is not, or other is new and this is not
123 * @throws DataIntegrityProblemException thrown if other is new and other.getId() != this.getId()
124 */
125 @Override
126 public void mergeFrom(OsmPrimitive other) {
127 super.mergeFrom(other);
128 if (!other.incomplete) {
129 setCoor(new LatLon(((Node)other).coor));
130 }
131 }
132
133 @Override public void load(PrimitiveData data) {
134 super.load(data);
135 setCoor(((NodeData)data).getCoor());
136 }
137
138 @Override public NodeData save() {
139 NodeData data = new NodeData();
140 saveCommonAttributes(data);
141 data.setCoor(getCoor());
142 return data;
143 }
144
145 @Override public String toString() {
146 String coorDesc = coor == null?"":"lat="+coor.lat()+",lon="+coor.lon();
147 return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " " + coorDesc+"}";
148 }
149
150 @Override
151 public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
152 if (other == null || ! (other instanceof Node) )
153 return false;
154 if (! super.hasEqualSemanticAttributes(other))
155 return false;
156 Node n = (Node)other;
157 if (coor == null && n.coor == null)
158 return true;
159 else if (coor != null && n.coor != null)
160 return coor.equals(n.coor);
161 else
162 return false;
163 }
164
165 public int compareTo(OsmPrimitive o) {
166 return o instanceof Node ? Long.valueOf(getId()).compareTo(o.getId()) : 1;
167 }
168
169 @Override
170 public String getDisplayName(NameFormatter formatter) {
171 return formatter.format(this);
172 }
173
174 public OsmPrimitiveType getType() {
175 return OsmPrimitiveType.NODE;
176 }
177}
Note: See TracBrowser for help on using the repository browser.