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-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// ===========================================================================
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 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
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);
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
132private:
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
140protected:
146 public:
152 NodesHandler(std::map<long long int, PCOSMNode*>& toFill, bool withAttributes,
153 MsgHandler& errorHandler);
154
155
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
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
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.
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
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
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.
std::vector< PCOSMRelation * > Relations
static const std::set< std::string > MyKeysToInclude
std::map< long long int, PCOSMRelation * > RelationsMap
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.
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