【问题标题】:User defined spatial predicate within Boost GeometryBoost Geometry 中用户定义的空间谓词
【发布时间】:2015-04-14 23:06:57
【问题描述】:

我需要确定两个几何图形的内部是否相交。 InteriorsIntersect 谓词不是由 OGC 或 Boost Geometry 指定,而是由 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 中的一个算法。

【问题讨论】:

    标签: c++ boost boost-geometry


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 1970-01-01
      相关资源
      最近更新 更多