Overpass API regression suite coverage (Saxony) / 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);
40598216 q Bbox_Constraint(Bbox_Query_Statement& bbox_) : bbox(&bbox_),
41598216 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);
47598216 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)
57301196 q const Bbox_Double& bbox_ = filter_.get_bbox();
59301196 q if (!bbox_.valid())
600 return ids_required;
62301196 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)
68140117 q ranges = filter_.get_ranges_32();
69140117 q return true;
73bool Bbox_Constraint::get_ranges
74 (Resource_Manager& rman, Ranges< Uint31_Index >& ranges)
76256166 q ranges = filter_.get_ranges_31();
77256166 q return true;
81void Bbox_Constraint::filter(Resource_Manager& rman, Set& into)
83326216 q filter_.filter(into);
87void Bbox_Constraint::filter(const Statement& query, Resource_Manager& rman, Set& into)
89301196 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)
103780192 q Token_Node_Ptr tree_it = input_tree;
104780192 q uint line_nr = tree_it->line_col.first;
105780192 q std::map< std::string, std::string > attributes;
107780192 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 }
114780192 q attributes["e"] = tree_it.rhs()->token;
115780192 q tree_it = tree_it.lhs();
117780192 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 }
124780192 q attributes["n"] = tree_it.rhs()->token;
125780192 q tree_it = tree_it.lhs();
127780192 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 }
134780192 q attributes["w"] = tree_it.rhs()->token;
135780192 q attributes["s"] = tree_it.lhs()->token;
137780192 q attributes["into"] = into;
138780192 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)
144792195 q : Output_Statement(line_number_)
146792195 q std::map< std::string, std::string > attributes;
148792195 q attributes["into"] = "_";
149792195 q attributes["s"] = "";
150792195 q attributes["n"] = "";
151792195 q attributes["w"] = "";
152792195 q attributes["e"] = "";
154792195 q eval_attributes_array(get_name(), attributes, input_attributes);
156792195 q set_output(attributes["into"]);
157792195 q south = atof(attributes["s"].c_str());
158792195 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 }
165792195 q north = atof(attributes["n"].c_str());
166792195 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 }
173792195 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 }
180792195 q west = atof(attributes["w"].c_str());
181792195 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 }
188792195 q east = atof(attributes["e"].c_str());
189792195 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)
2004222 q : Output_Statement(0), south(bbox.south), north(bbox.north), west(bbox.west), east(bbox.east) {}
203Bbox_Query_Statement::~Bbox_Query_Statement()
205834216 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin();
2061407216 q it != constraints.end(); ++it)
207573196 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)
2292521 q Set into;
2312521 q Bbox_Constraint constraint(*this);
2322521 q Ranges< Uint32_Index > ranges;
2332521 q constraint.get_ranges(rman, ranges);
2342521 q get_elements_from_db< Uint32_Index, Node_Skeleton >(ranges, *this, rman)
2352521 q .swap(into.nodes, into.attic_nodes);
2362521 q constraint.filter(rman, into);
2372521 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.nodes, into.attic_nodes);
2392521 q transfer_output(rman, into);
2402521 q rman.health_check(*this);
244Query_Constraint* Bbox_Query_Statement::get_query_constraint()
246573196 q constraints.push_back(new Bbox_Constraint(*this));
247573196 q return constraints.back();