58 std::set<std::string> result;
59 result.insert(
"highway");
60 result.insert(
"railway");
61 result.insert(
"railway:position");
62 result.insert(
"railway:position:exact");
63 result.insert(
"waterway");
64 result.insert(
"aeroway");
65 result.insert(
"aerialway");
66 result.insert(
"power");
67 result.insert(
"man_made");
68 result.insert(
"building");
69 result.insert(
"leisure");
70 result.insert(
"amenity");
71 result.insert(
"shop");
72 result.insert(
"tourism");
73 result.insert(
"historic");
74 result.insert(
"landuse");
75 result.insert(
"natural");
76 result.insert(
"military");
77 result.insert(
"boundary");
78 result.insert(
"admin_level");
79 result.insert(
"sport");
80 result.insert(
"polygon");
81 result.insert(
"place");
82 result.insert(
"population");
83 result.insert(
"barrier");
84 result.insert(
"openGeoDB:population");
85 result.insert(
"openGeoDB:name");
91 if (!oc.
isSet(
"osm-files")) {
97 std::map<long long int, PCOSMNode*> nodes;
98 bool withAttributes = oc.
getBool(
"all-attributes");
101 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
109 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
119 RelationsHandler relationsHandler(additionalWays, relations, withAttributes, *m);
120 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
129 EdgesHandler edgesHandler(nodes, edges, additionalWays, withAttributes, *m);
130 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
138 const bool useName = oc.
getBool(
"osm.use-name");
141 if (mergeRelationsThreshold >= 0) {
143 if (!rel->keep || rel->myWays.empty()) {
148 for (
auto it = rel->myWays.begin(); it != rel->myWays.end();) {
149 if (edges.count(*it) == 0 || edges[*it]->myCurrentNodes.empty()) {
150 it = rel->myWays.erase(it);
152 numNodes += (int)edges[*it]->myCurrentNodes.size();
157 WRITE_WARNINGF(
TL(
"Could not import polygon from relation '%' (missing ways)"), rel->id);
167 std::set<long long int> remaining(rel->myWays.begin(), rel->myWays.end());
168 PCOSMEdge* minEdge = edges[rel->myWays.front()];
172 remaining.erase(minEdge->
id);
174 while (!remaining.empty()) {
176 double minDist = std::numeric_limits<double>::max();
177 bool minFront =
false;
178 for (
long long int wayID : remaining) {
184 if (frontDist < minDist) {
189 if (backDist < minDist) {
195 if (minDist > mergeRelationsThreshold) {
197 for (
long long int wayID : remaining) {
211 if (length > mergeRelationsThreshold) {
212 WRITE_WARNINGF(
TL(
"Could not import polygon from relation '%' (name:% reason: found gap of %m to way '%')\n Total length of remaining ways: %m."),
213 rel->id, e->
name, minDist, minEdge->
id, length);
226 remaining.erase(minEdge->
id);
234 for (
long long int wayID : rel->myWays) {
243 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
249 if (!e->
standalone && mergeRelationsThreshold >= 0) {
270 std::string unknownPolyType =
"";
271 for (std::map<std::string, std::string>::iterator it = e->
myAttributes.begin(); it != e->
myAttributes.end(); ++it) {
272 const std::string& key = it->first;
273 const std::string& value = it->second;
274 const std::string fullType = key +
"." + value;
275 if (tm.
has(key +
"." + value)) {
276 index =
addPolygon(e, vec, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
277 }
else if (tm.
has(key)) {
278 index =
addPolygon(e, vec, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
280 unknownPolyType = fullType;
284 if (index == 0 && !def.
discard && unknownPolyType !=
"") {
285 addPolygon(e, vec, def, unknownPolyType, index, useName, toFill, ignorePruning, withAttributes);
291 for (std::map<long long int, PCOSMNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i) {
304 std::string unKnownPOIType =
"";
305 for (std::map<std::string, std::string>::iterator it = n->
myAttributes.begin(); it != n->
myAttributes.end(); ++it) {
306 const std::string& key = it->first;
307 const std::string& value = it->second;
308 const std::string fullType = key +
"." + value;
309 if (tm.
has(key +
"." + value)) {
310 index =
addPOI(n, pos, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
311 }
else if (tm.
has(key)) {
312 index =
addPOI(n, pos, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
314 unKnownPOIType = fullType;
318 if (index == 0 && !def.
discard && unKnownPOIType !=
"") {
319 addPOI(n, pos, def, unKnownPOIType, index, useName, toFill, ignorePruning, withAttributes);
323 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
327 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
331 for (Relations::iterator i = relations.begin(); i != relations.end(); ++i) {
350 const bool closedShape = vec.front() == vec.back();
351 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
357 if (withAttributes) {
360 if (!toFill.
add(poly, ignorePruning)) {
371 int index,
bool useName,
PCPolyContainer& toFill,
bool ignorePruning,
bool withAttributes) {
375 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
380 def.
color, pos,
false,
"", 0,
false, 0, (
double)def.
layer);
381 if (withAttributes) {
384 if (!toFill.
add(poi, ignorePruning)) {
397 bool withAttributes,
MsgHandler& errorHandler) :
398 SUMOSAXHandler(
"osm - file"), myWithAttributes(withAttributes), myErrorHandler(errorHandler),
399 myToFill(toFill), myLastNodeID(-1) {}
407 myParentElements.push_back(element);
410 long long int id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
415 if (myToFill.find(
id) == myToFill.end()) {
427 myToFill[toAdd->
id] = toAdd;
430 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_NODE
431 && myLastNodeID != -1) {
436 myToFill[myLastNodeID]->name = value;
437 }
else if (key ==
"") {
438 myErrorHandler.inform(
"Empty key in a a tag while parsing node '" +
toString(myLastNodeID) +
"' occurred.");
444 myToFill[myLastNodeID]->myAttributes[key] = value;
454 myParentElements.pop_back();
466 myAdditionalWays(additionalWays),
467 myRelations(relations),
468 myWithAttributes(withAttributes),
469 myErrorHandler(errorHandler),
470 myCurrentRelation(nullptr) {
480 myParentElements.push_back(element);
483 myCurrentWays.clear();
486 if (action ==
"delete" || !ok) {
487 myCurrentRelation =
nullptr;
490 myCurrentRelation->keep =
false;
491 myCurrentRelation->id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
492 myRelations.push_back(myCurrentRelation);
495 }
else if (myCurrentRelation ==
nullptr) {
503 if (role ==
"outer" || role ==
"inner") {
505 if (memberType ==
"way") {
506 myCurrentWays.push_back(ref);
513 && myCurrentRelation !=
nullptr) {
518 myErrorHandler.inform(
"Empty key in a a tag while parsing way '" +
toString(myCurrentRelation) +
"' occurred.");
525 myCurrentRelation->name = value;
527 myCurrentRelation->keep =
true;
528 for (std::vector<long long int>::iterator it = myCurrentWays.begin(); it != myCurrentWays.end(); ++it) {
529 myAdditionalWays[*it] = myCurrentRelation;
532 myCurrentRelation->myAttributes[key] = value;
539 myParentElements.pop_back();
541 myCurrentRelation->myWays = myCurrentWays;
542 myCurrentRelation =
nullptr;
543 myCurrentWays.clear();
554 bool withAttributes,
MsgHandler& errorHandler) :
556 myWithAttributes(withAttributes),
557 myErrorHandler(errorHandler),
558 myOSMNodes(osmNodes),
560 myAdditionalWays(additionalWays) {
570 myParentElements.push_back(element);
574 const long long int id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
576 if (action ==
"delete" || !ok) {
577 myCurrentEdge =
nullptr;
581 myCurrentEdge->id = id;
582 myCurrentEdge->myIsClosed =
false;
583 myCurrentEdge->standalone =
false;
584 myKeep = (myAdditionalWays.find(
id) != myAdditionalWays.end());
587 if (element ==
SUMO_TAG_ND && myCurrentEdge !=
nullptr) {
589 const long long int ref = attrs.
get<
long long int>(
SUMO_ATTR_REF,
nullptr, ok);
591 if (myOSMNodes.find(ref) == myOSMNodes.end()) {
592 WRITE_WARNINGF(
TL(
"The referenced geometry information (ref='%') is not known"), ref);
595 myCurrentEdge->myCurrentNodes.push_back(ref);
599 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_WAY
600 && myCurrentEdge !=
nullptr) {
605 myErrorHandler.inform(
"Empty key in a a tag while parsing way '" +
toString(myCurrentEdge->id) +
"' occurred.");
612 myCurrentEdge->name = value;
615 myCurrentEdge->standalone =
true;
617 myCurrentEdge->myAttributes[key] = value;
624 myParentElements.pop_back();
625 if (element ==
SUMO_TAG_WAY && myCurrentEdge !=
nullptr) {
627 RelationsMap::const_iterator it = myAdditionalWays.find(myCurrentEdge->id);
628 if (it != myAdditionalWays.end()) {
629 myCurrentEdge->myAttributes.insert((*it).second->myAttributes.begin(), (*it).second->myAttributes.end());
631 myEdgeMap[myCurrentEdge->id] = myCurrentEdge;
633 delete myCurrentEdge;
635 myCurrentEdge =
nullptr;
#define WRITE_WARNINGF(...)
#define WRITE_MESSAGEF(...)
#define WRITE_ERRORF(...)
#define PROGRESS_BEGIN_TIME_MESSAGE(msg)
#define PROGRESS_TIME_MESSAGE(before)
@ SUMO_TAG_NODE
alternative definition for junction
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static bool isReadable(std::string path)
Checks whether the given file is readable.
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
bool isInStringVector(const std::string &optionName, const std::string &itemName) const
Returns the named option is a list of string values containing the specified item.
A class which extracts OSM-edges from a parsed OSM-file.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void myEndElement(int element)
Called when a closing tag occurs.
~EdgesHandler()
Destructor.
EdgesHandler(const std::map< long long int, PCOSMNode * > &osmNodes, EdgeMap &toFill, const RelationsMap &additionalWays, bool withAttributes, MsgHandler &errorHandler)
Constructor.
A class which extracts OSM-nodes from a parsed OSM-file.
NodesHandler(std::map< long long int, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
void myEndElement(int element)
Called when a closing tag occurs.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
~NodesHandler()
Destructor.
A class which extracts relevant way-ids from relations in a parsed OSM-file.
void myEndElement(int element)
Called when a closing tag occurs.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
RelationsHandler(RelationsMap &additionalWays, Relations &relations, bool withAttributes, MsgHandler &errorHandler)
Constructor.
~RelationsHandler()
Destructor.
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 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.
bool add(SUMOPolygon *poly, bool ignorePruning=false)
Adds a polygon to the storage.
A storage for type mappings.
const TypeDef & getDefault()
get the default type according to the given options
const TypeDef & get(const std::string &id)
Returns a type definition.
bool has(const std::string &id)
Returns the information whether the named type is known.
void updateParameters(const Parameterised::Map &mapArg)
Adds or updates all given parameters from the map.
A point in 2D or 3D with translation and scaling methods.
static const Position INVALID
used to indicate that a position is valid
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
void push_back_noDoublePos(const Position &p)
insert in back a non double position
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
SAX-handler base for SUMO-files.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.
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.
double lat
The latitude the node is located at.
double lon
The longitude the node is located at.
std::string name
The nodes name (if any)
long long int id
The node's id.
std::map< std::string, std::string > myAttributes
Additional attributes.
An internal definition of a loaded relation.
A single definition of values that shall be used for a given type.
bool discard
Information whether polygons of this type shall be discarded.
std::string prefix
The prefix to use.
double layer
The layer to use.
bool allowFill
Information whether polygons of this type can be filled.
std::string id
The new type id to use.
RGBColor color
The color to use.