Overpass API regression suite coverage (Nova Scotia) / overpass_api/data/relation_geometry_store.cc

overpass_api/data/relation_geometry_store.cc

139 of 143 instrumented lines run by the suite (97.2%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#include "collect_members.h"
20#include "relation_geometry_store.h"
23Relation_Geometry_Store::~Relation_Geometry_Store()
241619172 q{
251619172 q delete way_geometry_store;
261619172 q}
29Relation_Geometry_Store::Relation_Geometry_Store
30 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations,
31 const Statement& query, Resource_Manager& rman,
32 double south_, double north_, double west_, double east_)
331054172 q : way_geometry_store(0), south(ilat_(south_)), north(ilat_(north_)), west(ilon_(west_)), east(ilon_(east_))
341054172 q{
351054172 q if (relations.empty())
36866137 q {
37 // Turn off bounding box, because it isn't needed anyway
38866137 q north = 0;
39866137 q south = 1;
40866137 q }
411054172 q Request_Context context(&query, rman);
431054172 q Ranges< Uint32_Index > node_ranges(south <= north
441054172 q ? get_ranges_32(south_, north_, west_, east_) : Ranges< Uint32_Index >::global());
46 // Retrieve all nodes referred by the relations.
471054172 q Timeless< Uint32_Index, Node_Skeleton > node_members
481054172 q = relation_node_members(context, relations, {}, node_ranges, {}, true);
50 // Order node ids by id.
511054172 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::iterator it = node_members.current.begin();
5211593172 q it != node_members.current.end(); ++it)
531053945 q {
541053945 q for (std::vector< Node_Skeleton >::const_iterator iit = it->second.begin();
552233945 q iit != it->second.end(); ++iit)
561180045 q nodes.push_back(Node(iit->id, it->first.val(), iit->ll_lower));
571053945 q }
581054172 q sort(nodes.begin(), nodes.end(), Node_Comparator_By_Id());
601054172 q Ranges< Uint31_Index > way_ranges(south <= north
611054172 q ? calc_parents(node_ranges) : Ranges< Uint31_Index >::global());
63 // Retrieve all ways referred by the relations.
641054172 q Timeless< Uint31_Index, Way_Skeleton > way_members
651054172 q = relation_way_members(context, relations, {}, way_ranges, {}, true);
671054172 q way_geometry_store = new Way_Geometry_Store(way_members.current, query, rman);
69 // Order way ids by id.
701054172 q for (std::map< Uint31_Index, std::vector< Way_Skeleton > >::iterator it = way_members.current.begin();
71113493172 q it != way_members.current.end(); ++it)
7211243952 q {
7311243952 q for (std::vector< Way_Skeleton >::const_iterator iit = it->second.begin();
7436426352 q iit != it->second.end(); ++iit)
7525182452 q ways.push_back(*iit);
7611243952 q }
771054172 q sort(ways.begin(), ways.end());
781054172 q}
81Relation_Geometry_Store::Relation_Geometry_Store
82 (const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& relations,
83 const Statement& query, Resource_Manager& rman,
84 double south_, double north_, double west_, double east_)
8556590 q : way_geometry_store(0), south(ilat_(south_)), north(ilat_(north_)), west(ilon_(west_)), east(ilon_(east_))
8656590 q{
8756590 q if (relations.empty())
8842070 q {
89 // Turn off bounding box, because it isn't needed anyway
9042070 q north = 0;
9142070 q south = 1;
9242070 q }
9356590 q Request_Context context(&query, rman);
9556590 q Ranges< Uint32_Index > node_ranges(south <= north
9656590 q ? get_ranges_32(south_, north_, west_, east_) : Ranges< Uint32_Index >::global());
98 // Retrieve all nodes referred by the relations.
9956590 q auto nodes_by_idx = relation_node_members(context, {}, relations, node_ranges, {}, true);
101 // Order node ids by id.
10256590 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::iterator it = nodes_by_idx.current.begin();
1031948890 q it != nodes_by_idx.current.end(); ++it)
104189239 q {
105189239 q for (std::vector< Node_Skeleton >::const_iterator iit = it->second.begin();
106194269 q iit != it->second.end(); ++iit)
1075037 q nodes.push_back(Node(iit->id, it->first.val(), iit->ll_lower));
108189239 q }
10956590 q for (std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >::iterator it = nodes_by_idx.attic.begin();
1101948890 q it != nodes_by_idx.attic.end(); ++it)
111189239 q {
112189239 q for (std::vector< Attic< Node_Skeleton > >::const_iterator iit = it->second.begin();
113191699 q iit != it->second.end(); ++iit)
1142466 q nodes.push_back(Node(iit->id, it->first.val(), iit->ll_lower));
115189239 q }
11656590 q sort(nodes.begin(), nodes.end(), Node_Comparator_By_Id());
11856590 q Ranges< Uint31_Index > way_ranges(south <= north
11956590 q ? calc_parents(node_ranges) : Ranges< Uint31_Index >::global());
121 // Retrieve all ways referred by the relations.
12256590 q Timeless< Uint31_Index, Way_Skeleton > ways_by_idx_pair
12356590 q = relation_way_members(context,
12456590 q std::map< Uint31_Index, std::vector< Relation_Skeleton > >(), relations,
12556590 q way_ranges, {}, true);
12656590 q std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > > ways_by_idx;
12756590 q keep_matching_skeletons(ways_by_idx, ways_by_idx_pair.current, ways_by_idx_pair.attic,
12856590 q rman.get_desired_timestamp());
13056590 q way_geometry_store = new Way_Geometry_Store(ways_by_idx, query, rman);
13256590 q for (std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >::iterator it = ways_by_idx.begin();
1331674090 q it != ways_by_idx.end(); ++it)
1341617522 q {
1351617522 q for (std::vector< Attic< Way_Skeleton > >::const_iterator iit = it->second.begin();
1364369722 q iit != it->second.end(); ++iit)
1372752222 q ways.push_back(*iit);
1381617522 q }
13956590 q sort(ways.begin(), ways.end());
143bool Relation_Geometry_Store::matches_bbox(uint32 ll_upper, uint32 ll_lower) const
1441260950857 q{
1451260950857 q if (north < south)
1461260568756 q return true;
14738211 q uint32 lat(::ilat(ll_upper, ll_lower));
14838211 q int32 lon(::ilon(ll_upper, ll_lower));
14938211 q return (lat >= south && lat <= north &&
15038211 q ((lon >= west && lon <= east)
151121 q || (east < west && (lon >= west || lon <= east))));
1521260950857 q}
155std::vector< std::vector< Quad_Coord > > Relation_Geometry_Store::get_geometry
156 (const Relation_Skeleton& relation) const
1573257661 q{
1583257661 q std::vector< std::vector< Quad_Coord > > result;
1593257661 q for (std::vector< Relation_Entry >::const_iterator it = relation.members.begin();
16077514261 q it != relation.members.end(); ++it)
16174256661 q {
16274256661 q if (it->type == Relation_Entry::NODE)
1632734048 q {
1642734048 q const Node* node = binary_search_for_id(nodes, it->ref);
1652734048 q if (node == 0 || !matches_bbox(node->index, node->ll_lower_))
1661181814 q result.push_back(std::vector< Quad_Coord >(1, Quad_Coord(0u, 0u)));
1671552246 q else
1681552246 q result.push_back(std::vector< Quad_Coord >(1, Quad_Coord(node->index, node->ll_lower_)));
1692734048 q }
17071522660 q else if (it->type == Relation_Entry::WAY)
17170395360 q {
17270395360 q const Way_Skeleton* way = binary_search_for_id(ways, Way_Skeleton::Id_Type(it->ref.val()));
17370395360 q if (way == 0)
17426414020 q result.push_back(std::vector< Quad_Coord >());
17543981356 q else
17643981356 q {
17743981356 q result.push_back(way_geometry_store->get_geometry(*way));
17843981356 q if (result.back().empty())
18043981256 q else if (result.back().size() == 1)
1810 {
1820 if (!matches_bbox(result.back().begin()->ll_upper, result.back().begin()->ll_lower))
1830 *result.back().begin() = Quad_Coord(0u, 0u);
1840 }
18543981256 q else
18643981256 q {
18743981256 q bool this_matches = matches_bbox(result.back()[0].ll_upper, result.back()[0].ll_lower);
18843981256 q bool next_matches = matches_bbox(result.back()[1].ll_upper, result.back()[1].ll_lower);
18943981256 q if (!this_matches && !next_matches)
190171 q result.back()[0] = Quad_Coord(0u, 0u);
1911215417456 q for (uint i = 1; i < result.back().size() - 1; ++i)
1921171436256 q {
1931171436256 q bool last_matches = this_matches;
1941171436256 q this_matches = next_matches;
1951171436256 q next_matches = matches_bbox(result.back()[i+1].ll_upper, result.back()[i+1].ll_lower);
1961171436256 q if (!last_matches && !this_matches && !next_matches)
19737871 q result.back()[i] = Quad_Coord(0u, 0u);
1981171436256 q }
19943981256 q if (!this_matches && !next_matches)
200171 q result.back()[result.back().size()-1] = Quad_Coord(0u, 0u);
20143981256 q }
20243981356 q }
20370395360 q }
2041127324 q else if (it->type == Relation_Entry::RELATION)
2051127324 q result.push_back(std::vector< Quad_Coord >());
20674256661 q }
2083257661 q return result;
2093257661 q}