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

Last change on this file since 12846 was 12778, checked in by bastiK, 7 years ago

see #15229 - deprecate Projections#project and Projections#inverseProject

replacement is a bit more verbose, but the fact that Main.proj is
involved need not be hidden

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import org.openstreetmap.josm.Main;
5import org.openstreetmap.josm.data.coor.EastNorth;
6import org.openstreetmap.josm.data.coor.LatLon;
7import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
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 /**
78 * @deprecated use {@link #getEastNorth(org.openstreetmap.josm.data.projection.Projecting)}
79 */
80 @Override
81 @Deprecated
82 public EastNorth getEastNorth() {
83 // No internal caching of projected coordinates needed. In contrast to getEastNorth()
84 // on Node, this method is rarely used. Caching would be overkill.
85 return Main.getProjection().latlon2eastNorth(getCoor());
86 }
87
88 @Override
89 public void setEastNorth(EastNorth eastNorth) {
90 setCoor(Main.getProjection().eastNorth2latlon(eastNorth));
91 }
92
93 @Override
94 public NodeData makeCopy() {
95 return new NodeData(this);
96 }
97
98 @Override
99 public String toString() {
100 return super.toString() + " NODE " + getCoor();
101 }
102
103 @Override
104 public OsmPrimitiveType getType() {
105 return OsmPrimitiveType.NODE;
106 }
107
108 @Override
109 public void accept(PrimitiveVisitor visitor) {
110 visitor.visit(this);
111 }
112}
Note: See TracBrowser for help on using the repository browser.