60 std::set<std::string> result;
61 result.insert(
"highway");
62 result.insert(
"railway");
63 result.insert(
"railway:position");
64 result.insert(
"railway:position:exact");
65 result.insert(
"waterway");
66 result.insert(
"aeroway");
67 result.insert(
"aerialway");
68 result.insert(
"power");
69 result.insert(
"man_made");
70 result.insert(
"building");
71 result.insert(
"leisure");
72 result.insert(
"amenity");
73 result.insert(
"shop");
74 result.insert(
"tourism");
75 result.insert(
"historic");
76 result.insert(
"landuse");
77 result.insert(
"natural");
78 result.insert(
"military");
79 result.insert(
"boundary");
80 result.insert(
"admin_level");
81 result.insert(
"sport");
82 result.insert(
"polygon");
83 result.insert(
"place");
84 result.insert(
"population");
85 result.insert(
"openGeoDB:population");
86 result.insert(
"openGeoDB:name");
93 if (!oc.
isSet(
"osm-files")) {
99 std::map<long long int, PCOSMNode*> nodes;
100 bool withAttributes = oc.
getBool(
"all-attributes");
103 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
106 WRITE_ERROR(
"Could not open osm-file '" + *file +
"'.");
112 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
122 RelationsHandler relationsHandler(additionalWays, relations, withAttributes, *m);
123 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
133 EdgesHandler edgesHandler(nodes, edges, additionalWays, withAttributes, *m);
134 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
143 const bool useName = oc.
getBool(
"osm.use-name");
146 if (mergeRelationsThreshold >= 0) {
148 if (!rel->keep || rel->myWays.empty()) {
153 for (
auto it = rel->myWays.begin(); it != rel->myWays.end();) {
154 if (edges.count(*it) == 0 || edges[*it]->myCurrentNodes.empty()) {
155 it = rel->myWays.erase(it);
157 numNodes += (int)edges[*it]->myCurrentNodes.size();
172 std::set<long long int> remaining(rel->myWays.begin(), rel->myWays.end());
173 PCOSMEdge* minEdge = edges[rel->myWays.front()];
176 minEdge->standalone =
false;
177 remaining.erase(minEdge->id);
179 while (!remaining.empty()) {
181 double minDist = std::numeric_limits<double>::max();
182 bool minFront =
false;
183 for (
long long int wayID : remaining) {
189 if (frontDist < minDist) {
194 if (backDist < minDist) {
200 if (minDist > mergeRelationsThreshold) {
202 for (
long long int wayID : remaining) {
216 if (length > mergeRelationsThreshold) {
218 "' (name:" + e->
name +
" reason: found gap of " +
toString(minDist) +
219 "m to way '" +
toString(minEdge->id) +
220 "')\n Total length of remaining ways: " +
toString(length) +
"m.");
232 minEdge->standalone =
false;
233 remaining.erase(minEdge->id);
241 for (
long long int wayID : rel->myWays) {
250 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
256 if (!e->
standalone && mergeRelationsThreshold >= 0) {
277 std::string unknownPolyType =
"";
278 for (std::map<std::string, std::string>::iterator it = e->
myAttributes.begin(); it != e->
myAttributes.end(); ++it) {
279 const std::string& key = it->first;
280 const std::string& value = it->second;
281 const std::string fullType = key +
"." + value;
282 if (tm.
has(key +
"." + value)) {
283 index =
addPolygon(e, vec, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
284 }
else if (tm.
has(key)) {
285 index =
addPolygon(e, vec, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
287 unknownPolyType = fullType;
291 if (index == 0 && !def.
discard && unknownPolyType !=
"") {
292 addPolygon(e, vec, def, unknownPolyType, index, useName, toFill, ignorePruning, withAttributes);
298 for (std::map<long long int, PCOSMNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i) {
311 std::string unKnownPOIType =
"";
312 for (std::map<std::string, std::string>::iterator it = n->
myAttributes.begin(); it != n->
myAttributes.end(); ++it) {
313 const std::string& key = it->first;
314 const std::string& value = it->second;
315 const std::string fullType = key +
"." + value;
316 if (tm.
has(key +
"." + value)) {
317 index =
addPOI(n, pos, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
318 }
else if (tm.
has(key)) {
319 index =
addPOI(n, pos, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
321 unKnownPOIType = fullType;
325 if (index == 0 && !def.
discard && unKnownPOIType !=
"") {
326 addPOI(n, pos, def, unKnownPOIType, index, useName, toFill, ignorePruning, withAttributes);
330 for (std::map<long long int, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
334 for (EdgeMap::iterator i = edges.begin(); i != edges.end(); ++i) {
338 for (Relations::iterator i = relations.begin(); i != relations.end(); ++i) {
357 const bool closedShape = vec.front() == vec.back();
358 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
364 if (withAttributes) {
367 if (!toFill.
add(poly, ignorePruning)) {
378 int index,
bool useName,
PCPolyContainer& toFill,
bool ignorePruning,
bool withAttributes) {
382 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
387 def.
color, pos,
false,
"", 0, 0, (
double)def.
layer);
388 if (withAttributes) {
391 if (!toFill.
add(poi, ignorePruning)) {
404 bool withAttributes,
MsgHandler& errorHandler) :
405 SUMOSAXHandler(
"osm - file"), myWithAttributes(withAttributes), myErrorHandler(errorHandler),
406 myToFill(toFill), myLastNodeID(-1) {}
417 long long int id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
445 }
else if (key ==
"") {
474 myAdditionalWays(additionalWays),
475 myRelations(relations),
478 myCurrentRelation(nullptr) {
493 if (action ==
"delete") {
511 if (role ==
"outer" || role ==
"inner") {
513 if (memberType ==
"way") {
562 bool withAttributes,
MsgHandler& errorHandler) :
566 myOSMNodes(osmNodes),
582 const long long int id = attrs.
get<
long long int>(
SUMO_ATTR_ID,
nullptr, ok);
584 if (action ==
"delete" || !ok) {
597 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
virtual 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.