Boost Geometry 中用户定义的空间谓词

User defined spatial predicate within Boost Geometry

我需要确定两个几何图形的内部是否相交。 OGC 或 Boost Geometry 未指定 InteriorsIntersect 谓词,而是由 DE-9IM 矩阵 (see also) 定义:

T * *
* * *
* * *

我使用 Boost Geometry 中的 relate 函数创建了自己的谓词。

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);
}

效果很好。我唯一担心的是 relate 函数和 static_mask 类型没有记录为 Boost Geometry API 的一部分,据我所知是实现细节。这样使用 relate 安全吗?有没有其他方法可以使用 Boost Geometry 实现相同的目标?理想情况下,我希望看到 relate 成为 boost/geometry/algorithms.

内的算法

relate()relation() 函数计划在 Boost 1.59 中发布。该界面与问题中提到的界面略有不同:

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();

也可以传递更复杂的掩码:

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);