Overpass API regression suite coverage (Saxony) / overpass_api/statements/item_geometry.h

overpass_api/statements/item_geometry.h

83 of 122 instrumented lines run by the suite (68.0%) 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#ifndef DE__OSM3S___OVERPASS_API__STATEMENTS__ITEM_GEOMETRY_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__ITEM_GEOMETRY_H
23#include "../../expat/escape_json.h"
24#include "../../expat/escape_xml.h"
25#include "../data/tag_store.h"
26#include "../data/utils.h"
27#include "evaluator.h"
28#include "statement.h"
30#include <map>
31#include <string>
32#include <vector>
35/* === Geometry Related Operators ===
38==== Closedness ====
40The operator <em>is_closed</em> returns whether the element is a closed way.
41The operator is undefined for any other type of element.
42For ways, it returns "1" if the first member of the way is equal to the last member of the way
43and "0" otherwise.
44The operators takes no parameters.
46The syntax is
48 is_closed()
49*/
51struct Is_Closed_Eval_Task : public Eval_Task
530 virtual std::string eval(const std::string* key) const { return ""; }
55 virtual std::string eval(const Element_With_Context< Node_Skeleton >& data, const std::string* key) const
56585188 q { return "NaW"; }
57 virtual std::string eval(const Element_With_Context< Attic< Node_Skeleton > >& data, const std::string* key) const
58373953 q { return "NaW"; }
59 virtual std::string eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const
601063169 q { return !data.object->nds.empty() && data.object->nds.front() == data.object->nds.back() ? "1" : "0"; }
61 virtual std::string eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const
62125132 q { return !data.object->nds.empty() && data.object->nds.front() == data.object->nds.back() ? "1" : "0"; }
63 virtual std::string eval(const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const
644275 q { return "NaW"; }
65 virtual std::string eval(const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const
663472 q { return "NaW"; }
67 virtual std::string eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const
680 { return "NaW"; }
69 virtual std::string eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const
7011 q { return "NaW"; }
71};
74class Evaluator_Is_Closed : public Evaluator
76public:
77 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Is_Closed >
78 {
792768692 q Statement_Maker() : Generic_Statement_Maker< Evaluator_Is_Closed >("eval-is-closed") {}
80 };
81 static Statement_Maker statement_maker;
82 static Element_Function_Maker< Evaluator_Is_Closed > evaluator_maker;
842768692 q static std::string stmt_func_name() { return "is_closed"; }
852222 q virtual std::string dump_xml(const std::string& indent) const { return indent + "<eval-is-closed/>\n"; }
864422 q virtual std::string dump_compact_ql(const std::string&) const { return "is_closed()"; }
88 Evaluator_Is_Closed(int line_number_, const std::map< std::string, std::string >& input_attributes,
89 Parsed_Query& global_settings);
908822 q virtual std::string get_name() const { return "eval-is-closed"; }
910 virtual std::string get_result_name() const { return ""; }
920 virtual void execute(Resource_Manager& rman) {}
930 virtual ~Evaluator_Is_Closed() {}
952121 q virtual Requested_Context request_context() const { return Requested_Context().add_usage(Set_Usage::SKELETON); }
978822 q virtual Statement::Eval_Return_Type return_type() const { return Statement::string; };
98 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key)
992121 q { return new Is_Closed_Eval_Task(); }
100};
103/* ==== Geometry ====
105The <em>geometry</em> operator returns the geometry of a single object
106as a geometry that can be put into the other geometry converting operators.
108Its syntax is:
110 geom()
111*/
113struct Geometry_Geometry_Task : Eval_Geometry_Task
1154238 q Geometry_Geometry_Task() {}
1170 virtual Opaque_Geometry* eval() const { return 0; }
119 virtual Opaque_Geometry* eval(const Element_With_Context< Node_Skeleton >& data) const
1207821311 q { return data.geometry ? data.geometry->clone() : new Null_Geometry(); }
121 virtual Opaque_Geometry* eval(const Element_With_Context< Attic< Node_Skeleton > >& data) const
1220 { return data.geometry ? data.geometry->clone() : new Null_Geometry(); }
123 virtual Opaque_Geometry* eval(const Element_With_Context< Way_Skeleton >& data) const
1241610611 q { return data.geometry ? data.geometry->clone() : new Null_Geometry(); }
125 virtual Opaque_Geometry* eval(const Element_With_Context< Attic< Way_Skeleton > >& data) const
1260 { return data.geometry ? data.geometry->clone() : new Null_Geometry(); }
127 virtual Opaque_Geometry* eval(const Element_With_Context< Relation_Skeleton >& data) const
1285487 q { return data.geometry ? data.geometry->clone() : new Null_Geometry(); }
129 virtual Opaque_Geometry* eval(const Element_With_Context< Attic< Relation_Skeleton > >& data) const
1300 { return data.geometry ? data.geometry->clone() : new Null_Geometry(); }
131 virtual Opaque_Geometry* eval(const Element_With_Context< Area_Skeleton >& data) const
1320 { return data.geometry ? data.geometry->clone() : new Null_Geometry(); }
133 virtual Opaque_Geometry* eval(const Element_With_Context< Derived_Skeleton >& data) const
1343711748 q { return data.geometry ? data.geometry->clone() : new Null_Geometry(); }
135};
138class Evaluator_Geometry : public Evaluator
140public:
141 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Geometry >
142 {
1432768692 q Statement_Maker() : Generic_Statement_Maker< Evaluator_Geometry >("eval-geometry") {}
144 };
145 static Statement_Maker statement_maker;
146 static Element_Function_Maker< Evaluator_Geometry > evaluator_maker;
1482768692 q static std::string stmt_func_name() { return "geom"; }
149 virtual std::string dump_xml(const std::string& indent) const
1504542 q { return indent + "<eval-geometry/>\n"; }
151 virtual std::string dump_compact_ql(const std::string&) const
1529042 q { return "geom(\"\")"; }
154 Evaluator_Geometry(int line_number_, const std::map< std::string, std::string >& input_attributes,
155 Parsed_Query& global_settings);
15618042 q virtual std::string get_name() const { return "eval-geometry"; }
1570 virtual std::string get_result_name() const { return ""; }
1580 virtual void execute(Resource_Manager& rman) {}
1590 virtual ~Evaluator_Geometry() {}
1614238 q virtual Requested_Context request_context() const { return Requested_Context().add_usage(Set_Usage::GEOMETRY); }
16318042 q virtual Statement::Eval_Return_Type return_type() const { return Statement::geometry; };
164 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key)
1650 { return new Const_Eval_Task("<Opaque_Geometry>"); }
166 virtual Eval_Geometry_Task* get_geometry_task(Prepare_Task_Context& context)
1674238 q { return new Geometry_Geometry_Task(); }
1680 virtual bool returns_geometry() const { return true; }
169};
172/* ==== Length ====
174The length operator returns the length of the element.
175For ways this is the length of the way.
176For relations this is the sum of the lengthes of the members of type way.
177For nodes it is always zero.
179Its syntax is:
181 length()
182*/
184struct Length_Eval_Task : public Eval_Task
1862521 q Length_Eval_Task() {}
1880 virtual std::string eval(const std::string* key) const { return ""; }
190 virtual std::string eval(const Element_With_Context< Node_Skeleton >& data, const std::string* key) const
1913965215 q { return "0"; }
192 virtual std::string eval(const Element_With_Context< Attic< Node_Skeleton > >& data, const std::string* key) const
19367362 q { return "0"; }
194 virtual std::string eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const
19522546 q { return data.geometry ? fixed_to_string(length(*data.geometry), 3) : "0"; }
196 virtual std::string eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const
197231 q { return data.geometry ? fixed_to_string(length(*data.geometry), 3) : "0"; }
198 virtual std::string eval(const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const
1991706 q { return data.geometry ? fixed_to_string(length(*data.geometry), 3) : "0"; }
200 virtual std::string eval(const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const
2010 { return data.geometry ? fixed_to_string(length(*data.geometry), 3) : "0"; }
202 virtual std::string eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const
2030 { return "0"; }
204 virtual std::string eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const
20552 q { return "0"; }
206};
209class Evaluator_Length : public Evaluator
211public:
212 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Length >
213 {
2142768692 q Statement_Maker() : Generic_Statement_Maker< Evaluator_Length >("eval-length") {}
215 };
216 static Statement_Maker statement_maker;
217 static Element_Function_Maker< Evaluator_Length > evaluator_maker;
2192768692 q static std::string stmt_func_name() { return "length"; }
220 virtual std::string dump_xml(const std::string& indent) const
2212321 q { return indent + "<eval-length/>\n"; }
222 virtual std::string dump_compact_ql(const std::string&) const
2234621 q { return "length()"; }
225 Evaluator_Length(int line_number_, const std::map< std::string, std::string >& input_attributes,
226 Parsed_Query& global_settings);
2279221 q virtual std::string get_name() const { return "eval-length"; }
2280 virtual std::string get_result_name() const { return ""; }
2290 virtual void execute(Resource_Manager& rman) {}
2300 virtual ~Evaluator_Length() {}
2322521 q virtual Requested_Context request_context() const { return Requested_Context().add_usage(Set_Usage::GEOMETRY); }
23410021 q virtual Statement::Eval_Return_Type return_type() const { return Statement::string; };
235 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key)
2362521 q { return new Length_Eval_Task(); }
237};
240/* ==== Latitude and Longitude ====
242The latitude and longitude operators return the respective coordinate of the element or the element's center.
243For nodes it is the latitude resp. longitude of the node's coordinate.
244For ways and relations it refers to the coordinate derived from the center of the bounding box.
246Their syntaxes are:
248 lat()
250resp.
252 lon()
253*/
255struct Latitude_Eval_Task : public Eval_Task
2571813 q Latitude_Eval_Task() {}
2590 virtual std::string eval(const std::string* key) const { return ""; }
261 virtual std::string eval(const Element_With_Context< Node_Skeleton >& data, const std::string* key) const
262197224 q { return data.geometry &&
263197224 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lat(), 7) : "NaN"; }
264 virtual std::string eval(const Element_With_Context< Attic< Node_Skeleton > >& data, const std::string* key) const
26538071 q { return data.geometry &&
26638071 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lat(), 7) : "NaN"; }
267 virtual std::string eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const
268733264 q { return data.geometry &&
269733264 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lat(), 7) : "NaN"; }
270 virtual std::string eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const
27119861 q { return data.geometry &&
27219861 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lat(), 7) : "NaN"; }
273 virtual std::string eval(const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const
27411071 q { return data.geometry &&
27511071 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lat(), 7) : "NaN"; }
276 virtual std::string eval(const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const
2770 { return data.geometry &&
2780 data.geometry->has_center() ? fixed_to_string(data.geometry->center_lat(), 7) : "NaN"; }
279 virtual std::string eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const
2800 { return data.geometry &&
2810 data.geometry->has_center() ? fixed_to_string(data.geometry->center_lat(), 7) : "NaN"; }
282 virtual std::string eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const
2833711452 q { return data.geometry &&
2843711452 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lat(), 7) : "NaN"; }
285};
288class Evaluator_Latitude : public Evaluator
290public:
291 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Latitude >
292 {
2932768692 q Statement_Maker() : Generic_Statement_Maker< Evaluator_Latitude >("eval-lat") {}
294 };
295 static Statement_Maker statement_maker;
296 static Element_Function_Maker< Evaluator_Latitude > evaluator_maker;
2982768692 q static std::string stmt_func_name() { return "lat"; }
299 virtual std::string dump_xml(const std::string& indent) const
3001613 q { return indent + "<eval-lat/>\n"; }
301 virtual std::string dump_compact_ql(const std::string&) const
3023213 q { return "lat()"; }
304 Evaluator_Latitude(int line_number_, const std::map< std::string, std::string >& input_attributes,
305 Parsed_Query& global_settings);
3066413 q virtual std::string get_name() const { return "eval-lat"; }
3070 virtual std::string get_result_name() const { return ""; }
3080 virtual void execute(Resource_Manager& rman) {}
3090 virtual ~Evaluator_Latitude() {}
3111813 q virtual Requested_Context request_context() const { return Requested_Context().add_usage(Set_Usage::GEOMETRY); }
3137213 q virtual Statement::Eval_Return_Type return_type() const { return Statement::string; };
314 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key)
3151813 q { return new Latitude_Eval_Task(); }
316};
319struct Longitude_Eval_Task : public Eval_Task
3211211 q Longitude_Eval_Task() {}
3230 virtual std::string eval(const std::string* key) const { return ""; }
325 virtual std::string eval(const Element_With_Context< Node_Skeleton >& data, const std::string* key) const
32676593 q { return data.geometry &&
32776593 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lon(), 7) : "NaN"; }
328 virtual std::string eval(const Element_With_Context< Attic< Node_Skeleton > >& data, const std::string* key) const
3290 { return data.geometry &&
3300 data.geometry->has_center() ? fixed_to_string(data.geometry->center_lon(), 7) : "NaN"; }
331 virtual std::string eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const
332776535 q { return data.geometry &&
333776535 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lon(), 7) : "NaN"; }
334 virtual std::string eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const
335141 q { return data.geometry &&
336141 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lon(), 7) : "NaN"; }
337 virtual std::string eval(const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const
33815274 q { return data.geometry &&
33915274 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lon(), 7) : "NaN"; }
340 virtual std::string eval(const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const
3410 { return data.geometry &&
3420 data.geometry->has_center() ? fixed_to_string(data.geometry->center_lon(), 7) : "NaN"; }
343 virtual std::string eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const
3440 { return data.geometry &&
3450 data.geometry->has_center() ? fixed_to_string(data.geometry->center_lon(), 7) : "NaN"; }
346 virtual std::string eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const
34711 q { return data.geometry &&
34811 q data.geometry->has_center() ? fixed_to_string(data.geometry->center_lon(), 7) : "NaN"; }
349};
352class Evaluator_Longitude : public Evaluator
354public:
355 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Longitude >
356 {
3572768692 q Statement_Maker() : Generic_Statement_Maker< Evaluator_Longitude >("eval-lon") {}
358 };
359 static Statement_Maker statement_maker;
360 static Element_Function_Maker< Evaluator_Longitude > evaluator_maker;
3622768692 q static std::string stmt_func_name() { return "lon"; }
363 virtual std::string dump_xml(const std::string& indent) const
3641211 q { return indent + "<eval-lon/>\n"; }
365 virtual std::string dump_compact_ql(const std::string&) const
3662411 q { return "lon()"; }
368 Evaluator_Longitude(int line_number_, const std::map< std::string, std::string >& input_attributes,
369 Parsed_Query& global_settings);
3704811 q virtual std::string get_name() const { return "eval-lon"; }
3710 virtual std::string get_result_name() const { return ""; }
3720 virtual void execute(Resource_Manager& rman) {}
3730 virtual ~Evaluator_Longitude() {}
3751211 q virtual Requested_Context request_context() const { return Requested_Context().add_usage(Set_Usage::GEOMETRY); }
3775711 q virtual Statement::Eval_Return_Type return_type() const { return Statement::string; };
378 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key)
3791211 q { return new Longitude_Eval_Task(); }
380};
383#endif