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

Last change on this file since 3163 was 3163, checked in by bastiK, 14 years ago

fixed #4815 (after [3154] you cannot remove a node from quadbuckets if the coordinates have changed -> first remove the node from quadbuckets then change the coordinates then add it back)

  • Property svn:eol-style set to native
File size: 5.5 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 private BBox bbox;
18
19 public final void setCoor(LatLon coor) {
20 if(coor != null){
21 if(this.coor == null) {
22 this.coor = new CachedLatLon(coor);
23 } else {
24 this.coor.setCoor(coor);
25 }
26 if (getDataSet() != null) {
27 getDataSet().fireNodeMoved(this);
28 }
29 }
30 }
31
32 public final LatLon getCoor() {
33 return coor;
34 }
35
36 public final void setEastNorth(EastNorth eastNorth) {
37 if(eastNorth != null)
38 {
39 if(coor != null) {
40 coor.setEastNorth(eastNorth);
41 } else {
42 coor = new CachedLatLon(eastNorth);
43 }
44 if (getDataSet() != null) {
45 getDataSet().fireNodeMoved(this);
46 }
47 }
48 }
49
50 public final EastNorth getEastNorth() {
51 return coor != null ? coor.getEastNorth() : null;
52 }
53
54 protected Node(long id, boolean allowNegative) {
55 super(id, allowNegative);
56 }
57
58 /**
59 * Create a new local node.
60 *
61 */
62 public Node() {
63 this(0, false);
64 }
65
66 /**
67 * Create an incomplete Node object
68 */
69 public Node(long id) {
70 super(id, false);
71 }
72
73 /**
74 * Create new node
75 * @param id
76 * @param version
77 */
78 public Node(long id, int version) {
79 super(id, version, false);
80 }
81
82 /**
83 *
84 * @param clone
85 * @param clearId If true, set version to 0 and id to new unique value
86 */
87 public Node(Node clone, boolean clearId) {
88 super(clone.getUniqueId(), true /* allow negative IDs */);
89 cloneFrom(clone);
90 if (clearId) {
91 clearOsmId();
92 }
93 }
94
95 /**
96 * Create an identical clone of the argument (including the id)
97 */
98 public Node(Node clone) {
99 this(clone, false);
100 }
101
102 public Node(LatLon latlon) {
103 super(0, false);
104 setCoor(latlon);
105 }
106
107 public Node(EastNorth eastNorth) {
108 super(0, false);
109 setEastNorth(eastNorth);
110 }
111
112 @Override public void visit(Visitor visitor) {
113 visitor.visit(this);
114 }
115
116 @Override public void cloneFrom(OsmPrimitive osm) {
117 super.cloneFrom(osm);
118 setCoor(((Node)osm).coor);
119 }
120
121 /**
122 * Merges the technical and semantical attributes from <code>other</code> onto this.
123 *
124 * Both this and other must be new, or both must be assigned an OSM ID. If both this and <code>other</code>
125 * have an assigend OSM id, the IDs have to be the same.
126 *
127 * @param other the other primitive. Must not be null.
128 * @throws IllegalArgumentException thrown if other is null.
129 * @throws DataIntegrityProblemException thrown if either this is new and other is not, or other is new and this is not
130 * @throws DataIntegrityProblemException thrown if other is new and other.getId() != this.getId()
131 */
132 @Override
133 public void mergeFrom(OsmPrimitive other) {
134 super.mergeFrom(other);
135 if (!other.isIncomplete()) {
136 setCoor(new LatLon(((Node)other).coor));
137 }
138 }
139
140 @Override public void load(PrimitiveData data) {
141 super.load(data);
142 setCoor(((NodeData)data).getCoor());
143 }
144
145 @Override public NodeData save() {
146 NodeData data = new NodeData();
147 saveCommonAttributes(data);
148 if (!isIncomplete()) {
149 data.setCoor(getCoor());
150 }
151 return data;
152 }
153
154 @Override public String toString() {
155 String coorDesc = coor == null?"":"lat="+coor.lat()+",lon="+coor.lon();
156 return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " " + coorDesc+"}";
157 }
158
159 @Override
160 public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
161 if (other == null || ! (other instanceof Node) )
162 return false;
163 if (! super.hasEqualSemanticAttributes(other))
164 return false;
165 Node n = (Node)other;
166 if (coor == null && n.coor == null)
167 return true;
168 else if (coor != null && n.coor != null)
169 return coor.equalsEpsilon(n.coor);
170 else
171 return false;
172 }
173
174 public int compareTo(OsmPrimitive o) {
175 return o instanceof Node ? Long.valueOf(getUniqueId()).compareTo(o.getUniqueId()) : 1;
176 }
177
178 @Override
179 public String getDisplayName(NameFormatter formatter) {
180 return formatter.format(this);
181 }
182
183 public OsmPrimitiveType getType() {
184 return OsmPrimitiveType.NODE;
185 }
186
187 @Override
188 public BBox getBBox() {
189 if (getDataSet() == null)
190 return new BBox(this);
191 if (bbox == null) {
192 bbox = new BBox(this);
193 }
194 return new BBox(bbox);
195 }
196
197 @Override
198 public void updatePosition() {
199 bbox = new BBox(this);
200 // TODO: replace CachedLatLon with simple doubles and update precalculated EastNorth value here
201 }
202
203 public boolean isJunctionNode() {
204 return (OsmPrimitive.getFilteredList(getReferrers(), Way.class)).size() > 1;
205 }
206}
Note: See TracBrowser for help on using the repository browser.