1 /***************************************************************************
2  *   Copyright (C) 2016 by pgRouting developers                            *
3  *   project@pgrouting.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License t &or more details.                        *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 
21 #ifndef SRC_WAY_H_
22 #define SRC_WAY_H_
23 
24 #include <boost/lexical_cast.hpp>
25 #include <vector>
26 #include <map>
27 #include <string>
28 #include "./osm_element.h"
29 #include "./Node.h"
30 
31 namespace osm2pgr {
32 
33 
34 /**
35   \code
36   <way id="20215432" visible="true" timestamp="2008-01-09T22:35:16+00:00" user="Pferdo">
37   <nd ref="213794929"/>
38   <nd ref="213795470"/>
39   <nd ref="213795483"/>
40   <nd ref="213795493"/>
41   <nd ref="213795506"/>
42   <nd ref="213795517"/>
43   <nd ref="213795527"/>
44   <nd ref="213795541"/>
45   <nd ref="213795552"/>
46   <nd ref="213795561"/>
47   <nd ref="213795571"/>
48   <tag k="name" v="Pfnderweg"/>
49   <tag k="created_by" v="JOSM"/>
50   <tag k="highway" v="residential"/>
51   </way>
52   \endcode
53   */
54 class Way : public Element {
55  public:
56      Way() = default;
~Way()57      ~Way() {};
58 
59      /**
60       *  @param atts attributes read py the parser
61       */
62      explicit Way(const char **atts);
63      Tag add_tag(const Tag &tag);
64      void add_node(Node* node);
65      void add_node(int64_t node_id);
66 
nodeRefs()67      std::vector<Node*>& nodeRefs() {return m_NodeRefs;}
nodeRefs()68      const std::vector<Node*> nodeRefs() const {return m_NodeRefs;}
69 
70 
71      std::string members_str() const;
72 
73  public:
maxspeed_forward(double p_max)74      inline void maxspeed_forward(double p_max) {m_maxspeed_forward = p_max;}
maxspeed_backward(double p_max)75      inline void maxspeed_backward(double p_max) {m_maxspeed_backward = p_max;}
76 
name()77      inline std::string name() const {return has_tag("name")? get_tag("name") : "";}
78 
79 
80      std::string oneWay() const;
81      std::string oneWayType_str() const;
is_oneway()82      inline bool is_oneway() const { return m_oneWay == "YES";}
is_reversed()83      inline bool is_reversed() const { return m_oneWay == "REVERSED";}
84 
maxspeed_forward()85      inline double maxspeed_forward() const {return m_maxspeed_forward;}
maxspeed_backward()86      inline double maxspeed_backward() const { return m_maxspeed_backward;}
87 
88      std::string get_geometry() const;
89      std::string length_str() const;
90 
91 
maxspeed_forward_str()92      inline std::string maxspeed_forward_str() const {
93          return boost::lexical_cast<std::string>(m_maxspeed_forward);
94      }
maxspeed_backward_str()95      inline std::string maxspeed_backward_str() const {
96          return boost::lexical_cast<std::string>(m_maxspeed_backward);
97      }
98 
99 
100      //! splits the way
101      std::vector<std::vector<Node*>> split_me();
102      std::string geometry_str(const std::vector<Node*> &) const;
103      std::string length_str(const std::vector<Node*> &) const;
104 
105      /**
106       * to insert the relations tags
107       */
108      void insert_tags(const std::map<std::string, std::string> &tags);
109 
110 #ifndef NDEBUG
111      friend
112      std::ostream& operator<<(std::ostream &, const Way &);
113 #endif
114 
115 
116  private:
117      bool is_number(const std::string& s) const;
118      double get_kph(const std::string &value) const;
119      void max_speed(const Tag& tag);
120      void oneWay(const Tag& tag);
121      void implied_oneWay(const Tag& tag);
122 
123 
124  private:
125      /** references to node that its on the file */
126      std::vector<Node*> m_NodeRefs;
127 
128      /** node identifiers found as part of the way */
129      std::vector<int64_t> m_node_ids;
130 
131      double m_maxspeed_forward;
132      double m_maxspeed_backward;
133      std::string m_oneWay;
134 };
135 
136 
137 }  // end namespace osm2pgr
138 #endif  // SRC_WAY_H_
139