Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

equals

Checks if a geometry are spatially equal.

Description

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 multi-linestring or a segment. This only works theoretically, not all combinations are implemented yet.

Synopsis

template<typename Geometry1, typename Geometry2>
bool equals(Geometry1 const & geometry1, Geometry2 const & geometry2)

Parameters

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

Returns true if two geometries are spatially equal

Header

Either

#include <boost/geometry.hpp>

Or

#include <boost/geometry/algorithms/equals.hpp>

Conformance

The function equals implements function Equals from the OGC Simple Feature Specification.

Supported geometries

Point

Segment

Box

Linestring

Ring

Polygon

MultiPoint

MultiLinestring

MultiPolygon

Variant

Point

ok

nyi

nyi

nyi

nyi

nyi

nyi

nyi

nyi

nyi

Segment

nyi

ok

nyi

nyi

nyi

nyi

nyi

nyi

nyi

nyi

Box

nyi

nyi

ok

nyi

ok

ok

nyi

nyi

nyi

ok

Linestring

nyi

nyi

nyi

ok

nyi

nyi

nyi

ok

nyi

nyi

Ring

nyi

nyi

ok

nyi

ok

ok

nyi

nyi

nyi

ok

Polygon

nyi

nyi

ok

nyi

ok

ok

nyi

nyi

ok

ok

MultiPoint

nyi

nyi

nyi

nyi

nyi

nyi

nyi

nyi

nyi

nyi

MultiLinestring

nyi

nyi

nyi

ok

nyi

nyi

nyi

ok

nyi

nyi

MultiPolygon

nyi

nyi

nyi

nyi

nyi

ok

nyi

nyi

ok

ok

Variant

nyi

nyi

ok

nyi

ok

ok

nyi

nyi

nyi

ok

Complexity

Linear

Example

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

PrevUpHomeNext