void _createWay(const long wayId, const unsigned int startNodeId, const unsigned int endNodeId) { // Make sure way in question does not already exist in map CPPUNIT_ASSERT_EQUAL(_map->containsWay(wayId), false ); boost::shared_ptr<Way>newWay(new Way(Status::Unknown1, wayId, 1.0)); // Make sure there are nodes to add if ( startNodeId <= endNodeId ) { // Create the nodes and and add them to the map, if necessary for ( unsigned int i = startNodeId; i <= endNodeId; i++ ) { // Make sure map does not already have node in question if ( _map->containsNode(i) == false ) { boost::shared_ptr<Node> createNode(new Node(Status::Unknown1, i, i * 1.0, i * 1.0, 1.0)); _map->addNode(createNode); } // Add the node into the new way newWay->addNode(i); } } else { LOG_DEBUG("Adding way to map, but could not add any nodes due to start ID of " << startNodeId << " and end node ID " << endNodeId ); } // Tag the way as a highway to ensure it passes linear test newWay->setTag("highway", "road"); // Add the way to the map _map->addWay(newWay); LOG_DEBUG("Way added to map with ID " << newWay->getId()); }
void OSMData::startElementHandler (const XML_Char *name, const XML_Char **atts) { // Les differents element XML d'un OSM sont : // osm, bounds, node, way, relation, nd, member, tag // On peut donc, presque, se contenter de tester le 1er chr ce qui va mieux // qu'un strcmp // Mesure sur rhone-alpes.osm (2.4G) GCC 4.5.0 MinGW en "-O2 -DNDEBUG -g" : // strcmp = 80.0s, switch = 78.7s + newND fixe = 78.1s switch (name[0]) { case 'o' : // XML "osm" element : ignored { checkSyntax (!strcmp (name, "osm")); } break; case 'b' : // XML "bounds" element { checkSyntax (!strcmp (name, "bounds")); m_filebound.min.lat = fixedlatlon (value (atts, "minlat")); m_filebound.max.lat = fixedlatlon (value (atts, "maxlat")); m_filebound.min.lon = fixedlatlon (value (atts, "minlon")); m_filebound.max.lon = fixedlatlon (value (atts, "maxlon")); } break; case 'n' : // XML "node" or "nd" element { if (name[1] == 'o') { checkSyntax (!strcmp (name, "node")); newNode (atts); } else { checkSyntax (!strcmp (name, "nd")); #if 1 // Pas la peine de chercher, "ref" est toujours atts[0] ? checkSyntax (! strcmp (atts[0], "ref")); newND (idvalue(atts[1])); #else newND (idvalue(value(atts, "ref"))); #endif } } break; case 'w' : // XML "way" element { checkSyntax (!strcmp (name, "way")); newWay (atts); } break; case 'r' : // XML "relation" element { checkSyntax (!strcmp (name, "relation")); newRelation (atts); } break; case 'm' : // XML "member" element { checkSyntax (!strcmp (name, "member")); newMember (idvalue(value(atts, "ref")), eltvalue(value(atts, "type")), value(atts, "role")); } break; case 't' : // XML "tag" element { checkSyntax (!strcmp (name, "tag")); // Pas la peine de chercher, c'est toujours 0="k" et 2="v" ... ? addTag (value(atts, "k"), value(atts, "v")); } break; } }