54 #ifdef CHECK_MEMORY_LEAKS
56 #endif // CHECK_MEMORY_LEAKS
69 std::set<std::string> result;
70 result.insert(
"waterway");
71 result.insert(
"aeroway");
72 result.insert(
"aerialway");
73 result.insert(
"power");
74 result.insert(
"man_made");
75 result.insert(
"building");
76 result.insert(
"leisure");
77 result.insert(
"amenity");
78 result.insert(
"shop");
79 result.insert(
"tourism");
80 result.insert(
"historic");
81 result.insert(
"landuse");
82 result.insert(
"natural");
83 result.insert(
"military");
84 result.insert(
"boundary");
85 result.insert(
"admin_level");
86 result.insert(
"sport");
87 result.insert(
"polygon");
88 result.insert(
"place");
89 result.insert(
"population");
90 result.insert(
"openGeoDB:population");
91 result.insert(
"openGeoDB:name");
98 if (!oc.
isSet(
"osm-files")) {
104 std::map<SUMOLong, PCOSMNode*> nodes;
105 bool withAttributes = oc.
getBool(
"all-attributes");
108 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
111 WRITE_ERROR(
"Could not open osm-file '" + *file +
"'.");
121 std::map<std::string, PCOSMEdge*> edges;
122 EdgesHandler edgesHandler(nodes, edges, withAttributes, *m);
123 for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
131 const bool useName = oc.
getBool(
"osm.use-name");
133 for (std::map<std::string, PCOSMEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
149 WRITE_WARNING(
"Unable to project coordinates for polygon '" + e->
id +
"'.");
156 std::string unknownPolyType =
"";
157 for (std::map<std::string, std::string>::iterator it = e->
myAttributes.begin(); it != e->
myAttributes.end(); ++it) {
158 const std::string& key = it->first;
159 const std::string& value = it->second;
160 const std::string fullType = key +
"." + value;
161 if (tm.
has(key +
"." + value)) {
162 index =
addPolygon(e, vec, tm.
get(fullType), fullType, index, useName, toFill, ignorePruning, withAttributes);
163 }
else if (tm.
has(key)) {
164 index =
addPolygon(e, vec, tm.
get(key), fullType, index, useName, toFill, ignorePruning, withAttributes);
166 unknownPolyType = fullType;
170 if (index == 0 && !def.
discard && unknownPolyType !=
"") {
171 addPolygon(e, vec, def, unknownPolyType, index, useName, toFill, ignorePruning, withAttributes);
177 for (std::map<SUMOLong, PCOSMNode*>::iterator i = nodes.begin(); i != nodes.end(); ++i) {
190 std::string unKnownPOIType =
"";
191 for (std::map<std::string, std::string>::iterator it = n->
myAttributes.begin(); it != n->
myAttributes.end(); ++it) {
192 const std::string& key = it->first;
193 const std::string& value = it->second;
194 const std::string fullType = key +
"." + value;
195 if (tm.
has(key +
"." + value)) {
196 index =
addPOI(n, pos, tm.
get(fullType), fullType, index, toFill, ignorePruning, withAttributes);
197 }
else if (tm.
has(key)) {
198 index =
addPOI(n, pos, tm.
get(key), fullType, index, toFill, ignorePruning, withAttributes);
200 unKnownPOIType = fullType;
204 if (index == 0 && !def.
discard && unKnownPOIType !=
"") {
205 addPOI(n, pos, def, unKnownPOIType, index, toFill, ignorePruning, withAttributes);
209 for (std::map<SUMOLong, PCOSMNode*>::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
213 for (std::map<std::string, PCOSMEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
224 const bool closedShape = vec.front() == vec.back();
225 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
226 const std::string
id = def.
prefix + (useName && edge->
name !=
"" ? edge->
name : edge->
id) + idSuffix;
231 if (withAttributes) {
234 if (!toFill.
insert(
id, poly, def.
layer, ignorePruning)) {
244 int index,
PCPolyContainer& toFill,
bool ignorePruning,
bool withAttributes) {
248 const std::string idSuffix = (index == 0 ?
"" :
"#" +
toString(index));
254 if (withAttributes) {
257 if (!toFill.
insert(
id, poi, def.
layer, ignorePruning)) {
270 bool withAttributes,
MsgHandler& errorHandler) :
271 SUMOSAXHandler(
"osm - file"), myWithAttributes(withAttributes), myErrorHandler(errorHandler),
272 myToFill(toFill), myLastNodeID(-1) {}
280 myParentElements.push_back(element);
288 if (myToFill.find(
id) == myToFill.end()) {
301 myToFill[toAdd->
id] = toAdd;
304 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_NODE
305 && myLastNodeID != -1) {
310 myErrorHandler.inform(
"Empty key in a a tag while parsing node '" +
toString(myLastNodeID) +
"' occured.");
316 myToFill[myLastNodeID]->myAttributes[key] = value;
326 myParentElements.pop_back();
334 std::map<std::string, PCOSMEdge*>& toFill,
bool withAttributes,
MsgHandler& errorHandler)
335 :
SUMOSAXHandler(
"osm - file"), myWithAttributes(withAttributes), myErrorHandler(errorHandler),
336 myOSMNodes(osmNodes), myEdgeMap(toFill) {
346 myParentElements.push_back(element);
355 myCurrentEdge->id = id;
356 myCurrentEdge->myIsClosed =
false;
364 if (myOSMNodes.find(ref) == myOSMNodes.end()) {
368 myCurrentEdge->myCurrentNodes.push_back(ref);
372 if (element ==
SUMO_TAG_TAG && myParentElements.size() > 2 && myParentElements[myParentElements.size() - 2] ==
SUMO_TAG_WAY
373 && myCurrentEdge != 0) {
378 myErrorHandler.inform(
"Empty key in a a tag while parsing way '" +
toString(myCurrentEdge->id) +
"' occured.");
385 myCurrentEdge->name = value;
389 myCurrentEdge->myAttributes[key] = value;
396 myParentElements.pop_back();
399 myEdgeMap[myCurrentEdge->id] = myCurrentEdge;
401 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) ...
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.
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 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)
std::vector< SUMOLong > myCurrentNodes
The list of nodes this edge is made of.
static std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
~EdgesHandler()
Destructor.
bool insert(const std::string &id, Polygon *poly, int layer, bool ignorePruning=false)
Adds a polygon to the storage.
EdgesHandler(const std::map< SUMOLong, PCOSMNode * > &osmNodes, std::map< std::string, PCOSMEdge * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Constructor.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
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.
#define WRITE_WARNING(msg)
std::string id
The edge's id.
bool discard
Information whether polygons of this type shall be discarded.
A storage for loaded polygons and pois.
static OptionsCont & getOptions()
Retrieves the options.
NodesHandler(std::map< SUMOLong, PCOSMNode * > &toFill, bool withAttributes, MsgHandler &errorHandler)
Contructor.
RGBColor color
The color to use.
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.
static bool exists(std::string path)
Checks whether the given file exists.
SUMOLong id
The node's id.
#define PROGRESS_BEGIN_MESSAGE(msg)
A class which extracts OSM-edges from a parsed OSM-file.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
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.
std::string prefix
The prefix to use.
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
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)
int layer
The layer to use.
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()
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.