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

Last change on this file since 12729 was 12725, checked in by bastiK, 7 years ago

see #15229 - deprecate ILatLon#getEastNorth() so ILatLon has no dependency on Main.proj

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