Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2026 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// ===========================================================================
35class OptionsCont;
36
37
38// ===========================================================================
39// class declarations
40// ===========================================================================
48public:
60 static void loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
61 PCTypeMap& tm);
62
63
64protected:
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
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 Whether 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
119protected:
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, const std::string& toDiscard);
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
129protected:
130 static const std::set<std::string> MyKeysToInclude;
131 static std::set<std::string> MyDiscardOverrides;
132
133private:
134 static std::set<std::string> initMyKeysToInclude();
135
138
139 static double mergeClosest(const std::map<long long int, PCOSMNode*>& nodes, std::vector<std::vector<long long int> >& snippets);
140
141 static double parseHeight(const std::map<std::string, std::string>& attrs, long long int id);
142
144 static bool myFullType;
145
146protected:
152 public:
158 NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
159 MsgHandler& errorHandler);
160
161
164
165
166 protected:
168
169
177 void myStartElement(int element, const SUMOSAXAttributes& attrs);
178
179
186 void myEndElement(int element);
188
189
190 private:
193
196
198 std::map<long long int, PCOSMNode*>& myToFill;
199
201 std::vector<int> myParentElements;
202
204 long long int myLastNodeID;
205
206 private:
209
212
213 };
214
220 public:
228 RelationsHandler(RelationsMap& additionalWays,
229 Relations& relations,
230 std::set<long long int>& innerEdges,
231 bool withAttributes,
232 MsgHandler& errorHandler);
233
234
237
238
239 protected:
241
242
250 void myStartElement(int element, const SUMOSAXAttributes& attrs);
251
252
259 void myEndElement(int element);
261
262
263 private:
266
269
271 std::set<long long int>& myInnerEdges;
272
275
278
281
283 std::vector<long long int> myCurrentWays;
284
286 std::vector<long long int> myParentElements;
287
289 bool myKeep;
290
291 private:
294
297
298 };
299
300
306 public:
315 EdgesHandler(const std::map<long long int, PCOSMNode*>& osmNodes,
316 EdgeMap& toFill,
317 const RelationsMap& additionalWays,
318 bool withAttributes,
319 MsgHandler& errorHandler);
320
321
324
325
326 protected:
328
329
337 void myStartElement(int element, const SUMOSAXAttributes& attrs);
338
339
346 void myEndElement(int element);
348
349
350 private:
353
356
358 const std::map<long long int, PCOSMNode*>& myOSMNodes;
359
362
365
368
370 std::vector<int> myParentElements;
371
373 bool myKeep;
374
375 private:
378
381
382 };
383
384};
A storage for options typed value containers)
Definition OptionsCont.h:92
A class which extracts OSM-edges from a parsed OSM-file.
bool myWithAttributes
Whether all attributes shall be stored.
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
EdgeMap & myEdgeMap
A map of built edges.
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
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.
EdgesHandler & operator=(const EdgesHandler &s)
Invalidated assignment operator.
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
EdgesHandler(const EdgesHandler &s)
Invalidated copy constructor.
A class which extracts OSM-nodes from a parsed OSM-file.
NodesHandler & operator=(const NodesHandler &s)
Invalidated assignment operator.
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
NodesHandler(const NodesHandler &s)
Invalidated copy constructor.
long long int myLastNodeID
The id of the last parsed node.
bool myWithAttributes
Whether all attributes shall be stored.
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.
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)
A class which extracts relevant way-ids from relations in a parsed OSM-file.
std::set< long long int > & myInnerEdges
the loaded edges
Relations & myRelations
the loaded relations
std::vector< long long int > myCurrentWays
the ways within the current relation
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
PCOSMRelation * myCurrentRelation
The currently parsed relation.
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
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set)
bool myWithAttributes
Whether all attributes shall be stored.
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list
A reader of pois and polygons stored in OSM-format.
Definition PCLoaderOSM.h:47
std::map< long long int, PCOSMEdge * > EdgeMap
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 std::set< std::string > MyDiscardOverrides
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as OSM-XML.
std::vector< PCOSMRelation * > Relations
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, const std::string &toDiscard)
try add the polygon and return the next index on success
static const std::set< std::string > MyKeysToInclude
static bool myFullType
Whether the type id or full type should be used.
std::map< long long int, PCOSMRelation * > RelationsMap
static double parseHeight(const std::map< std::string, std::string > &attrs, long long int id)
static std::set< std::string > initMyKeysToInclude()
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.
unsigned node
An internal definition of a loaded edge.
bool myIsClosed
Information whether this area is closed.
long long int id
The edge's id.
std::map< std::string, std::string > myAttributes
Additional attributes.
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
std::string name
The edge's name (if any)
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