1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al. 3 * This file is part of Overpass_API. 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. 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. 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/>. 19#include "../data/bbox_filter.h" 20#include "../data/tag_store.h" 21#include "../data/utils.h" 26Generic_Statement_Maker< Localize_Statement > Localize_Statement::statement_maker("localize"); 29Localize_Statement::Localize_Statement 30 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings) 316019 q : Output_Statement(line_number_), type(data) 336019 q std::map< std::string, std::string > attributes; 356019 q attributes["from"] = "_"; 366019 q attributes["into"] = "_"; 376019 q attributes["type"] = "l"; 386019 q attributes["s"] = ""; 396019 q attributes["n"] = ""; 406019 q attributes["w"] = ""; 416019 q attributes["e"] = ""; 436019 q eval_attributes_array(get_name(), attributes, input_attributes); 456019 q set_output(attributes["into"]); 466019 q input = attributes["from"]; 486019 q if (attributes["type"] == "ll") 50279 q else if (attributes["type"] == "llb") 52155 q else if (attributes["type"] != "l") 530 add_static_error("Localize must have one of the values \"l\", \"ll\", or \"llb\". \"l\" is the default value."); 566019 q if (!attributes["s"].empty() || !attributes["n"].empty() 576019 q || !attributes["w"].empty() || !attributes["e"].empty()) 590 south = atof(attributes["s"].c_str()); 600 if ((south < -90.0) || (south > 90.0) || (attributes["s"] == "")) 610 add_static_error("For the attribute \"s\" of the element \"bbox-query\"" 620 " the only allowed values are floats between -90.0 and 90.0."); 640 north = atof(attributes["n"].c_str()); 650 if ((north < -90.0) || (north > 90.0) || (attributes["n"] == "")) 660 add_static_error("For the attribute \"n\" of the element \"bbox-query\"" 670 " the only allowed values are floats between -90.0 and 90.0."); 690 add_static_error("The value of attribute \"n\" of the element \"bbox-query\"" 700 " must always be greater or equal than the value of attribute \"s\"."); 720 west = atof(attributes["w"].c_str()); 730 if ((west < -180.0) || (west > 180.0) || (attributes["w"] == "")) 740 add_static_error("For the attribute \"w\" of the element \"bbox-query\"" 750 " the only allowed values are floats between -180.0 and 180.0."); 770 east = atof(attributes["e"].c_str()); 780 if ((east < -180.0) || (east > 180.0) || (attributes["e"] == "")) 790 add_static_error("For the attribute \"e\" of the element \"bbox-query\"" 800 " the only allowed values are floats between -180.0 and 180.0."); 90104337616 q Node_Context() : local_id(0ull), count(0), lat(100.), lon(0.) {} 91 Derived_Skeleton::Id_Type local_id; 95 std::map< Node_Skeleton::Id_Type, std::vector< Way_Skeleton::Id_Type > > link_by_origin; 98 struct Way_Section_Context 10014176514 q Way_Section_Context(uint pos_) : pos(pos_), local_id(0ull), local_from(0ull), local_to(0ull) {} 102 Derived_Skeleton::Id_Type local_id; 103 Derived_Skeleton::Id_Type local_from; 104 Derived_Skeleton::Id_Type local_to; 105 std::vector< Point_Double > points; 108 NWR_Context(Resource_Manager& rman, const Statement& stmt, const Set& input_set, 109 const Owner< Bbox_Double >& bbox); 110 void prepare_links(Resource_Manager& rman, const Statement& stmt, const Set& input_set, 111 const Owner< Bbox_Double >& bbox); 112 Derived_Skeleton::Id_Type local_id_by_node_id(Node_Skeleton::Id_Type id) const; 1132435316 q Node_Context& context_by_node_id(Node_Skeleton::Id_Type id) { return context_by_node_id_[id]; } 11419474114 q std::vector< Way_Section_Context >& context_by_way_id(Way_Skeleton::Id_Type id) { return context_by_way_id_[id]; } 118 std::map< Node_Skeleton::Id_Type, Node_Context > context_by_node_id_; 119 std::map< Way_Skeleton::Id_Type, std::vector< Way_Section_Context > > context_by_way_id_; 123struct Node_Skeleton_By_Coord_Then_Id 125 bool operator()(const Node_Skeleton* lhs, const Node_Skeleton* rhs) 127335325816 q if (lhs->ll_lower != rhs->ll_lower) 128335316216 q return lhs->ll_lower < rhs->ll_lower; 129964 q return lhs->id < rhs->id; 134bool admissible_by_bbox(const Owner< Bbox_Double >& bbox, const NWR_Context::Node_Context& node_context) 1362435316 q return (!bbox || bbox->contains(Point_Double(node_context.lat, node_context.lon))); 140bool admissible_by_bbox(const Owner< Bbox_Double >& bbox, const std::vector< Point_Double >& points) 1450 for (std::vector< Point_Double >::const_iterator it = points.begin(); it != points.end(); ++it) 1470 if (bbox->contains(*it)) 1500 for (uint j = 1; j < points.size(); ++j) 1520 if (bbox->intersects(points[j-1], points[j])) 159template< typename Index, typename Object, typename Task > 160void for_each_elem(const std::map< Index, std::vector< Object > >& container, Task task) 16216819 q for (typename std::map< Index, std::vector< Object > >::const_iterator 1636916119 q it_idx = container.begin(); it_idx != container.end(); ++it_idx) 1656899316 q for (typename std::vector< Object >::const_iterator it_elem = it_idx->second.begin(); 16687990516 q it_elem != it_idx->second.end(); ++it_elem) 16781091216 q task(it_idx->first, *it_elem); 172struct Set_Coord_In_Context 174 void operator()(Uint32_Index idx, const Node_Skeleton& node) 17645199216 q NWR_Context::Node_Context& context = (*context_by_node_id)[node.id]; 17745199216 q context.lat = ::lat(idx.val(), node.ll_lower); 17845199216 q context.lon = ::lon(idx.val(), node.ll_lower); 181 Set_Coord_In_Context(std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >& context_by_node_id_) 1824219 q : context_by_node_id(&context_by_node_id_) {} 184 std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >* context_by_node_id; 190 void operator()(Uint31_Index idx, const Way_Skeleton& way) 19211964014 q if (!way.nds.empty()) 19411964014 q (*context_by_node_id)[way.nds.front()].count += 2; 195110223914 q for (uint i = 1; i < way.nds.size()-1; ++i) 19698259914 q ++(*context_by_node_id)[way.nds[i]].count; 19711964014 q (*context_by_node_id)[way.nds.back()].count += 2; 201 Count_Node_Use(std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >& context_by_node_id_) 2024219 q : context_by_node_id(&context_by_node_id_) {} 204 std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >* context_by_node_id; 208struct Partition_Into_Links 210 void operator()(Uint31_Index idx, const Way_Skeleton& way) 21211964014 q if (!way.nds.empty()) 21411964014 q std::vector< NWR_Context::Way_Section_Context >& way_context = (*context_by_way_id)[way.id]; 21611964014 q std::vector< NWR_Context::Node_Context* > nds_contexts; 21711964014 q nds_contexts.reserve(way.nds.size()); 21864827814 q for (std::vector< Node::Id_Type >::const_iterator it_nds = way.nds.begin(); it_nds != way.nds.end(); ++it_nds) 22058552714 q std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >::iterator it_ctx 22158552714 q = context_by_node_id->find(*it_nds); 22258552714 q if (it_ctx == context_by_node_id->end() || it_ctx->second.lat == 100.) 22452863814 q nds_contexts.push_back(&it_ctx->second); 2286275114 q const NWR_Context::Node_Context& start_context = *nds_contexts[start]; 2296275114 q way_context.push_back(NWR_Context::Way_Section_Context(start)); 2306275114 q way_context.back().local_from = start_context.local_id; 2316275114 q way_context.back().points.push_back(Point_Double(start_context.lat, start_context.lon)); 23343597914 q for (uint i = 1; i < way.nds.size()-1; ++i) 23537322814 q NWR_Context::Node_Context& context = *nds_contexts[i]; 23637322814 q way_context.back().points.push_back(Point_Double(context.lat, context.lon)); 23837322814 q if (context.local_id.val() || context.count > 1) 2407901414 q context.link_by_origin[way.nds[start]].push_back(way.id); 2427901414 q way_context.back().local_to = context.local_id; 2437901414 q if (!admissible_by_bbox(*bbox, way_context.back().points)) 2440 way_context.back().points.clear(); 2457901414 q way_context.push_back(NWR_Context::Way_Section_Context(start)); 2467901414 q way_context.back().local_from = context.local_id; 2477901414 q way_context.back().points.push_back(Point_Double(context.lat, context.lon)); 2516275114 q NWR_Context::Node_Context& context = *nds_contexts.back(); 2526275114 q way_context.back().points.push_back(Point_Double(context.lat, context.lon)); 2536275114 q way_context.back().local_to = context.local_id; 2546275114 q context.link_by_origin[way.nds[start]].push_back(way.id); 2556275114 q if (!admissible_by_bbox(*bbox, way_context.back().points)) 2560 way_context.back().points.clear(); 260 Partition_Into_Links( 261 std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >& context_by_node_id_, 262 std::map< Way_Skeleton::Id_Type, std::vector< NWR_Context::Way_Section_Context > >& context_by_way_id_, 263 const Owner< Bbox_Double >& bbox_) 2644219 q : context_by_node_id(&context_by_node_id_), context_by_way_id(&context_by_way_id_), bbox(&bbox_) {} 266 std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >* context_by_node_id; 267 std::map< Way_Skeleton::Id_Type, std::vector< NWR_Context::Way_Section_Context > >* context_by_way_id; 268 const Owner< Bbox_Double >* bbox; 272struct Figure_Out_Local_Ids_Of_Links 274 void operator()(Uint31_Index idx, const Way_Skeleton& way) 27611964014 q if (!way.nds.empty()) 27811964014 q std::vector< NWR_Context::Way_Section_Context >& way_context = (*context_by_way_id)[way.id]; 27911964014 q std::vector< std::pair< Node_Skeleton::Id_Type, Node_Skeleton::Id_Type > > segment_count; 28126140514 q for (uint i = 0; i < way_context.size(); ++i) 28314176514 q NWR_Context::Node_Context& context = (*context_by_node_id)[ 28414176514 q i+1 < way_context.size() ? way.nds[way_context[i+1].pos] : way.nds.back()]; 28514176514 q const std::vector< Way_Skeleton::Id_Type >& parallel_links 28614176514 q = context.link_by_origin.find(way.nds[way_context[i].pos])->second; 28714176514 q if (parallel_links.size() > 1) 2891037811 q uint parallel_links_pos = 0; 2901558711 q while (parallel_links_pos < parallel_links.size() 2911558711 q && !(parallel_links[parallel_links_pos] == way.id)) 2931037811 q if (parallel_links_pos+1 == parallel_links.size() || !(parallel_links[parallel_links_pos+1] == way.id)) 2941037611 q way_context[i].local_id = parallel_links_pos + 1; 29721 q Node_Skeleton::Id_Type target_id = 29821 q (i+1 < way_context.size() ? way.nds[way_context[i+1].pos] : way.nds.back()); 29921 q for (std::vector< std::pair< Node_Skeleton::Id_Type, Node_Skeleton::Id_Type > >::const_iterator 30031 q it_pair = segment_count.begin(); it_pair != segment_count.end(); ++it_pair) 30211 q if (it_pair->first == way.nds[way_context[i].pos] && it_pair->second == target_id) 30521 q way_context[i].local_id = parallel_links_pos + 1; 30621 q segment_count.push_back(std::make_pair(way.nds[way_context[i].pos], target_id)); 313 Figure_Out_Local_Ids_Of_Links( 314 std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >& context_by_node_id_, 315 std::map< Way_Skeleton::Id_Type, std::vector< NWR_Context::Way_Section_Context > >& context_by_way_id_) 3164219 q : context_by_node_id(&context_by_node_id_), context_by_way_id(&context_by_way_id_) {} 318 std::map< Node_Skeleton::Id_Type, NWR_Context::Node_Context >* context_by_node_id; 319 std::map< Way_Skeleton::Id_Type, std::vector< NWR_Context::Way_Section_Context > >* context_by_way_id; 323NWR_Context::NWR_Context(Resource_Manager& rman, const Statement& stmt, const Set& input_set, 324 const Owner< Bbox_Double >& bbox) 326 // Collect all objects required for context 3282119 q Request_Context context(&stmt, rman); 3310 Bbox_Filter filter(*bbox); 3320 add_nw_member_objects(context, input_set, relevant_nwrs, &filter.get_ranges_32(), &filter.get_ranges_31()); 3352119 q add_nw_member_objects(context, input_set, relevant_nwrs); 3382119 q if (rman.get_desired_timestamp() == NOW) 3401414 q collect_ways(context, relevant_nwrs.nodes, {}, 0, {}, true).swap(extra_ways.ways, extra_ways.attic_ways); 3411414 q sort_second(extra_ways.ways); 3421414 q indexed_set_union(relevant_nwrs.ways, extra_ways.ways); 34676 q collect_ways(context, relevant_nwrs.nodes, relevant_nwrs.attic_nodes, 0, 34776 q {}, true).swap(extra_ways.ways, extra_ways.attic_ways); 34876 q indexed_set_union(relevant_nwrs.attic_ways, extra_ways.attic_ways); 34976 q indexed_set_union(relevant_nwrs.ways, extra_ways.ways); 35076 q keep_matching_skeletons(relevant_nwrs.ways, relevant_nwrs.attic_ways, rman.get_desired_timestamp()); 353 // Build local ids for node segments 3552119 q indexed_set_union(relevant_nwrs.nodes, input_set.nodes); 3562119 q indexed_set_union(relevant_nwrs.attic_nodes, input_set.attic_nodes); 3572119 q keep_matching_skeletons(relevant_nwrs.nodes, relevant_nwrs.attic_nodes, rman.get_desired_timestamp()); 3592119 q std::map< Uint32_Index, std::vector< Node_Skeleton > >::const_iterator it_now_idx 3602119 q = relevant_nwrs.nodes.begin(); 3612119 q std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >::const_iterator it_attic_idx 3622119 q = relevant_nwrs.attic_nodes.begin(); 3641634919 q while (it_now_idx != relevant_nwrs.nodes.end() || it_attic_idx != relevant_nwrs.attic_nodes.end()) 3661632816 q std::vector< const Node_Skeleton* > elem_refs; 3681632816 q bool now_relevant = false; 3691632816 q bool attic_relevant = false; 3701632816 q if (it_attic_idx == relevant_nwrs.attic_nodes.end()) 37226314 q else if (it_now_idx == relevant_nwrs.nodes.end()) 3730 attic_relevant = true; 37426314 q else if (it_now_idx->first < it_attic_idx->first) 37517292 q now_relevant = true; 3769024 q else if (it_attic_idx->first < it_now_idx->first) 377652 q attic_relevant = true; 3808374 q now_relevant = true; 3818374 q attic_relevant = true; 3861626316 q for (std::vector< Node_Skeleton >::const_iterator it_elem = it_now_idx->second.begin(); 38746388616 q it_elem != it_now_idx->second.end(); ++it_elem) 38844762316 q elem_refs.push_back(&*it_elem); 3959024 q for (std::vector< Attic< Node_Skeleton > >::const_iterator it_elem = it_attic_idx->second.begin(); 39652714 q it_elem != it_attic_idx->second.end(); ++it_elem) 39743694 q elem_refs.push_back(&*it_elem); 4021632816 q std::sort(elem_refs.begin(), elem_refs.end(), Node_Skeleton_By_Coord_Then_Id()); 40545210416 q for (uint i = 1; i < elem_refs.size(); ++i) 40743577616 q if (elem_refs[equal_since]->ll_lower == elem_refs[i]->ll_lower) 409764 q if (i - equal_since == 1) 410684 q context_by_node_id_[elem_refs[equal_since]->id].local_id = 1; 411764 q context_by_node_id_[elem_refs[i]->id].local_id = i + 1 - equal_since; 418 // Store node coordinates for use by links 4192119 q for_each_elem(relevant_nwrs.nodes, Set_Coord_In_Context(context_by_node_id_)); 4202119 q for_each_elem(relevant_nwrs.attic_nodes, Set_Coord_In_Context(context_by_node_id_)); 422 // Count node use by ways 4232119 q for_each_elem(relevant_nwrs.ways, Count_Node_Use(context_by_node_id_)); 4242119 q for_each_elem(relevant_nwrs.attic_ways, Count_Node_Use(context_by_node_id_)); 428void NWR_Context::prepare_links(Resource_Manager& rman, const Statement& stmt, const Set& input_set, 429 const Owner< Bbox_Double >& bbox) 4322119 q for_each_elem(relevant_nwrs.ways, Partition_Into_Links(context_by_node_id_, context_by_way_id_, bbox)); 4332119 q for_each_elem(relevant_nwrs.attic_ways, Partition_Into_Links(context_by_node_id_, context_by_way_id_, bbox)); 4352119 q for (std::map< Node_Skeleton::Id_Type, Node_Context >::iterator it_ctx = context_by_node_id_.begin(); 436104310019 q it_ctx != context_by_node_id_.end(); ++it_ctx) 438104307916 q for (std::map< Node_Skeleton::Id_Type, std::vector< Way_Skeleton::Id_Type > >::iterator 439117964816 q it_orig = it_ctx->second.link_by_origin.begin(); it_orig != it_ctx->second.link_by_origin.end(); ++it_orig) 44013656914 q std::sort(it_orig->second.begin(), it_orig->second.end()); 443 // Figure out local ids of links 4442119 q for_each_elem(relevant_nwrs.ways, Figure_Out_Local_Ids_Of_Links(context_by_node_id_, context_by_way_id_)); 4452119 q for_each_elem(relevant_nwrs.attic_ways, Figure_Out_Local_Ids_Of_Links(context_by_node_id_, context_by_way_id_)); 449Derived_Skeleton::Id_Type NWR_Context::local_id_by_node_id(Node_Skeleton::Id_Type id) const 4511684610 q std::map< Node_Skeleton::Id_Type, Node_Context >::const_iterator it 4521684610 q = context_by_node_id_.find(id); 4531684610 q if (it != context_by_node_id_.end()) 4541684610 q return it->second.local_id; 4550 return Derived_Skeleton::Id_Type(0ull); 459struct Derived_Structure_Builder 461 Derived_Structure_Builder(Resource_Manager& rman, 462 const std::string& name, Opaque_Geometry* geometry, 463 const std::vector< std::pair< std::string, std::string > >* tags) 46625584116 q target.id = rman.get_global_settings().dispense_derived_id(); 46725584116 q target.acquire_geometry(geometry); 47124170816 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it_tag = tags->begin(); 472281309816 q it_tag != tags->end(); ++it_tag) 473257139016 q target.tags.push_back(std::make_pair( 474257139016 q it_tag->first.empty() ? "" : it_tag->first[0] == '_' ? "_" + it_tag->first : it_tag->first, 479 void set_tag(const std::string& key, const std::string& value) 48021526814 q { target.tags.push_back(std::make_pair(key, value)); } 482 const Derived_Structure& get() 48443987416 q std::sort(target.tags.begin(), target.tags.end()); 489 Derived_Structure target; 493template< typename Index, typename Maybe_Attic > 494void process_vertices(const std::map< Index, std::vector< Maybe_Attic > >& items, Set_With_Context& context_from, 495 Set& into, Resource_Manager& rman, NWR_Context& nwr_context, 496 Localize_Statement::Mode mode, const Owner< Bbox_Double >& bbox) 4982519 q for (typename std::map< Index, std::vector< Maybe_Attic > >::const_iterator it_idx = items.begin(); 49977419 q it_idx != items.end(); ++it_idx) 50174910 q for (typename std::vector< Maybe_Attic >::const_iterator it_elem = it_idx->second.begin(); 5028369710 q it_elem != it_idx->second.end(); ++it_elem) 5048294810 q const Element_With_Context< Maybe_Attic >& data = context_from.get_context(it_idx->first, *it_elem); 5068294810 q if (mode == Localize_Statement::all || (data.tags && !data.tags->empty())) 5081684610 q NWR_Context::Node_Context& node_context = nwr_context.context_by_node_id(it_elem->id); 5091684610 q if (data.tags && !data.tags->empty()) 51033449 q ++node_context.count; 5121684610 q if (admissible_by_bbox(bbox, node_context)) 5141684610 q Derived_Structure_Builder result(rman, "vertex", 5161684610 q ::lat(it_idx->first.val(), it_elem->ll_lower), ::lon(it_idx->first.val(), it_elem->ll_lower)), 5191684610 q Derived_Skeleton::Id_Type local_id = nwr_context.local_id_by_node_id(it_elem->id); 521622 q result.set_tag("_local_id", to_string(local_id.val())); 5231684610 q if (mode == Localize_Statement::all) 524139614 q result.set_tag("_node_ref", to_string(it_elem->id.val())); 5261684610 q into.deriveds[Uint31_Index(0u)].push_back(result.get()); 534template< typename Index, typename Maybe_Attic > 535void generate_links(const std::map< Index, std::vector< Maybe_Attic > >& items, Set_With_Context& context_from, 536 Set& into, Resource_Manager& rman, NWR_Context& nwr_context, 537 Localize_Statement::Mode mode, const Owner< Bbox_Double >& bbox) 5392619 q for (typename std::map< Index, std::vector< Maybe_Attic > >::const_iterator it_idx = items.begin(); 54077019 q it_idx != items.end(); ++it_idx) 54274411 q for (typename std::vector< Maybe_Attic >::const_iterator it_elem = it_idx->second.begin(); 5432079511 q it_elem != it_idx->second.end(); ++it_elem) 5452005111 q const Element_With_Context< Maybe_Attic >& data = context_from.get_context(it_idx->first, *it_elem); 5472005111 q if (mode == Localize_Statement::all || (data.tags && !data.tags->empty())) 5491995411 q std::vector< NWR_Context::Way_Section_Context >& way_context = nwr_context.context_by_way_id(it_elem->id); 5511995411 q for (std::vector< NWR_Context::Way_Section_Context >::const_iterator it_way_ctx = way_context.begin(); 5527351711 q it_way_ctx != way_context.end(); ++it_way_ctx) 5545356311 q if (it_way_ctx->points.empty()) 5575356311 q Derived_Structure_Builder result(rman, "link", 5585356311 q new Linestring_Geometry(it_way_ctx->points), data.tags); 5605356311 q if (it_way_ctx->local_from.val()) 5611072 q result.set_tag("_local_from", to_string(it_way_ctx->local_from.val())); 5625356311 q if (it_way_ctx->local_to.val()) 5631072 q result.set_tag("_local_to", to_string(it_way_ctx->local_to.val())); 5645356311 q if (it_way_ctx->local_id.val()) 56570467 q result.set_tag("_local_id", to_string(it_way_ctx->local_id.val())); 5675356311 q if (mode == Localize_Statement::all) 56872694 q result.set_tag("_way_ref", to_string(it_elem->id.val())); 5705356311 q into.deriveds[Uint31_Index(0u)].push_back(result.get()); 578template< typename Index, typename Maybe_Attic > 579void generate_loose_links(const std::map< Index, std::vector< Maybe_Attic > >& items, 580 Set_With_Context& context_from, Set& into, Resource_Manager& rman, Localize_Statement::Mode mode) 5822014 q for (typename std::map< Index, std::vector< Maybe_Attic > >::const_iterator it_idx = items.begin(); 58367814 q it_idx != items.end(); ++it_idx) 5856589 q for (typename std::vector< Maybe_Attic >::const_iterator it_elem = it_idx->second.begin(); 58696439 q it_elem != it_idx->second.end(); ++it_elem) 58889859 q const Element_With_Context< Maybe_Attic >& data = context_from.get_context(it_idx->first, *it_elem); 59089859 q if ((mode == Localize_Statement::all || (data.tags && !data.tags->empty())) 59189859 q && it_elem->nds.empty()) 5930 Derived_Structure_Builder result(rman, "link", new Null_Geometry(), data.tags); 5950 if (mode == Localize_Statement::all) 5960 result.set_tag("_way_ref", to_string(it_elem->id.val())); 5980 into.deriveds[Uint31_Index(0u)].push_back(result.get()); 605template< typename Index, typename Maybe_Attic > 606void generate_trigraphs(const std::map< Index, std::vector< Maybe_Attic > >& items, Set_With_Context& context_from, 607 Set& into, Resource_Manager& rman, NWR_Context& nwr_context, 608 Localize_Statement::Mode mode, const Owner< Bbox_Double >& bbox) 6102619 q for (typename std::map< Index, std::vector< Maybe_Attic > >::const_iterator it_idx = items.begin(); 61117319 q it_idx != items.end(); ++it_idx) 6131478 q for (typename std::vector< Maybe_Attic >::const_iterator it_elem = it_idx->second.begin(); 6149998 q it_elem != it_idx->second.end(); ++it_elem) 6168528 q const Element_With_Context< Maybe_Attic >& data = context_from.get_context(it_idx->first, *it_elem); 6188528 q if (mode == Localize_Statement::all || (data.tags && !data.tags->empty())) 6208528 q Derived_Structure* last = 0; 6218528 q Point_Double last_point(100., 0.); 6238528 q for (std::vector< Relation_Entry >::const_iterator it_memb = data.object->members.begin(); 6241817338 q it_memb != data.object->members.end(); ++it_memb) 6261808818 q if (it_memb->type == Relation_Entry::NODE) 62875078 q NWR_Context::Node_Context& node_context = nwr_context.context_by_node_id(it_memb->ref); 63075078 q if (admissible_by_bbox(bbox, node_context)) 63275078 q Derived_Structure_Builder result(rman, "trigraph", 63375078 q new Point_Geometry(node_context.lat, node_context.lon), data.tags); 63575078 q if (node_context.local_id.val()) 6360 result.set_tag("_local_ref", to_string(node_context.local_id.val())); 63875078 q if (mode == Localize_Statement::all) 64021 q result.set_tag("_child_node_ref", to_string(it_memb->ref.val())); 64121 q result.set_tag("_relation_ref", to_string(it_elem->id.val())); 64668488 q last->tags.push_back(std::make_pair("_next", to_string(result.get().id.val()))); 64768488 q result.set_tag("_previous", to_string(last->id.val())); 64975078 q into.deriveds[Uint31_Index(0u)].push_back(result.get()); 65075078 q last = &into.deriveds[Uint31_Index(0u)].back(); 6551733748 q else if (it_memb->type == Relation_Entry::WAY) 6571726248 q std::vector< NWR_Context::Way_Section_Context >& way_context 6581726248 q = nwr_context.context_by_way_id(Way_Skeleton::Id_Type(it_memb->ref.val())); 6601726248 q if (way_context.empty()) 666930268 q enum { both_possible, must_forwards, must_backwards } elem_orientation = both_possible; 667930268 q if (last && last_point.lat <= 90.) 669920518 q if (!way_context.front().points.empty() && last_point == way_context.front().points.front()) 670597068 q elem_orientation = must_forwards; 671323458 q else if (!way_context.back().points.empty() && last_point == way_context.back().points.back()) 672296418 q elem_orientation = must_backwards; 674930268 q if (elem_orientation == both_possible) 67636798 q std::vector< Relation_Entry >::const_iterator it_next = it_memb+1; 67736798 q if (it_next != data.object->members.end() && it_next->type == Relation_Entry::WAY) 67921638 q std::vector< NWR_Context::Way_Section_Context >& next_way_context 68021638 q = nwr_context.context_by_way_id(Way_Skeleton::Id_Type(it_next->ref.val())); 68121638 q if (!next_way_context.empty()) 68320348 q if (!way_context.back().points.empty() 68420348 q && ((!next_way_context.front().points.empty() 68520348 q && next_way_context.front().points.front() == way_context.back().points.back()) 68620348 q || (!next_way_context.back().points.empty() 68712348 q && next_way_context.back().points.back() == way_context.back().points.back()))) 6889138 q elem_orientation = must_forwards; 68911218 q else if (!way_context.front().points.empty() 69011218 q && ((!next_way_context.front().points.empty() 69111218 q && next_way_context.front().points.front() == way_context.front().points.front()) 69211218 q || (!next_way_context.back().points.empty() 69310228 q && next_way_context.back().points.back() == way_context.front().points.front()))) 6946348 q elem_orientation = must_backwards; 699930268 q if (elem_orientation != must_backwards) 7011780508 q for (uint i = 0; i < way_context.size(); ++i) 7031152998 q if (way_context[i].points.empty()) 7091152998 q Derived_Structure_Builder result(rman, "trigraph", 7101152998 q new Linestring_Geometry(way_context[i].points), data.tags); 7121152998 q if (way_context[i].local_from.val()) 71362 q result.set_tag("_vertex_local_from", to_string(way_context[i].local_from.val())); 7141152998 q if (way_context[i].local_to.val()) 71562 q result.set_tag("_vertex_local_to", to_string(way_context[i].local_to.val())); 7161152998 q if (way_context[i].local_id.val()) 71717756 q result.set_tag("_local_ref", to_string(way_context[i].local_id.val())); 7191152998 q if (mode == Localize_Statement::all) 72151 q result.set_tag("_child_way_ref", to_string(it_memb->ref.val())); 72251 q result.set_tag("_relation_ref", to_string(it_elem->id.val())); 7271147228 q last->tags.push_back(std::make_pair("_next", to_string(result.get().id.val()))); 7281147228 q result.set_tag("_previous", to_string(last->id.val())); 7301152998 q into.deriveds[Uint31_Index(0u)].push_back(result.get()); 7311152998 q last = &into.deriveds[Uint31_Index(0u)].back(); 733627518 q last_point = (way_context.empty() || way_context.back().points.empty()) ? Point_Double(100., 0.) 734627518 q : way_context.back().points.back(); 738922948 q for (int i = way_context.size()-1; i >= 0; --i) 740620198 q if (way_context[i].points.empty()) 746620198 q std::vector< Point_Double > points = way_context[i].points; 747620198 q std::reverse(points.begin(), points.end()); 748620198 q Derived_Structure_Builder result(rman, "trigraph", 749620198 q new Linestring_Geometry(points), data.tags); 751620198 q if (way_context[i].local_to.val()) 75282 q result.set_tag("_vertex_local_from", to_string(way_context[i].local_to.val())); 753620198 q if (way_context[i].local_from.val()) 75482 q result.set_tag("_vertex_local_to", to_string(way_context[i].local_from.val())); 755620198 q if (way_context[i].local_id.val()) 7568605 q result.set_tag("_local_ref", to_string(way_context[i].local_id.val())); 758620198 q if (mode == Localize_Statement::all) 76031 q result.set_tag("_child_way_ref", to_string(it_memb->ref.val())); 76131 q result.set_tag("_relation_ref", to_string(it_elem->id.val())); 766618968 q last->tags.push_back(std::make_pair("_next", to_string(result.get().id.val()))); 767618968 q result.set_tag("_previous", to_string(last->id.val())); 769620198 q into.deriveds[Uint31_Index(0u)].push_back(result.get()); 770620198 q last = &into.deriveds[Uint31_Index(0u)].back(); 772302758 q last_point = (way_context.empty() || way_context.front().points.empty()) ? Point_Double(100., 0.) 773302758 q : way_context.front().points.front(); 7767505 q else if (mode >= Localize_Statement::also_loose) 7786074 q Derived_Structure_Builder result(rman, "trigraph", new Null_Geometry(), data.tags); 7806074 q if (mode == Localize_Statement::all) 7820 result.set_tag("_child_relation_ref", to_string(it_memb->ref.val())); 7830 result.set_tag("_relation_ref", to_string(it_elem->id.val())); 7885674 q last->tags.push_back(std::make_pair("_next", to_string(result.get().id.val()))); 7895674 q result.set_tag("_previous", to_string(last->id.val())); 7916074 q into.deriveds[Uint31_Index(0u)].push_back(result.get()); 7926074 q last = &into.deriveds[Uint31_Index(0u)].back(); 795 // Relation members do not have any effect without loose mode 804void Localize_Statement::execute(Resource_Manager& rman) 8102119 q const Set* input_set = rman.get_set(input); 8130 transfer_output(rman, into); 8172119 q Owner< Bbox_Double > bbox(south <= 90. ? new Bbox_Double(south, west, north, east) : 0); 8192119 q Requested_Context requested_context; 8202119 q requested_context.add_usage(input, Set_Usage::TAGS); 8212119 q Prepare_Task_Context context(requested_context, *this, rman); 8222119 q Set_With_Context* context_from = context.get_set(input); 8242119 q if (context_from && context_from->base) 8262119 q NWR_Context nwr_context(rman, *this, *input_set, bbox); 8272119 q process_vertices(context_from->base->nodes, *context_from, into, rman, nwr_context, type, bbox); 8282119 q if (!context_from->base->attic_nodes.empty()) 82943 q process_vertices(context_from->base->attic_nodes, *context_from, into, rman, nwr_context, type, bbox); 8312119 q nwr_context.prepare_links(rman, *this, *input_set, bbox); 8322119 q generate_links(context_from->base->ways, *context_from, into, rman, nwr_context, type, bbox); 8332119 q if (!context_from->base->attic_ways.empty()) 83454 q generate_links(context_from->base->attic_ways, *context_from, into, rman, nwr_context, type, bbox); 8381614 q generate_loose_links(context_from->base->ways, *context_from, into, rman, type); 8391614 q if (!context_from->base->attic_ways.empty()) 84043 q generate_loose_links(context_from->base->attic_ways, *context_from, into, rman, type); 8432119 q generate_trigraphs(context_from->base->relations, *context_from, into, rman, nwr_context, type, bbox); 8442119 q if (!context_from->base->attic_ways.empty()) 84554 q generate_trigraphs(context_from->base->attic_relations, *context_from, into, rman, nwr_context, type, bbox); 8482119 q transfer_output(rman, into); 8492119 q rman.health_check(*this);