|  | Home | Libraries | People | FAQ | More | 
Checks if two geometries overlap.
template<typename Geometry1, typename Geometry2> bool overlaps(Geometry1 const & geometry1, Geometry2 const & geometry2)
| Type | Concept | Name | Description | 
|---|---|---|---|
| Geometry1 const & | Any type fulfilling a Geometry Concept | geometry1 | A model of the specified concept | 
| Geometry2 const & | Any type fulfilling a Geometry Concept | geometry2 | A model of the specified concept | 
Returns true if two geometries overlap
Either
            #include <boost/geometry.hpp>
          
Or
            #include <boost/geometry/algorithms/overlaps.hpp>
          
The function overlaps implements function Overlaps from the OGC Simple Feature Specification.
| Point | Segment | Box | Linestring | Ring | Polygon | MultiPoint | MultiLinestring | MultiPolygon | Variant | |
|---|---|---|---|---|---|---|---|---|---|---|
| Point | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| Segment | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| Box | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| Linestring | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| Ring | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| Polygon | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| MultiPoint | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| MultiLinestring | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| MultiPolygon | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
| Variant | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
                       | 
Checks if two geometries overlap
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> namespace bg = boost::geometry;int main() { // Checks if the two geometries overlaps or not. bg::model::polygon<bg::model::d2::point_xy<double> > poly1; bg::read_wkt("POLYGON((0 0,0 4,4 4,4 0,0 0))", poly1); bg::model::polygon<bg::model::d2::point_xy<double> > poly2; bg::read_wkt("POLYGON((2 2,2 6,6 7,6 1,2 2))", poly2); bool check_overlap = bg::overlaps(poly1, poly2); if (check_overlap) { std::cout << "Overlaps: Yes" << std::endl; } else { std::cout << "Overlaps: No" << std::endl; } bg::model::polygon<bg::model::d2::point_xy<double> > poly3; bg::read_wkt("POLYGON((-1 -1,-3 -4,-7 -7,-4 -3,-1 -1))", poly3); check_overlap = bg::overlaps(poly1, poly3); if (check_overlap) { std::cout << "Overlaps: Yes" << std::endl; } else { std::cout << "Overlaps: No" << std::endl; } return 0; }
Output:
Overlaps: YesOverlaps: No