Eclipse SUMO - Simulation of Urban MObility
PCLoaderOSM.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2008-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // A reader of pois and polygons stored in OSM-format
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include <string>
27 #include "PCPolyContainer.h"
28 #include "PCTypeMap.h"
30 
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
35 class OptionsCont;
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
47 class PCLoaderOSM : public SUMOSAXHandler {
48 public:
60  static void loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
61  PCTypeMap& tm);
62 
63 
64 protected:
65 
68  struct PCOSMNode {
70  long long int id;
72  double lon;
74  double lat;
76  std::string name;
78  std::map<std::string, std::string> myAttributes;
79  };
80 
81 
84  struct PCOSMRelation {
86  long long int id;
88  std::string name;
90  std::vector<long long int> myWays;
92  std::map<std::string, std::string> myAttributes;
94  bool keep;
95  };
96 
97 
100  struct PCOSMEdge {
102  long long int id;
104  std::string name;
108  std::vector<long long int> myCurrentNodes;
110  std::map<std::string, std::string> myAttributes;
111  // @brief Wether this way constitutes a complete polygon object
113  };
114 
115  typedef std::vector<PCOSMRelation*> Relations;
116  typedef std::map<long long int, PCOSMRelation*> RelationsMap;
117  typedef std::map<long long int, PCOSMEdge*> EdgeMap;
118 
119 protected:
121  static int addPolygon(const PCOSMEdge* edge, const PositionVector& vec, const PCTypeMap::TypeDef& def,
122  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
123 
125  static int addPOI(const PCOSMNode* node, const Position& pos, const PCTypeMap::TypeDef& def,
126  const std::string& fullType, int index, bool useName, PCPolyContainer& toFill, bool ignorePruning, bool withAttributes);
127 
128 
129 protected:
130  static const std::set<std::string> MyKeysToInclude;
131 
132 private:
133  static std::set<std::string> initMyKeysToInclude();
134 
137 
138  static double mergeClosest(const std::map<long long int, PCOSMNode*>& nodes, std::vector<std::vector<long long int> >& snippets);
139 
140 protected:
145  class NodesHandler : public SUMOSAXHandler {
146  public:
152  NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
153  MsgHandler& errorHandler);
154 
155 
157  ~NodesHandler();
158 
159 
160  protected:
162 
163 
171  void myStartElement(int element, const SUMOSAXAttributes& attrs);
172 
173 
180  void myEndElement(int element);
182 
183 
184  private:
187 
190 
192  std::map<long long int, PCOSMNode*>& myToFill;
193 
195  std::vector<int> myParentElements;
196 
198  long long int myLastNodeID;
199 
200  private:
203 
206 
207  };
208 
214  public:
222  RelationsHandler(RelationsMap& additionalWays,
223  Relations& relations,
224  std::set<long long int>& innerEdges,
225  bool withAttributes,
226  MsgHandler& errorHandler);
227 
228 
231 
232 
233  protected:
235 
236 
244  void myStartElement(int element, const SUMOSAXAttributes& attrs);
245 
246 
253  void myEndElement(int element);
255 
256 
257  private:
260 
263 
265  std::set<long long int>& myInnerEdges;
266 
269 
272 
275 
277  std::vector<long long int> myCurrentWays;
278 
280  std::vector<long long int> myParentElements;
281 
283  bool myKeep;
284 
285  private:
288 
291 
292  };
293 
294 
299  class EdgesHandler : public SUMOSAXHandler {
300  public:
309  EdgesHandler(const std::map<long long int, PCOSMNode*>& osmNodes,
310  EdgeMap& toFill,
311  const RelationsMap& additionalWays,
312  bool withAttributes,
313  MsgHandler& errorHandler);
314 
315 
317  ~EdgesHandler();
318 
319 
320  protected:
322 
323 
331  void myStartElement(int element, const SUMOSAXAttributes& attrs);
332 
333 
340  void myEndElement(int element);
342 
343 
344  private:
347 
350 
352  const std::map<long long int, PCOSMNode*>& myOSMNodes;
353 
356 
359 
362 
364  std::vector<int> myParentElements;
365 
367  bool myKeep;
368 
369  private:
372 
375 
376  };
377 
378 };
A storage for options typed value containers)
Definition: OptionsCont.h:89
A class which extracts OSM-edges from a parsed OSM-file.
Definition: PCLoaderOSM.h:299
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:346
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
Definition: PCLoaderOSM.h:367
EdgeMap & myEdgeMap
A map of built edges.
Definition: PCLoaderOSM.h:355
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:358
EdgesHandler & operator=(const EdgesHandler &s)
Invalidated assignment operator.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void myEndElement(int element)
Called when a closing tag occurs.
PCOSMEdge * myCurrentEdge
The currently built edge.
Definition: PCLoaderOSM.h:361
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
Definition: PCLoaderOSM.h:352
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:364
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:349
EdgesHandler(const std::map< long long int, PCOSMNode * > &osmNodes, EdgeMap &toFill, const RelationsMap &additionalWays, bool withAttributes, MsgHandler &errorHandler)
Constructor.
EdgesHandler(const EdgesHandler &s)
Invalidated copy constructor.
A class which extracts OSM-nodes from a parsed OSM-file.
Definition: PCLoaderOSM.h:145
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
Definition: PCLoaderOSM.h:192
NodesHandler(const NodesHandler &s)
Invalidated copy constructor.
long long int myLastNodeID
The id of the last parsed node.
Definition: PCLoaderOSM.h:198
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:186
NodesHandler(std::map< long long int, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
void myEndElement(int element)
Called when a closing tag occurs.
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:195
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:189
NodesHandler & operator=(const NodesHandler &s)
Invalidated assignment operator.
A class which extracts relevant way-ids from relations in a parsed OSM-file.
Definition: PCLoaderOSM.h:213
std::set< long long int > & myInnerEdges
the loaded edges
Definition: PCLoaderOSM.h:265
Relations & myRelations
the loaded relations
Definition: PCLoaderOSM.h:262
std::vector< long long int > myCurrentWays
the ways within the current relation
Definition: PCLoaderOSM.h:277
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
Definition: PCLoaderOSM.h:280
PCOSMRelation * myCurrentRelation
The currently parsed relation.
Definition: PCLoaderOSM.h:274
void myEndElement(int element)
Called when a closing tag occurs.
RelationsHandler & operator=(const RelationsHandler &s)
Invalidated assignment operator.
RelationsHandler(const RelationsHandler &s)
Invalidated copy constructor.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
RelationsMap & myAdditionalWays
additional ways which are reference by relations
Definition: PCLoaderOSM.h:259
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
Definition: PCLoaderOSM.h:271
bool myWithAttributes
Whether all attributes shall be stored.
Definition: PCLoaderOSM.h:268
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
Definition: PCLoaderOSM.h:283
RelationsHandler(RelationsMap &additionalWays, Relations &relations, std::set< long long int > &innerEdges, bool withAttributes, MsgHandler &errorHandler)
Constructor.
A reader of pois and polygons stored in OSM-format.
Definition: PCLoaderOSM.h:47
static int addPolygon(const PCOSMEdge *edge, const PositionVector &vec, const PCTypeMap::TypeDef &def, const std::string &fullType, int index, bool useName, PCPolyContainer &toFill, bool ignorePruning, bool withAttributes)
try add the polygon and return the next index on success
std::map< long long int, PCOSMEdge * > EdgeMap
Definition: PCLoaderOSM.h:117
static Position convertNodePosition(PCOSMNode *n)
retrieve cartesian coordinate for given node
static int addPOI(const PCOSMNode *node, const Position &pos, const PCTypeMap::TypeDef &def, const std::string &fullType, int index, bool useName, PCPolyContainer &toFill, bool ignorePruning, bool withAttributes)
try add the POI and return the next index on success
static double mergeClosest(const std::map< long long int, PCOSMNode * > &nodes, std::vector< std::vector< long long int > > &snippets)
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as OSM-XML.
Definition: PCLoaderOSM.cpp:90
std::vector< PCOSMRelation * > Relations
Definition: PCLoaderOSM.h:115
static const std::set< std::string > MyKeysToInclude
Definition: PCLoaderOSM.h:130
std::map< long long int, PCOSMRelation * > RelationsMap
Definition: PCLoaderOSM.h:116
static std::set< std::string > initMyKeysToInclude()
Definition: PCLoaderOSM.cpp:57
A storage for loaded polygons and pois.
A storage for type mappings.
Definition: PCTypeMap.h:42
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
An internal definition of a loaded edge.
Definition: PCLoaderOSM.h:100
bool myIsClosed
Information whether this area is closed.
Definition: PCLoaderOSM.h:106
long long int id
The edge's id.
Definition: PCLoaderOSM.h:102
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:110
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
Definition: PCLoaderOSM.h:108
std::string name
The edge's name (if any)
Definition: PCLoaderOSM.h:104
An internal representation of an OSM-node.
Definition: PCLoaderOSM.h:68
double lat
The latitude the node is located at.
Definition: PCLoaderOSM.h:74
double lon
The longitude the node is located at.
Definition: PCLoaderOSM.h:72
std::string name
The nodes name (if any)
Definition: PCLoaderOSM.h:76
long long int id
The node's id.
Definition: PCLoaderOSM.h:70
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:78
An internal definition of a loaded relation.
Definition: PCLoaderOSM.h:84
std::vector< long long int > myWays
The list of ways this relation is made of.
Definition: PCLoaderOSM.h:90
std::string name
The relation's name (if any)
Definition: PCLoaderOSM.h:88
bool keep
whether this relation is a valid polygon
Definition: PCLoaderOSM.h:94
std::map< std::string, std::string > myAttributes
Additional attributes.
Definition: PCLoaderOSM.h:92
long long int id
The relation's id.
Definition: PCLoaderOSM.h:86
A single definition of values that shall be used for a given type.
Definition: PCTypeMap.h:61