source: subversion/lib/libosm/Node.h @ 2485

Last change on this file since 2485 was 2327, checked in by jonb, 13 years ago

Fix lat/lon precision, generate self-closing tags, indent output, error check parsing

File size: 1.9 KB
Line 
1#ifndef NODE_H
2#define NODE_H
3
4/*
5    Copyright (C) 2005 Nick Whitelegg, Hogweed Software, nick@hogweed.org
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
20
21 */
22
23
24#include <vector>
25#include <map>
26#include <fstream>
27#include <string>
28
29#include <iostream>
30
31#include <cmath>
32#include "Object.h"
33
34using std::ostream;
35using std::endl;
36
37namespace OSM
38{
39
40class Node : public Object
41{
42private:
43        double lat, lon;
44
45public:
46        Node()
47        {
48                lat=lon=0; 
49                id = 0; 
50        }
51
52        Node(double lt, double ln)
53        {
54                lat=lt; 
55                lon=ln; 
56                id=0; 
57        }
58        Node(int i,double lt, double ln)
59        {
60                lat=lt; 
61                lon=ln; 
62                id=i; 
63        }
64
65        bool operator==(const Node& tp)
66        { 
67                return (fabs(lat-tp.lat)<0.000001) && (fabs(lon-tp.lon)<0.000001); 
68        }
69
70        double getLat() { return lat; }
71        double getLon() { return lon; }
72
73        void setCoords(double lat,double lon)
74                { this->lat=lat; this->lon=lon; }
75
76        void toXML(std::ostream &strm)
77        {
78                std::streamsize old = strm.precision(15);
79                if (hasTags()) {
80                        strm << "  <node id='" << id << "' lat='" << lat << "' lon='" << lon
81                                        <<"'>" << endl;
82                        tagsToXML(strm);
83                        strm << "  </node>" << endl;
84                } else {
85                        strm << "  <node id='" << id << "' lat='" << lat << "' lon='" << lon
86                                        <<"'/>" << endl;
87                }
88                strm.precision(old);
89        }
90};
91
92}
93#endif
Note: See TracBrowser for help on using the repository browser.