source: josm/trunk/src/org/openstreetmap/josm/data/osm/NodeData.java@ 12161

Last change on this file since 12161 was 12161, checked in by michael2402, 7 years ago

See #13415: Add the ILatLon interface, unify handling of Nodes and CachedLatLon

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import org.openstreetmap.josm.data.coor.EastNorth;
5import org.openstreetmap.josm.data.coor.LatLon;
6import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
7import org.openstreetmap.josm.data.projection.Projections;
8
9public class NodeData extends PrimitiveData implements INode {
10
11 private static final long serialVersionUID = 5626323599550908773L;
12 /*
13 * we "inline" lat/lon coordinates instead of using a LatLon => reduces memory footprint
14 */
15 private double lat = Double.NaN;
16 private double lon = Double.NaN;
17
18 /**
19 * Constructs a new {@code NodeData}.
20 */
21 public NodeData() {
22 // contents can be set later with setters
23 }
24
25 /**
26 * Constructs a new {@code NodeData} with given id.
27 * @param id id
28 * @since 12017
29 */
30 public NodeData(long id) {
31 super(id);
32 }
33
34 /**
35 * Constructs a new {@code NodeData}.
36 * @param data node data to copy
37 */
38 public NodeData(NodeData data) {
39 super(data);
40 setCoor(data.getCoor());
41 }
42
43 @Override
44 public double lat() {
45 return lat;
46 }
47
48 @Override
49 public double lon() {
50 return lon;
51 }
52
53 @Override
54 public boolean isLatLonKnown() {
55 return !Double.isNaN(lat) && !Double.isNaN(lon);
56 }
57
58 @Override
59 public LatLon getCoor() {
60 return isLatLonKnown() ? new LatLon(lat, lon) : null;
61 }
62
63 @Override
64 public final void setCoor(LatLon coor) {
65 if (coor == null) {
66 this.lat = Double.NaN;
67 this.lon = Double.NaN;
68 } else {
69 this.lat = coor.lat();
70 this.lon = coor.lon();
71 }
72 }
73
74 @Override
75 public EastNorth getEastNorth() {
76 // No internal caching of projected coordinates needed. In contrast to getEastNorth()
77 // on Node, this method is rarely used. Caching would be overkill.
78 return Projections.project(getCoor());
79 }
80
81 @Override
82 public void setEastNorth(EastNorth eastNorth) {
83 setCoor(Projections.inverseProject(eastNorth));
84 }
85
86 @Override
87 public NodeData makeCopy() {
88 return new NodeData(this);
89 }
90
91 @Override
92 public String toString() {
93 return super.toString() + " NODE " + getCoor();
94 }
95
96 @Override
97 public OsmPrimitiveType getType() {
98 return OsmPrimitiveType.NODE;
99 }
100
101 @Override
102 public void accept(PrimitiveVisitor visitor) {
103 visitor.visit(this);
104 }
105}
Note: See TracBrowser for help on using the repository browser.