Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/bbox_query.cc

overpass_api/statements/bbox_query.cc

80 of 136 instrumented lines run by the suite (58.8%) 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 <algorithm>
20#include <sstream>
22#include "../../template_db/block_backend.h"
23#include "../../template_db/random_file.h"
24#include "../core/settings.h"
25#include "../data/collect_members.h"
26#include "../data/bbox_filter.h"
27#include "../data/way_geometry_store.h"
28#include "bbox_query.h"
29#include "recurse.h"
32//-----------------------------------------------------------------------------
35class Bbox_Constraint : public Query_Constraint
37 public:
38 Query_Filter_Strategy delivers_data(Resource_Manager& rman);
40530189 q Bbox_Constraint(Bbox_Query_Statement& bbox_) : bbox(&bbox_),
41530189 q filter_(Bbox_Double(bbox->get_south(), bbox->get_west(), bbox->get_north(), bbox->get_east())) {}
42 bool get_ranges(Resource_Manager& rman, Ranges< Uint32_Index >& ranges);
43 bool get_ranges(Resource_Manager& rman, Ranges< Uint31_Index >& ranges);
45 void filter(Resource_Manager& rman, Set& into);
46 void filter(const Statement& query, Resource_Manager& rman, Set& into);
47530189 q virtual ~Bbox_Constraint() {}
49 private:
50 Bbox_Query_Statement* bbox;
51 Bbox_Filter filter_;
52};
55Query_Filter_Strategy Bbox_Constraint::delivers_data(Resource_Manager& rman)
57262169 q const Bbox_Double& bbox_ = filter_.get_bbox();
59262169 q if (!bbox_.valid())
600 return ids_required;
62262169 q return ((bbox_.north - bbox_.south) * std::abs(bbox_.east - bbox_.west) < 1.0) ? prefer_ranges : ids_useful;
66bool Bbox_Constraint::get_ranges(Resource_Manager& rman, Ranges< Uint32_Index >& ranges)
68140115 q ranges = filter_.get_ranges_32();
69140115 q return true;
73bool Bbox_Constraint::get_ranges
74 (Resource_Manager& rman, Ranges< Uint31_Index >& ranges)
76253157 q ranges = filter_.get_ranges_31();
77253157 q return true;
81void Bbox_Constraint::filter(Resource_Manager& rman, Set& into)
83285188 q filter_.filter(into);
87void Bbox_Constraint::filter(const Statement& query, Resource_Manager& rman, Set& into)
89262169 q filter_.filter(query, rman, into);
92//-----------------------------------------------------------------------------
95Bbox_Query_Statement::Statement_Maker Bbox_Query_Statement::statement_maker;
96Bbox_Query_Statement::Criterion_Maker Bbox_Query_Statement::criterion_maker;
99Statement* Bbox_Query_Statement::Criterion_Maker::create_criterion(const Token_Node_Ptr& input_tree,
100 const std::string& result_type, const std::string& into,
101 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
103696170 q Token_Node_Ptr tree_it = input_tree;
104696170 q uint line_nr = tree_it->line_col.first;
105696170 q std::map< std::string, std::string > attributes;
107696170 q if (tree_it->token != "," || !tree_it->rhs || !tree_it->lhs)
1080 {
1090 if (error_output)
1100 error_output->add_parse_error("bbox requires four arguments", line_nr);
1110 return 0;
1120 }
114696170 q attributes["e"] = tree_it.rhs()->token;
115696170 q tree_it = tree_it.lhs();
117696170 q if (tree_it->token != "," || !tree_it->rhs || !tree_it->lhs)
1180 {
1190 if (error_output)
1200 error_output->add_parse_error("bbox requires four arguments", line_nr);
1210 return 0;
1220 }
124696170 q attributes["n"] = tree_it.rhs()->token;
125696170 q tree_it = tree_it.lhs();
127696170 q if (tree_it->token != "," || !tree_it->rhs || !tree_it->lhs)
1280 {
1290 if (error_output)
1300 error_output->add_parse_error("bbox requires four arguments", line_nr);
1310 return 0;
1320 }
134696170 q attributes["w"] = tree_it.rhs()->token;
135696170 q attributes["s"] = tree_it.lhs()->token;
137696170 q attributes["into"] = into;
138696170 q return new Bbox_Query_Statement(line_nr, attributes, global_settings);
142Bbox_Query_Statement::Bbox_Query_Statement
143 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
144708173 q : Output_Statement(line_number_)
146708173 q std::map< std::string, std::string > attributes;
148708173 q attributes["into"] = "_";
149708173 q attributes["s"] = "";
150708173 q attributes["n"] = "";
151708173 q attributes["w"] = "";
152708173 q attributes["e"] = "";
154708173 q eval_attributes_array(get_name(), attributes, input_attributes);
156708173 q set_output(attributes["into"]);
157708173 q south = atof(attributes["s"].c_str());
158708173 q if ((south < -90.0) || (south > 90.0) || (attributes["s"] == ""))
1590 {
1600 std::ostringstream temp;
1610 temp<<"For the attribute \"s\" of the element \"bbox-query\""
1620 <<" the only allowed values are floats between -90.0 and 90.0.";
1630 add_static_error(temp.str());
1640 }
165708173 q north = atof(attributes["n"].c_str());
166708173 q if ((north < -90.0) || (north > 90.0) || (attributes["n"] == ""))
1670 {
1680 std::ostringstream temp;
1690 temp<<"For the attribute \"n\" of the element \"bbox-query\""
1700 <<" the only allowed values are floats between -90.0 and 90.0.";
1710 add_static_error(temp.str());
1720 }
173708173 q if (north < south)
1740 {
1750 std::ostringstream temp;
1760 temp<<"The value of attribute \"n\" of the element \"bbox-query\""
1770 <<" must always be greater or equal than the value of attribute \"s\".";
1780 add_static_error(temp.str());
1790 }
180708173 q west = atof(attributes["w"].c_str());
181708173 q if ((west < -180.0) || (west > 180.0) || (attributes["w"] == ""))
1820 {
1830 std::ostringstream temp;
1840 temp<<"For the attribute \"w\" of the element \"bbox-query\""
1850 <<" the only allowed values are floats between -180.0 and 180.0.";
1860 add_static_error(temp.str());
1870 }
188708173 q east = atof(attributes["e"].c_str());
189708173 q if ((east < -180.0) || (east > 180.0) || (attributes["e"] == ""))
1900 {
1910 std::ostringstream temp;
1920 temp<<"For the attribute \"e\" of the element \"bbox-query\""
1930 <<" the only allowed values are floats between -180.0 and 180.0.";
1940 add_static_error(temp.str());
1950 }
199Bbox_Query_Statement::Bbox_Query_Statement(const Bbox_Double& bbox)
2003318 q : Output_Statement(0), south(bbox.south), north(bbox.north), west(bbox.west), east(bbox.east) {}
203Bbox_Query_Statement::~Bbox_Query_Statement()
205741189 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin();
2061248189 q it != constraints.end(); ++it)
207507170 q delete *it;
211const Ranges< Uint32_Index >& Bbox_Query_Statement::get_ranges_32()
2120{
2130 if (ranges_32.empty())
2140 ranges_32 = ::get_ranges_32(south, north, west, east);
2150 return ranges_32;
2160}
219const Ranges< Uint31_Index >& Bbox_Query_Statement::get_ranges_31()
2200{
2210 if (ranges_31.empty())
2220 ranges_31 = calc_parents(get_ranges_32());
2230 return ranges_31;
2240}
227void Bbox_Query_Statement::execute(Resource_Manager& rman)
2292320 q Set into;
2312320 q Bbox_Constraint constraint(*this);
2322320 q Ranges< Uint32_Index > ranges;
2332320 q constraint.get_ranges(rman, ranges);
2342320 q get_elements_from_db< Uint32_Index, Node_Skeleton >(ranges, *this, rman)
2352320 q .swap(into.nodes, into.attic_nodes);
2362320 q constraint.filter(rman, into);
2372320 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.nodes, into.attic_nodes);
2392320 q transfer_output(rman, into);
2402320 q rman.health_check(*this);
244Query_Constraint* Bbox_Query_Statement::get_query_constraint()
246507170 q constraints.push_back(new Bbox_Constraint(*this));
247507170 q return constraints.back();