55 #ifdef CHECK_MEMORY_LEAKS
57 #endif // CHECK_MEMORY_LEAKS
70 std::set<std::string> result;
71 result.insert(
"highway");
72 result.insert(
"waterway");
73 result.insert(
"aeroway");
74 result.insert(
"aerialway");
75 result.insert(
"power");
76 result.insert(
"man_made");
77 result.insert(
"building");
78 result.insert(
"leisure");
79 result.insert(
"amenity");
80 result.insert(
"shop");
81 result.insert(
"tourism");
82 result.insert(
"historic");
83 result.insert(
"landuse");
84 result.insert(
"natural");
85 result.insert(
"military");
86 result.insert(
"boundary");
87 result.insert(
"admin_level");
88 result.insert(
"sport");
89 result.insert(
"polygon");
90 result.insert(
"place");
91 result.insert(
"population");
92 result.insert(
"openGeoDB:population");
93 result.insert(
"openGeoDB:name");
100 if (!oc.
isSet(
"osm-files")) {
106 std::map<long long int, PCOSMNode*> nodes;
107 bool withAttributes = oc.
getBool(
"all-attributes");
110 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
113 WRITE_ERROR(
"Could not open osm-file '" + *file +
"'.");
118 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
128 RelationsHandler relationsHandler(additionalWays, relations, withAttributes, *m);
129 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
138 EdgesHandler edgesHandler(nodes, edges, additionalWays, withAttributes, *m);
139 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
147 const bool useName = oc.
getBool(
"osm.use-name");
149 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
172 std::string unknownPolyType =
"";
173 for (std::map<std::string, std::string>::iterator it = e->
myAttributes.begin(); it != e->
myAttributes.end(); ++it) {
174 const std::string& key = it->first;
175 const std::string& value = it->second;
176 const std::string fullType = key +
"." + value;
177 if (tm.
has(key +
"." + value)) {
178 index =
addPolygon(e, vec, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
179 }
else if (tm.
has(key)) {
180 index =
addPolygon(e, vec, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
182 unknownPolyType = fullType;
186 if (index == 0 && !def.
discard && unknownPolyType !=
"") {
187 addPolygon(e, vec, def, unknownPolyType, index, useName, toFill, ignorePruning, withAttributes);
193 for (std::map<long long int, PCOSMNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i) {
206 std::string unKnownPOIType =
"";
207 for (std::map<std::string, std::string>::iterator it = n->
myAttributes.begin(); it != n->
myAttributes.end(); ++it) {
208 const std::string& key = it->first;
209 const std::string& value = it->second;
210 const std::string fullType = key +
"." + value;
211 if (tm.
has(key +
"." + value)) {
212 index =
addPOI(n, pos, tm.
get(fullType), fullType, index, toFill, ignorePruning, withAttributes);
213 }
else if (tm.
has(key)) {
214 index =
addPOI(n, pos, tm.
get(key), fullType, index, toFill, ignorePruning, withAttributes);
216 unKnownPOIType = fullType;
220 if (index == 0 && !def.
discard && unKnownPOIType !=
"") {
221 addPOI(n, pos, def, unKnownPOIType, index, toFill, ignorePruning, withAttributes);
225 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
229 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
233 for (Relations::iterator i = relations.begin(); i != relations.end(); ++i) {
244 const bool closedShape = vec.front() == vec.back();
245 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
251 if (withAttributes) {
254 if (!toFill.
add(poly, ignorePruning)) {
264 int index,
PCPolyContainer& toFill,
bool ignorePruning,
bool withAttributes) {
268 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
274 if (withAttributes) {
277 if (!toFill.
add(poi, ignorePruning)) {
290 bool withAttributes,
MsgHandler& errorHandler) :
291 SUMOSAXHandler(
"osm - file"), myWithAttributes(withAttributes), myErrorHandler(errorHandler),
292 myToFill(toFill), myLastNodeID(-1) {}
300 myParentElements.push_back(element);
308 if (myToFill.find(
id) == myToFill.end()) {
321 myToFill[toAdd->
id] = toAdd;
324 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_NODE
325 && myLastNodeID != -1) {
330 myErrorHandler.inform(
"Empty key in a a tag while parsing node '" +
toString(myLastNodeID) +
"' occured.");
336 myToFill[myLastNodeID]->myAttributes[key] = value;
346 myParentElements.pop_back();
358 myAdditionalWays(additionalWays),
359 myRelations(relations),
360 myWithAttributes(withAttributes),
361 myErrorHandler(errorHandler),
362 myCurrentRelation(0) {
372 myParentElements.push_back(element);
376 myCurrentWays.clear();
378 if (action ==
"delete" || !ok) {
379 myCurrentRelation = 0;
383 myRelations.push_back(myCurrentRelation);
385 }
else if (myCurrentRelation == 0) {
393 if (role ==
"outer" || role ==
"inner") {
395 if (memberType ==
"way") {
396 myCurrentWays.push_back(ref);
403 && myCurrentRelation != 0) {
408 myErrorHandler.inform(
"Empty key in a a tag while parsing way '" +
toString(myCurrentRelation) +
"' occured.");
415 myCurrentRelation->name = value;
417 for (std::vector<long long int>::iterator it = myCurrentWays.begin(); it != myCurrentWays.end(); ++it) {
418 myAdditionalWays[*it] = myCurrentRelation;
421 myCurrentRelation->myAttributes[key] = value;
428 myParentElements.pop_back();
430 myCurrentRelation = 0;
431 myCurrentWays.clear();
442 bool withAttributes,
MsgHandler& errorHandler) :
444 myWithAttributes(withAttributes),
445 myErrorHandler(errorHandler),
446 myOSMNodes(osmNodes),
448 myAdditionalWays(additionalWays) {
458 myParentElements.push_back(element);
467 myCurrentEdge->id = id;
468 myCurrentEdge->myIsClosed =
false;
469 myKeep = (myAdditionalWays.find(
id) != myAdditionalWays.end());
476 if (myOSMNodes.find(ref) == myOSMNodes.end()) {
480 myCurrentEdge->myCurrentNodes.push_back(ref);
484 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_WAY
485 && myCurrentEdge != 0) {
490 myErrorHandler.inform(
"Empty key in a a tag while parsing way '" +
toString(myCurrentEdge->id) +
"' occured.");
497 myCurrentEdge->name = value;
501 myCurrentEdge->myAttributes[key] = value;
508 myParentElements.pop_back();
511 RelationsMap::const_iterator it = myAdditionalWays.find(myCurrentEdge->id);
512 if (it != myAdditionalWays.end()) {
513 myCurrentEdge->myAttributes.insert((*it).second->myAttributes.begin(), (*it).second->myAttributes.end());
515 myEdgeMap[myCurrentEdge->id] = myCurrentEdge;
517 delete myCurrentEdge;
std::string id
The new type id to use.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
SUMOReal lat
The latitude the node is located at.
An internal definition of a loaded edge.
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
NodesHandler(std::map< long long int, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
static int addPOI(const PCOSMNode *node, const Position &pos, const PCTypeMap::TypeDef &def, const std::string &fullType, int index, PCPolyContainer &toFill, bool ignorePruning, bool withAttributes)
try add the POI and return the next index on success
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
static void loadIfSet(OptionsCont &oc, PCPolyContainer &toFill, PCTypeMap &tm)
Loads pois/polygons assumed to be stored as OSM-XML.
void myEndElement(int element)
Called when a closing tag occurs.
A single definition of values that shall be used for a given type.
bool isInStringVector(const std::string &optionName, const std::string &itemName)
Returns the named option is a list of string values containing the specified item.
static bool isReadable(std::string path)
Checks whether the given file is readable.
An internal definition of a loaded relation.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
~EdgesHandler()
Destructor.
SUMOReal layer
The layer to use.
long long int id
The node's id.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
RelationsHandler(RelationsMap &additionalWays, Relations &relations, bool withAttributes, MsgHandler &errorHandler)
Constructor.
static std::set< std::string > initMyKeysToInclude()
SAX-handler base for SUMO-files.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
SUMOReal lon
The longitude the node is located at.
~RelationsHandler()
Destructor.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
#define WRITE_WARNING(msg)
bool discard
Information whether polygons of this type shall be discarded.
A storage for loaded polygons and pois.
static OptionsCont & getOptions()
Retrieves the options.
RGBColor color
The color to use.
std::map< long long int, PCOSMEdge * > EdgeMap
long long int id
The edge's id.
A class which extracts relevant way-ids from relations in a parsed OSM-file.
static const std::set< std::string > MyKeysToInclude
std::map< std::string, std::string > myAttributes
Additional attributes.
A storage for type mappings.
const TypeDef & get(const std::string &id)
Returns a type definition.
void myEndElement(int element)
Called when a closing tag occurs.
void myEndElement(int element)
Called when a closing tag occurs.
Encapsulated SAX-Attributes.
A point in 2D or 3D with translation and scaling methods.
std::map< std::string, std::string > myAttributes
Additional attributes.
bool has(const std::string &id)
Returns the information whether the named type is known.
#define PROGRESS_BEGIN_MESSAGE(msg)
A class which extracts OSM-edges from a parsed OSM-file.
std::map< long long int, PCOSMRelation * > RelationsMap
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
bool add(SUMO::Polygon *poly, bool ignorePruning=false)
Adds a polygon to the storage.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
A class which extracts OSM-nodes from a parsed OSM-file.
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
std::string prefix
The prefix to use.
std::vector< PCOSMRelation * > Relations
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
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
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
A storage for options typed value containers)
std::string name
The edge's name (if any)
const TypeDef & getDefault()
get the default type according to the given options
void push_back_noDoublePos(const Position &p)
insert in back a non double position
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
~NodesHandler()
Destructor.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
#define PROGRESS_DONE_MESSAGE()
EdgesHandler(const std::map< long long int, PCOSMNode * > &osmNodes, EdgeMap &toFill, const RelationsMap &additionalWays, bool withAttributes, MsgHandler &errorHandler)
Constructor.
bool allowFill
Information whether polygons of this type can be filled.
An internal representation of an OSM-node.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.