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 "geometry_from_quad_coords.h" 22Opaque_Geometry* make_linestring_way_geom(const std::vector< Quad_Coord >& geometry) 241515210 q bool is_complete = true; 2518299710 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 2616784510 q is_complete &= (it->ll_upper != 0 || it->ll_lower != 0); 30124518 q std::vector< Point_Double > coords; 311344728 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 321220218 q coords.push_back(Point_Double(::lat(it->ll_upper, it->ll_lower), ::lon(it->ll_upper, it->ll_lower))); 33124518 q return new Linestring_Geometry(coords); 3727013 q Partial_Way_Geometry* pw_geom = new Partial_Way_Geometry(); 38485253 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 40458243 q if (it->ll_upper != 0 || it->ll_lower != 0) 4111701 q pw_geom->add_point(Point_Double(::lat(it->ll_upper, it->ll_lower), ::lon(it->ll_upper, it->ll_lower))); 43446543 q pw_geom->add_point(Point_Double(100., 200.)); 4527013 q return pw_geom; 51const Opaque_Geometry& Geometry_From_Quad_Coords::make_way_geom( 52 const Way_Skeleton& skel, unsigned int mode, Way_Bbox_Geometry_Store* store) 571252584292 q if (store && (mode & Output_Mode::GEOMETRY)) 58139659 q geom = make_linestring_way_geom(store->get_geometry(skel)); 591238619290 q else if (store && ((mode & Output_Mode::BOUNDS) || (mode & Output_Mode::CENTER))) 612340114 q std::vector< Quad_Coord > geometry = store->get_geometry(skel); 632340114 q double min_lat = 100.; 642340114 q double max_lat = -100.; 652340114 q double min_lon = 200.; 662340114 q double max_lon = -200.; 6826479414 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 7024139314 q double lat = ::lat(it->ll_upper, it->ll_lower); 7124139314 q min_lat = std::min(min_lat, lat); 7224139314 q max_lat = std::max(max_lat, lat); 7324139314 q double lon = ::lon(it->ll_upper, it->ll_lower); 7424139314 q min_lon = std::min(min_lon, lon); 7524139314 q max_lon = std::max(max_lon, lon); 782340114 q if (min_lat <= max_lat) 802340114 q if (mode & Output_Mode::BOUNDS) 81749010 q geom = new Bbox_Geometry(min_lat, min_lon, max_lat, max_lon); 83159114 q geom = new Point_Geometry((min_lat + max_lat) / 2., (min_lon + max_lon) / 2.); 860 geom = new Null_Geometry(); 891215218287 q geom = new Null_Geometry(); 95const Opaque_Geometry& Geometry_From_Quad_Coords::make_way_geom( 96 const std::vector< Quad_Coord >* geometry, const std::pair< Quad_Coord, Quad_Coord* >* bounds) 10125793040 q if (geometry && !geometry->empty()) 10211871 q geom = make_linestring_way_geom(*geometry); 10325674340 q else if (bounds && (bounds->first.ll_upper | bounds->first.ll_lower)) 105307175 q if (bounds->second) 106297352 q geom = new Bbox_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower), 107297352 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower), 108297352 q ::lat(bounds->second->ll_upper, bounds->second->ll_lower), 109297352 q ::lon(bounds->second->ll_upper, bounds->second->ll_lower)); 1119823 q geom = new Point_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower), 1129823 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower)); 11522602640 q geom = new Null_Geometry(); 121Opaque_Geometry* make_verbatim_rel_geom(const std::vector< std::vector< Quad_Coord > >& geometry) 123627014 q bool is_complete = true; 124627014 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 12546759714 q it != geometry.end(); ++it) 12928656213 q else if (it->size() == 1) 1309759211 q is_complete &= ((*it)[0].ll_upper != 0 || (*it)[0].ll_lower != 0); 133158396712 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 134139499712 q is_complete &= (it2->ll_upper != 0 || it2->ll_lower != 0); 140334510 q Compound_Geometry* cp_geom = new Compound_Geometry(); 141334510 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 14222989910 q it != geometry.end(); ++it) 1450 cp_geom->add_component(new Null_Geometry()); 14622655410 q else if (it->size() == 1) 147488098 q cp_geom->add_component(new Point_Geometry( 148488098 q ::lat(it->front().ll_upper, it->front().ll_lower), 149488098 q ::lon(it->front().ll_upper, it->front().ll_lower))); 15217774510 q std::vector< Point_Double > coords; 153145778310 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 154128003810 q coords.push_back(Point_Double(::lat(it2->ll_upper, it2->ll_lower), ::lon(it2->ll_upper, it2->ll_lower))); 15517774510 q cp_geom->add_component(new Linestring_Geometry(coords)); 160292511 q else if (geometry.empty()) 1610 return new Null_Geometry(); 164292511 q Partial_Relation_Geometry* pr_geom = new Partial_Relation_Geometry(); 165292511 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 16623769811 q it != geometry.end(); ++it) 16917476510 q pr_geom->add_placeholder(); 1706000810 q else if (it->size() == 1 && ((*it)[0].ll_upper != 0 || (*it)[0].ll_lower != 0)) 17113107 q pr_geom->add_point(Point_Double( 17213107 q ::lat(it->front().ll_upper, it->front().ll_lower), 17313107 q ::lon(it->front().ll_upper, it->front().ll_lower))); 17722113010 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 17916243210 q if (it2->ll_upper != 0 || it2->ll_lower != 0) 1801142458 q pr_geom->add_way_point( 1811142458 q Point_Double(::lat(it2->ll_upper, it2->ll_lower), ::lon(it2->ll_upper, it2->ll_lower))); 183481878 q pr_geom->add_way_placeholder(); 193const Opaque_Geometry& Geometry_From_Quad_Coords::make_relation_geom( 194 const Relation_Skeleton& skel, unsigned int mode, Relation_Geometry_Store* store) 199215311178 q if (store && (mode & Output_Mode::GEOMETRY)) 200626713 q geom = make_verbatim_rel_geom(store->get_geometry(skel)); 201209044175 q else if (store && ((mode & Output_Mode::BOUNDS) || (mode & Output_Mode::CENTER))) 2033719 q std::vector< std::vector< Quad_Coord > > geometry = store->get_geometry(skel); 2053719 q double min_lat = 100.; 2063719 q double max_lat = -100.; 2073719 q double min_lon = 200.; 2083719 q double max_lon = -200.; 2103719 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 211105729 q it != geometry.end(); ++it) 213102019 q if (it->size() == 1) 2158755 q double lat = ::lat((*it)[0].ll_upper, (*it)[0].ll_lower); 2168755 q min_lat = std::min(min_lat, lat); 2178755 q max_lat = std::max(max_lat, lat); 2188755 q double lon = ::lon((*it)[0].ll_upper, (*it)[0].ll_lower); 2198755 q min_lon = std::min(min_lon, lon); 2208755 q max_lon = std::max(max_lon, lon); 22293269 q else if (!it->empty()) 224360046 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 226323136 q double lat = ::lat(it2->ll_upper, it2->ll_lower); 227323136 q min_lat = std::min(min_lat, lat); 228323136 q max_lat = std::max(max_lat, lat); 229323136 q double lon = ::lon(it2->ll_upper, it2->ll_lower); 230323136 q min_lon = std::min(min_lon, lon); 231323136 q max_lon = std::max(max_lon, lon); 2363719 q if (min_lat <= max_lat) 2383688 q if (max_lon - min_lon >= 180.) 24321 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 24419031 q it != geometry.end(); ++it) 24619011 q if (it->size() == 1) 248221 q double lon = ::lon((*it)[0].ll_upper, (*it)[0].ll_lower); 250221 q max_lon = std::max(max_lon, lon); 2520 min_lon = std::min(min_lon, lon); 25418791 q else if (!it->empty()) 2561481 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 2581251 q double lon = ::lon(it2->ll_upper, it2->ll_lower); 260771 q max_lon = std::max(max_lon, lon); 262481 q min_lon = std::min(min_lon, lon); 2683688 q if (mode & Output_Mode::BOUNDS) 269124 q geom = new Bbox_Geometry(min_lat, min_lon, max_lat, max_lon); 2713564 q geom = new Point_Geometry((min_lat + max_lat) / 2., (min_lon + max_lon) / 2.); 27433 q geom = new Null_Geometry(); 277208673172 q geom = new Null_Geometry(); 283const Opaque_Geometry& Geometry_From_Quad_Coords::make_relation_geom( 284 const std::vector< std::vector< Quad_Coord > >* geometry, const std::pair< Quad_Coord, Quad_Coord* >* bounds) 29031 q geom = make_verbatim_rel_geom(*geometry); 294731 q geom = new Bbox_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower), 295731 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower), 296731 q ::lat(bounds->second->ll_upper, bounds->second->ll_lower), 297731 q ::lon(bounds->second->ll_upper, bounds->second->ll_lower)); 2991952 q geom = new Point_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower), 3001952 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower)); 30383214 q geom = new Null_Geometry();