1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
5 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
6 | import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
|
---|
7 | import org.openstreetmap.josm.data.projection.ProjectionRegistry;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * The data on a single node (tags and position) that is stored in the database
|
---|
11 | */
|
---|
12 | public 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 | public void setEastNorth(EastNorth eastNorth) {
|
---|
79 | setCoor(ProjectionRegistry.getProjection().eastNorth2latlon(eastNorth));
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public NodeData makeCopy() {
|
---|
84 | return new NodeData(this);
|
---|
85 | }
|
---|
86 |
|
---|
87 | @Override
|
---|
88 | public String toString() {
|
---|
89 | return super.toString() + " NODE " + getCoor();
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Override
|
---|
93 | public OsmPrimitiveType getType() {
|
---|
94 | return OsmPrimitiveType.NODE;
|
---|
95 | }
|
---|
96 |
|
---|
97 | @Override
|
---|
98 | public void accept(PrimitiveVisitor visitor) {
|
---|
99 | visitor.visit(this);
|
---|
100 | }
|
---|
101 |
|
---|
102 | @Override
|
---|
103 | public BBox getBBox() {
|
---|
104 | return new BBox(lon, lat);
|
---|
105 | }
|
---|
106 |
|
---|
107 | @Override
|
---|
108 | public boolean isReferredByWays(int n) {
|
---|
109 | return false;
|
---|
110 | }
|
---|
111 | }
|
---|