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) 241160511 q bool is_complete = true; 2542236111 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 2641075611 q is_complete &= (it->ll_upper != 0 || it->ll_lower != 0); 3097779 q std::vector< Point_Double > coords; 313774269 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 323676499 q coords.push_back(Point_Double(::lat(it->ll_upper, it->ll_lower), ::lon(it->ll_upper, it->ll_lower))); 3397779 q return new Linestring_Geometry(coords); 3718285 q Partial_Way_Geometry* pw_geom = new Partial_Way_Geometry(); 38449355 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 40431075 q if (it->ll_upper != 0 || it->ll_lower != 0) 412862 q pw_geom->add_point(Point_Double(::lat(it->ll_upper, it->ll_lower), ::lon(it->ll_upper, it->ll_lower))); 43428215 q pw_geom->add_point(Point_Double(100., 200.)); 4518285 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) 571085048275 q if (store && (mode & Output_Mode::GEOMETRY)) 581159310 q geom = make_linestring_way_geom(store->get_geometry(skel)); 591073455274 q else if (store && ((mode & Output_Mode::BOUNDS) || (mode & Output_Mode::CENTER))) 61748910 q std::vector< Quad_Coord > geometry = store->get_geometry(skel); 63748910 q double min_lat = 100.; 64748910 q double max_lat = -100.; 65748910 q double min_lon = 200.; 66748910 q double max_lon = -200.; 6815577010 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 7014828110 q double lat = ::lat(it->ll_upper, it->ll_lower); 7114828110 q min_lat = std::min(min_lat, lat); 7214828110 q max_lat = std::max(max_lat, lat); 7314828110 q double lon = ::lon(it->ll_upper, it->ll_lower); 7414828110 q min_lon = std::min(min_lon, lon); 7514828110 q max_lon = std::max(max_lon, lon); 78748910 q if (min_lat <= max_lat) 80748910 q if (mode & Output_Mode::BOUNDS) 8132027 q geom = new Bbox_Geometry(min_lat, min_lon, max_lat, max_lon); 8342873 q geom = new Point_Geometry((min_lat + max_lat) / 2., (min_lon + max_lon) / 2.); 860 geom = new Null_Geometry(); 891065966271 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) 10113307146 q if (geometry && !geometry->empty()) 102121 q geom = make_linestring_way_geom(*geometry); 10313305946 q else if (bounds && (bounds->first.ll_upper | bounds->first.ll_lower)) 10632 q geom = new Bbox_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower), 10732 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower), 10832 q ::lat(bounds->second->ll_upper, bounds->second->ll_lower), 10932 q ::lon(bounds->second->ll_upper, bounds->second->ll_lower)); 1112052 q geom = new Point_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower), 1122052 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower)); 11513285146 q geom = new Null_Geometry(); 121Opaque_Geometry* make_verbatim_rel_geom(const std::vector< std::vector< Quad_Coord > >& geometry) 123527212 q bool is_complete = true; 124527212 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 1255605112 q it != geometry.end(); ++it) 1294386611 q else if (it->size() == 1) 13051309 q is_complete &= ((*it)[0].ll_upper != 0 || (*it)[0].ll_lower != 0); 13315747119 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 13415359759 q is_complete &= (it2->ll_upper != 0 || it2->ll_lower != 0); 14049789 q Compound_Geometry* cp_geom = new Compound_Geometry(); 14149789 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 142421489 q it != geometry.end(); ++it) 1450 cp_geom->add_component(new Null_Geometry()); 146371709 q else if (it->size() == 1) 14743936 q cp_geom->add_component(new Point_Geometry( 14843936 q ::lat(it->front().ll_upper, it->front().ll_lower), 14943936 q ::lon(it->front().ll_upper, it->front().ll_lower))); 152327779 q std::vector< Point_Double > coords; 15314583929 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 15414256159 q coords.push_back(Point_Double(::lat(it2->ll_upper, it2->ll_lower), ::lon(it2->ll_upper, it2->ll_lower))); 155327779 q cp_geom->add_component(new Linestring_Geometry(coords)); 16029410 q else if (geometry.empty()) 1610 return new Null_Geometry(); 16429410 q Partial_Relation_Geometry* pr_geom = new Partial_Relation_Geometry(); 16529410 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 1661390310 q it != geometry.end(); ++it) 169691310 q pr_geom->add_placeholder(); 17066969 q else if (it->size() == 1 && ((*it)[0].ll_upper != 0 || (*it)[0].ll_lower != 0)) 1711694 q pr_geom->add_point(Point_Double( 1721694 q ::lat(it->front().ll_upper, it->front().ll_lower), 1731694 q ::lon(it->front().ll_upper, it->front().ll_lower))); 17665279 q pr_geom->start_way(); 1771174559 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 1791109289 q if (it2->ll_upper != 0 || it2->ll_lower != 0) 1801103607 q pr_geom->add_way_point( 1811103607 q Point_Double(::lat(it2->ll_upper, it2->ll_lower), ::lon(it2->ll_upper, it2->ll_lower))); 1835687 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) 199157601172 q if (store && (mode & Output_Mode::GEOMETRY)) 200526310 q geom = make_verbatim_rel_geom(store->get_geometry(skel)); 201152338168 q else if (store && ((mode & Output_Mode::BOUNDS) || (mode & Output_Mode::CENTER))) 2032259 q std::vector< std::vector< Quad_Coord > > geometry = store->get_geometry(skel); 2052259 q double min_lat = 100.; 2062259 q double max_lat = -100.; 2072259 q double min_lon = 200.; 2082259 q double max_lon = -200.; 2102259 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 21194799 q it != geometry.end(); ++it) 21392549 q if (it->size() == 1) 2152266 q double lat = ::lat((*it)[0].ll_upper, (*it)[0].ll_lower); 2162266 q min_lat = std::min(min_lat, lat); 2172266 q max_lat = std::max(max_lat, lat); 2182266 q double lon = ::lon((*it)[0].ll_upper, (*it)[0].ll_lower); 2192266 q min_lon = std::min(min_lon, lon); 2202266 q max_lon = std::max(max_lon, lon); 22290289 q else if (!it->empty()) 224582127 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 226554637 q double lat = ::lat(it2->ll_upper, it2->ll_lower); 227554637 q min_lat = std::min(min_lat, lat); 228554637 q max_lat = std::max(max_lat, lat); 229554637 q double lon = ::lon(it2->ll_upper, it2->ll_lower); 230554637 q min_lon = std::min(min_lon, lon); 231554637 q max_lon = std::max(max_lon, lon); 2362259 q if (min_lat <= max_lat) 2381727 q if (max_lon - min_lon >= 180.) 2430 for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin(); 2440 it != geometry.end(); ++it) 2460 if (it->size() == 1) 2480 double lon = ::lon((*it)[0].ll_upper, (*it)[0].ll_lower); 2500 max_lon = std::max(max_lon, lon); 2520 min_lon = std::min(min_lon, lon); 2540 else if (!it->empty()) 2560 for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) 2580 double lon = ::lon(it2->ll_upper, it2->ll_lower); 2600 max_lon = std::max(max_lon, lon); 2620 min_lon = std::min(min_lon, lon); 2681727 q if (mode & Output_Mode::BOUNDS) 269483 q geom = new Bbox_Geometry(min_lat, min_lon, max_lat, max_lon); 2711244 q geom = new Point_Geometry((min_lat + max_lat) / 2., (min_lon + max_lon) / 2.); 274534 q geom = new Null_Geometry(); 277152113165 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) 29092 q geom = make_verbatim_rel_geom(*geometry); 294431 q geom = new Bbox_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower), 295431 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower), 296431 q ::lat(bounds->second->ll_upper, bounds->second->ll_lower), 297431 q ::lon(bounds->second->ll_upper, bounds->second->ll_lower)); 299473 q geom = new Point_Geometry(::lat(bounds->first.ll_upper, bounds->first.ll_lower), 300473 q ::lon(bounds->first.ll_upper, bounds->first.ll_lower)); 303117225 q geom = new Null_Geometry();