diff --git a/src/raw/queryraw.cc b/src/raw/queryraw.cc index 115284d7..90961b40 100644 --- a/src/raw/queryraw.cc +++ b/src/raw/queryraw.cc @@ -863,7 +863,7 @@ QueryRaw::getNodeCacheFromWays(std::shared_ptr> ways, std::m } } -// Recive a string of comma separated values of Nodes ids +// Recieve a string of comma separated values of Nodes ids // and return a vector of Ways std::list> QueryRaw::getWaysByNodesRefs(std::string &nodeIds) const @@ -872,42 +872,49 @@ QueryRaw::getWaysByNodesRefs(std::string &nodeIds) const boost::timer::auto_cpu_timer timer("getWaysByNodesRefs(nodeIds): took %w seconds\n"); #endif std::list> ways; + std::vector queries; // Get all Ways that have references to Nodes from the DB, including Polygons and LineString geometries - std::string waysQuery = "SELECT distinct(osm_id), refs, version, tags, uid, changeset from way_refs join ways_poly wp on wp.osm_id = way_id where node_id = any(ARRAY[" + nodeIds + "])"; - waysQuery += " UNION SELECT distinct(osm_id), refs, version, tags, uid, changeset from way_refs join ways_line wl on wl.osm_id = way_id where node_id = any(ARRAY[" + nodeIds + "]);"; - auto ways_result = dbconn->query(waysQuery); - if (ways_result.size() == 0) { - log_error("No results returned!"); - return ways; - } + // std::string waysQuery = "SELECT distinct(osm_id), refs, version, tags, uid, changeset from way_refs join ways_poly wp on wp.osm_id = way_id where node_id = any(ARRAY[" + nodeIds + "])"; + queries.push_back("SELECT distinct(osm_id), refs, version, tags, uid, changeset from ways_poly where refs @> '{" + nodeIds + "}'"); - // Create Ways objects and fill the vector - for (auto way_it = ways_result.begin(); way_it != ways_result.end(); ++way_it) { - auto way = std::make_shared(); - way->id = (*way_it)[0].as(); - std::string refs_str = (*way_it)[1].as(); - if (refs_str.size() > 1) { - way->refs = arrayStrToVector(refs_str); + queries.push_back("SELECT distinct(osm_id), refs, version, tags, uid, changeset from ways_lines where refs @> '{" + nodeIds + "}'"); + // waysQuery += " UNION SELECT distinct(osm_id), refs, version, tags, uid, changeset from way_refs join ways_line wl on wl.osm_id = way_id where node_id = any(ARRAY[" + nodeIds + "]);"; + + for (auto it = queries.begin(); it != queries.end(); ++it) { + + auto ways_result = dbconn->query(*it); + if (ways_result.size() == 0) { + log_error("No results returned!"); + return ways; } - way->version = (*way_it)[2].as(); - auto tags = (*way_it)[3]; - if (!tags.is_null()) { - auto tags = parseJSONObjectStr((*way_it)[3].as()); - for (auto const& [key, val] : tags) - { - way->addTag(key, val); + + // Create Ways objects and fill the vector + for (auto way_it = ways_result.begin(); way_it != ways_result.end(); ++way_it) { + auto way = std::make_shared(); + way->id = (*way_it)[0].as(); + std::string refs_str = (*way_it)[1].as(); + if (refs_str.size() > 1) { + way->refs = arrayStrToVector(refs_str); } + way->version = (*way_it)[2].as(); + auto tags = (*way_it)[3]; + if (!tags.is_null()) { + auto tags = parseJSONObjectStr((*way_it)[3].as()); + for (auto const& [key, val] : tags) { + way->addTag(key, val); + } + } + auto uid = (*way_it)[4]; + if (!uid.is_null()) { + way->uid = (*way_it)[4].as(); + } + auto changeset = (*way_it)[5]; + if (!changeset.is_null()) { + way->changeset = (*way_it)[5].as(); + } + ways.push_back(way); } - auto uid = (*way_it)[4]; - if (!uid.is_null()) { - way->uid = (*way_it)[4].as(); - } - auto changeset = (*way_it)[5]; - if (!changeset.is_null()) { - way->changeset = (*way_it)[5].as(); - } - ways.push_back(way); } return ways; }