...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Checks if a geometry are spatially equal.
The free function equals checks if the first geometry is spatially equal the second geometry. Spatially equal means that the same point set is included. A box can therefore be spatially equal to a ring or a polygon, or a linestring can be spatially equal to a multilinestring or a segment. This only theoretically, not all combinations are implemented yet.
template<typename Geometry1, typename Geometry2> bool equals(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 are spatially equal
Either
#include <boost/geometry/geometry.hpp>
Or
#include <boost/geometry/algorithms/equals.hpp>
The function equals implements function Equals from the OGC Simple Feature Specification.
Point 
Box 
Linestring 
Ring 
Polygon 
MultiPolygon 


Point 






Box 






Linestring 






Ring 






Polygon 






MultiPolygon 






Linear
Shows the predicate equals, which returns true if two geometries are spatially equal
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/polygon.hpp> #include <boost/geometry/geometries/adapted/boost_tuple.hpp> BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) #include <boost/assign.hpp> int main() { using boost::assign::tuple_list_of; typedef boost::tuple<int, int> point; boost::geometry::model::polygon<point> poly1, poly2; boost::geometry::exterior_ring(poly1) = tuple_list_of(0, 0)(0, 5)(5, 5)(5, 0)(0, 0); boost::geometry::exterior_ring(poly2) = tuple_list_of(5, 0)(0, 0)(0, 5)(5, 5)(5, 0); std::cout << "polygons are spatially " << (boost::geometry::equals(poly1, poly2) ? "equal" : "not equal") << std::endl; boost::geometry::model::box<point> box; boost::geometry::assign_values(box, 0, 0, 5, 5); std::cout << "polygon and box are spatially " << (boost::geometry::equals(box, poly2) ? "equal" : "not equal") << std::endl; return 0; }
Output:
polygons are spatially equal polygon and box are spatially equal