...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Checks relation between a pair of geometries defined by a mask.
template<typename Geometry1, typename Geometry2, typename Mask, typename Strategy> bool relate(Geometry1 const & geometry1, Geometry2 const & geometry2, Mask const & mask, Strategy const & strategy)
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 |
Mask const & |
An intersection model Mask type. |
mask |
An intersection model mask object. |
Strategy const & |
Any type fulfilling a Relate Strategy Concept |
strategy |
The strategy which will be used for relate calculations |
true if the relation is compatible with the mask, false otherwise.
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/algorithms/relate.hpp>
The function relate implements function Relate from the OGC Simple Feature Specification.
Shows how to detect if a point is inside a polygon, or not
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> int main() { using point_type = boost::geometry::model::d2::point_xy<double>; using polygon_type = boost::geometry::model::polygon<point_type>; polygon_type poly; boost::geometry::read_wkt( "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly); point_type p(4, 1); boost::geometry::de9im::mask mask("T*F**F***"); // within bool check = boost::geometry::relate(p, poly, mask); std::cout << "relate: " << (check ? "yes" : "no") << std::endl; return 0; }
Output:
relate: yes