60 std::set<std::string> result;
61 result.insert(
"highway");
62 result.insert(
"waterway");
63 result.insert(
"aeroway");
64 result.insert(
"aerialway");
65 result.insert(
"power");
66 result.insert(
"man_made");
67 result.insert(
"building");
68 result.insert(
"leisure");
69 result.insert(
"amenity");
70 result.insert(
"shop");
71 result.insert(
"tourism");
72 result.insert(
"historic");
73 result.insert(
"landuse");
74 result.insert(
"natural");
75 result.insert(
"military");
76 result.insert(
"boundary");
77 result.insert(
"admin_level");
78 result.insert(
"sport");
79 result.insert(
"polygon");
80 result.insert(
"place");
81 result.insert(
"population");
82 result.insert(
"openGeoDB:population");
83 result.insert(
"openGeoDB:name");
90 if (!oc.
isSet(
"osm-files")) {
96 std::map<long long int, PCOSMNode*> nodes;
97 bool withAttributes = oc.
getBool(
"all-attributes");
100 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
103 WRITE_ERROR(
"Could not open osm-file '" + *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) {
130 EdgesHandler edgesHandler(nodes, edges, additionalWays, withAttributes, *m);
131 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
140 const bool useName = oc.
getBool(
"osm.use-name");
143 if (mergeRelationsThreshold >= 0) {
145 if (!rel->keep || rel->myWays.empty()) {
150 for (
auto it = rel->myWays.begin(); it != rel->myWays.end();) {
151 if (edges.count(*it) == 0 || edges[*it]->myCurrentNodes.empty()) {
152 it = rel->myWays.erase(it);
154 numNodes += (int)edges[*it]->myCurrentNodes.size();
169 std::set<long long int> remaining(rel->myWays.begin(), rel->myWays.end());
170 PCOSMEdge* minEdge = edges[rel->myWays.front()];
173 minEdge->standalone =
false;
174 remaining.erase(minEdge->id);
176 while (!remaining.empty()) {
178 double minDist = std::numeric_limits<double>::max();
179 bool minFront =
false;
180 for (
long long int wayID : remaining) {
186 if (frontDist < minDist) {
191 if (backDist < minDist) {
197 if (minDist > mergeRelationsThreshold) {
199 for (
long long int wayID : remaining) {
213 if (length > mergeRelationsThreshold) {
215 "' (name:" + e->
name +
" reason: found gap of " +
toString(minDist) +
216 "m to way '" +
toString(minEdge->id) +
217 "')\n Total length of remaining ways: " +
toString(length) +
"m.");
229 minEdge->standalone =
false;
230 remaining.erase(minEdge->id);
238 for (
long long int wayID : rel->myWays) {
247 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
253 if (!e->
standalone && mergeRelationsThreshold >= 0) {
274 std::string unknownPolyType =
"";
275 for (std::map<std::string, std::string>::iterator it = e->
myAttributes.begin(); it != e->
myAttributes.end(); ++it) {
276 const std::string& key = it->first;
277 const std::string& value = it->second;
278 const std::string fullType = key +
"." + value;
279 if (tm.
has(key +
"." + value)) {
280 index =
addPolygon(e, vec, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
281 }
else if (tm.
has(key)) {
282 index =
addPolygon(e, vec, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
284 unknownPolyType = fullType;
288 if (index == 0 && !def.
discard && unknownPolyType !=
"") {
289 addPolygon(e, vec, def, unknownPolyType, index, useName, toFill, ignorePruning, withAttributes);
295 for (std::map<long long int, PCOSMNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i) {
308 std::string unKnownPOIType =
"";
309 for (std::map<std::string, std::string>::iterator it = n->
myAttributes.begin(); it != n->
myAttributes.end(); ++it) {
310 const std::string& key = it->first;
311 const std::string& value = it->second;
312 const std::string fullType = key +
"." + value;
313 if (tm.
has(key +
"." + value)) {
314 index =
addPOI(n, pos, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
315 }
else if (tm.
has(key)) {
316 index =
addPOI(n, pos, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
318 unKnownPOIType = fullType;
322 if (index == 0 && !def.
discard && unKnownPOIType !=
"") {
323 addPOI(n, pos, def, unKnownPOIType, index, useName, toFill, ignorePruning, withAttributes);
327 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
331 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
335 for (Relations::iterator i = relations.begin(); i != relations.end(); ++i) {
354 const bool closedShape = vec.front() == vec.back();
355 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
361 if (withAttributes) {
364 if (!toFill.
add(poly, ignorePruning)) {
375 int index,
bool useName,
PCPolyContainer& toFill,
bool ignorePruning,
bool withAttributes) {
379 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
384 def.
color, pos,
false,
"", 0, 0, (
double)def.
layer);
385 if (withAttributes) {
388 if (!toFill.
add(poi, ignorePruning)) {
401 bool withAttributes,
MsgHandler& errorHandler) :
402 SUMOSAXHandler(
"osm - file"), myWithAttributes(withAttributes), myErrorHandler(errorHandler),
403 myToFill(toFill), myLastNodeID(-1) {}
414 long long int id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
442 }
else if (key ==
"") {
471 myAdditionalWays(additionalWays),
472 myRelations(relations),
475 myCurrentRelation(nullptr) {
490 if (action ==
"delete") {
508 if (role ==
"outer" || role ==
"inner") {
510 if (memberType ==
"way") {
559 bool withAttributes,
MsgHandler& errorHandler) :
563 myOSMNodes(osmNodes),
579 const long long int id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
581 if (action ==
"delete" || !ok) {
594 const long long int ref = attrs.
get<
long long int>(
SUMO_ATTR_REF,
nullptr, ok);
std::string id
The new type id to use.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
std::map< std::string, std::string > myAttributes
Additional attributes.
An internal definition of a loaded edge.
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.
EdgeMap & myEdgeMap
A map of built edges.
A single definition of values that shall be used for a given type.
PCOSMRelation * myCurrentRelation
The currently parsed relation.
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.
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
bool add(SUMOPolygon *poly, bool ignorePruning=false)
Adds a polygon to the storage.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
bool x2cartesian(Position &from, bool includeInBoundary=true)
Converts the given coordinate into a cartesian and optionally update myConvBoundary.
RelationsMap & myAdditionalWays
additional ways which are reference by relations
~EdgesHandler()
Destructor.
static Position convertNodePosition(PCOSMNode *n)
retrieve cartesian coordinate for given node
std::vector< long long int > myCurrentWays
the ways within the current relation
double layer
The layer to use.
long long int myLastNodeID
The id of the last parsed node.
Relations & myRelations
the loaded relations
long long int id
The node's id.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
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.
NodesHandler(std::map< long long int, PCOSMNode *> &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
~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.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
double lon
The longitude the node is located at.
bool keep
whether this relation is a valid polygon
RGBColor color
The color to use.
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
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.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
#define PROGRESS_TIME_MESSAGE(before)
static const std::set< std::string > MyKeysToInclude
double lat
The latitude the node is located at.
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.
PCOSMEdge * myCurrentEdge
The currently built edge.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void myEndElement(int element)
Called when a closing tag occurs.
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
void updateParameter(const std::map< std::string, std::string > &mapArg)
Adds or updates all given parameters from the map.
void myEndElement(int element)
Called when a closing tag occurs.
std::string name
The relation's name (if any)
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
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.
bool myIsClosed
Information whether this area is closed.
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) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
MsgHandler & myErrorHandler
The handler to report errors to (will be the WarningsHandler if –ignore-errors was set) ...
A class which extracts OSM-edges from a parsed OSM-file.
std::map< long long int, PCOSMRelation * > RelationsMap
long long int id
The relation's id.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool myKeep
whether the last edge (way) should be kept because it had a key from the inclusion list ...
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;.
A class which extracts OSM-nodes from a parsed OSM-file.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
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.
std::string prefix
The prefix to use.
std::vector< long long int > myParentElements
Current path in order to know to what occuring values belong.
std::vector< int > myParentElements
Current path in order to know to what occuring values belong.
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.
alternative definition for junction
void inform(std::string msg, bool addType=true)
adds a new error to the list
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
bool myWithAttributes
Whether all attributes shall be stored.
std::vector< long long int > myWays
The list of ways this relation is made of.
std::string name
The nodes name (if any)
void push_back_noDoublePos(const Position &p)
insert in back a non double position
~NodesHandler()
Destructor.
bool myWithAttributes
Whether all attributes shall be stored.
static long getCurrentMillis()
Returns the current time in milliseconds.
EdgesHandler(const std::map< long long int, PCOSMNode *> &osmNodes, EdgeMap &toFill, const RelationsMap &additionalWays, bool withAttributes, MsgHandler &errorHandler)
Constructor.
#define WRITE_MESSAGE(msg)
const std::map< long long int, PCOSMNode * > & myOSMNodes
The previously parsed nodes.
std::map< long long int, PCOSMNode * > & myToFill
The nodes container to fill.
const RelationsMap & myAdditionalWays
additional ways which are reference by relations
bool allowFill
Information whether polygons of this type can be filled.
static const Position INVALID
used to indicate that a position is valid
An internal representation of an OSM-node.