inline void PBFParser::parseDenseNode(ParserThreadData *thread_data) { const OSMPBF::DenseNodes &dense = thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID).dense(); int denseTagIndex = 0; int64_t m_lastDenseID = 0; int64_t m_lastDenseLatitude = 0; int64_t m_lastDenseLongitude = 0; const int number_of_nodes = dense.id_size(); std::vector<ImportNode> extracted_nodes_vector(number_of_nodes); for (int i = 0; i < number_of_nodes; ++i) { m_lastDenseID += dense.id(i); m_lastDenseLatitude += dense.lat(i); m_lastDenseLongitude += dense.lon(i); extracted_nodes_vector[i].node_id = static_cast<NodeID>(m_lastDenseID); extracted_nodes_vector[i].lat = static_cast<int>( COORDINATE_PRECISION * ((double)m_lastDenseLatitude * thread_data->PBFprimitiveBlock.granularity() + thread_data->PBFprimitiveBlock.lat_offset()) / NANO); extracted_nodes_vector[i].lon = static_cast<int>( COORDINATE_PRECISION * ((double)m_lastDenseLongitude * thread_data->PBFprimitiveBlock.granularity() + thread_data->PBFprimitiveBlock.lon_offset()) / NANO); while (denseTagIndex < dense.keys_vals_size()) { const int tagValue = dense.keys_vals(denseTagIndex); if (0 == tagValue) { ++denseTagIndex; break; } const int keyValue = dense.keys_vals(denseTagIndex + 1); const std::string &key = thread_data->PBFprimitiveBlock.stringtable().s(tagValue); const std::string &value = thread_data->PBFprimitiveBlock.stringtable().s(keyValue); extracted_nodes_vector[i].keyVals.Add(std::move(key), std::move(value)); denseTagIndex += 2; } } tbb::parallel_for(tbb::blocked_range<size_t>(0, extracted_nodes_vector.size()), [this, &extracted_nodes_vector](const tbb::blocked_range<size_t> &range) { lua_State *lua_state = this->scripting_environment.getLuaState(); for (size_t i = range.begin(); i != range.end(); ++i) { ImportNode &import_node = extracted_nodes_vector[i]; ParseNodeInLua(import_node, lua_state); } }); for (const ImportNode &import_node : extracted_nodes_vector) { extractor_callbacks->ProcessNode(import_node, use_elevation); } }
bool XMLParser::Parse() { while (xmlTextReaderRead(inputReader) == 1) { const int type = xmlTextReaderNodeType(inputReader); // 1 is Element if (type != 1) { continue; } xmlChar *currentName = xmlTextReaderName(inputReader); if (currentName == nullptr) { continue; } if (xmlStrEqual(currentName, (const xmlChar *)"node") == 1) { ImportNode current_node = ReadXMLNode(); ParseNodeInLua(current_node, lua_state); extractor_callbacks->ProcessNode(current_node); } if (xmlStrEqual(currentName, (const xmlChar *)"way") == 1) { ExtractionWay way = ReadXMLWay(); ParseWayInLua(way, lua_state); extractor_callbacks->ProcessWay(way); } if (use_turn_restrictions && xmlStrEqual(currentName, (const xmlChar *)"relation") == 1) { InputRestrictionContainer current_restriction = ReadXMLRestriction(); if ((UINT_MAX != current_restriction.fromWay) && !extractor_callbacks->ProcessRestriction(current_restriction)) { std::cerr << "[XMLParser] restriction not parsed" << std::endl; } } xmlFree(currentName); } return true; }
bool XMLParser::Parse() { while ( xmlTextReaderRead( inputReader ) == 1 ) { const int type = xmlTextReaderNodeType( inputReader ); //1 is Element if ( type != 1 ) { continue; } xmlChar* currentName = xmlTextReaderName( inputReader ); if ( currentName == NULL ) { continue; } if ( xmlStrEqual( currentName, ( const xmlChar* ) "node" ) == 1 ) { ImportNode n = _ReadXMLNode(); ParseNodeInLua( n, luaState ); extractor_callbacks->nodeFunction(n); // if(!extractor_callbacks->nodeFunction(n)) // std::cerr << "[XMLParser] dense node not parsed" << std::endl; } if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) { ExtractionWay way = _ReadXMLWay( ); ParseWayInLua( way, luaState ); extractor_callbacks->wayFunction(way); // if(!extractor_callbacks->wayFunction(way)) // std::cerr << "[PBFParser] way not parsed" << std::endl; } if( use_turn_restrictions ) { if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) { InputRestrictionContainer r = _ReadXMLRestriction(); if(r.fromWay != UINT_MAX) { if(!extractor_callbacks->restrictionFunction(r)) { std::cerr << "[XMLParser] restriction not parsed" << std::endl; } } } } xmlFree( currentName ); } return true; }
inline void PBFParser::parseDenseNode(_ThreadData * threadData) { const OSMPBF::DenseNodes& dense = threadData->PBFprimitiveBlock.primitivegroup( threadData->currentGroupID ).dense(); int denseTagIndex = 0; int64_t m_lastDenseID = 0; int64_t m_lastDenseLatitude = 0; int64_t m_lastDenseLongitude = 0; ImportNode n; std::vector<ImportNode> extracted_nodes_vector; const int number_of_nodes = dense.id_size(); extracted_nodes_vector.reserve(number_of_nodes); for(int i = 0; i < number_of_nodes; ++i) { n.Clear(); m_lastDenseID += dense.id( i ); m_lastDenseLatitude += dense.lat( i ); m_lastDenseLongitude += dense.lon( i ); n.id = m_lastDenseID; n.lat = 100000*( ( double ) m_lastDenseLatitude * threadData->PBFprimitiveBlock.granularity() + threadData->PBFprimitiveBlock.lat_offset() ) / NANO; n.lon = 100000*( ( double ) m_lastDenseLongitude * threadData->PBFprimitiveBlock.granularity() + threadData->PBFprimitiveBlock.lon_offset() ) / NANO; while (denseTagIndex < dense.keys_vals_size()) { const int tagValue = dense.keys_vals( denseTagIndex ); if( 0==tagValue ) { ++denseTagIndex; break; } const int keyValue = dense.keys_vals ( denseTagIndex+1 ); const std::string & key = threadData->PBFprimitiveBlock.stringtable().s(tagValue).data(); const std::string & value = threadData->PBFprimitiveBlock.stringtable().s(keyValue).data(); n.keyVals.Add(key, value); denseTagIndex += 2; } extracted_nodes_vector.push_back(n); } #pragma omp parallel for schedule ( guided ) for(int i = 0; i < number_of_nodes; ++i) { ImportNode &n = extracted_nodes_vector[i]; ParseNodeInLua( n, scriptingEnvironment.getLuaStateForThreadID(omp_get_thread_num()) ); } BOOST_FOREACH(ImportNode &n, extracted_nodes_vector) { extractor_callbacks->nodeFunction(n); }