Jamerson
Jamerson

Reputation: 484

User defined spatial predicate within Boost Geometry

I need to determine whether the interiors of two geometries intersect. An InteriorsIntersect predicate is not specified by OGC or Boost Geometry but is defined by the DE-9IM matrix (see also):

T * *
* * *
* * *

I've created my own predicate using the relate function in Boost Geometry.

namespace bgr = boost::geometry::detail::relate;
using InteriorsIntersectMask = bgr::static_mask<'T','*','*','*','*','*','*','*','*'>;

template<typename Geom1, typename Geom2>
inline bool interiorsIntersect(const Geom1& geom1, const Geom2& geom2)
{
    return bgr::relate<InteriorsIntersectMask>(geom1, geom2);
}

This works great. My only concern is that the relate function and static_mask type are not documented as part of the Boost Geometry API and are implementation details as far as I can tell. Is it safe to use relate in this way? Is there an alternative to achieving the same goal using Boost Geometry? Ideally I would like to see relate be an algorithm within boost/geometry/algorithms.

Upvotes: 1

Views: 215

Answers (1)

Adam Wulkiewicz
Adam Wulkiewicz

Reputation: 2098

The relate() and relation() functions are planned for release in Boost 1.59. The interface is silghtly different than the one mentioned in the question:

namespace bg = boost::geometry;
using II = bg::de9im::static_mask<'T','*','*','*','*','*','*','*','*'>;
bool check1 = bg::relate(geom1, geom2, II());

bg::de9im::mask ii("T********");
bool check2 = bg::relate(geom1, geom2, ii);

bg::de9im::matrix m = bg::relation(geom1, geom2);
std::cout << m.str();

It is also possible to pass more complex masks:

bg::de9im::mask ii1("1********");
bg::de9im::mask ii2("2********");
// check if the intersection of interiors is linear or areal
bool check2 = bg::relate(geom1, geom2, ii1 || ii2);

Upvotes: 1

Related Questions