c++ - boost multi_polygon 相交不编译

标签 c++ boost intersection boost-geometry

我试图找到两个多边形几何体的交集。它没有编译涉及 add_rings.hpp 和 convert_ring.hpp 的错误。

这是我尝试编译的一些测试代码:

#include "stdafx.h"

#include <vector>
#include <sstream>
#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/geometries.hpp>

namespace bg = boost::geometry;

// Typedef to simplify our point object declaration.
typedef bg::model::d2::point_xy< double > boostPoint;

// Typedef to simplify our polygon object declaration.
typedef bg::model::polygon<boostPoint,true> boostPolygon;

// Typedef to simplify our polygon object declaration.
typedef bg::model::multi_polygon<boostPolygon> boostMultiPolygon;

int _tmain(int argc, _TCHAR* argv[])
{
    std::string multiPolyOne = "MULTIPOLYGON(((2 2,2 12,12 12,12 2,2 2)),((6 6,6 9,9 9,9 6,6 6)))";
    std::string multiPolyTwo = "MULTIPOLYGON(((2 2,2 12,12 12,12 2,2 2)),((3 3,3 13,13 13,13 3,3 3)))";
    std::string multiPolyThree = "MULTIPOLYGON(((4 4,4 8,8 8,8 4,4 4),(5 5,6 5,6 6,5 6,5 5)))";

    boostMultiPolygon mp1, mp2, mp3;

    // A deque required by boost.
    std::deque<boostMultiPolygon> output;

    // boost method we will be using.
    using bg::read_wkt;

    read_wkt(multiPolyOne,mp1);
    read_wkt(multiPolyTwo,mp2);
    read_wkt(multiPolyThree,mp3);

    // Run the boost intersection.
    bg::intersection(mp1, mp2, output);

    return 0;
}

这会产生以下错误:

c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\convert_ring.hpp(41): error C2664: 'boost::mpl::assertion_failed' : cannot convert parameter 1 from 'boost::mpl::failed ************(__thiscall boost::geometry::detail::overlay::convert_ring<Tag>::NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TAG::* ***********)(boost::mpl::assert_::types<T    )' to 'boost::mpl::assert<false>::type'
          with
          [
              Tag=tag_out,
              T1=tag_out
          ]
          No constructor could take the source type, or constructor overload resolution was ambiguous
          c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\add_rings.hpp(47) : see reference to class template instantiation 'boost::geometry::detail::overlay::convert_ring<Tag>' being compiled
          with
          [
              Tag=tag_out
          ]
          c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\add_rings.hpp(105) : see reference to function template instantiation 'void boost::geometry::detail::overlay::convert_and_add<GeometryOut,Geometry1,Geometry2,RingCollection>(GeometryOut &,const Geometry1 &,const Geometry2 &,const RingCollection &,boost::geometry::ring_identifier,bool,bool)' being compiled
          with
          [
              GeometryOut=OneOut,
              Geometry1=boostMultiPolygon,
              Geometry2=boostMultiPolygon,
              RingCollection=ring_container_type
          ]
          c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\overlay.hpp(268) : see reference to function template instantiation 'OutputIterator boost::geometry::detail::overlay::add_rings<GeometryOut,std::map<_Kty,_Ty>,Geometry1,Geometry2,ring_container_type,OutputIterator>(const SelectionMap &,const Geometry1 &,const Geometry2 &,const RingCollection &,OutputIterator)' being compiled
          with
          [
              OutputIterator=std::back_insert_iterator<std::deque<boostMultiPolygon>>,
              GeometryOut=OneOut,
              _Kty=boost::geometry::ring_identifier,
              _Ty=properties,
              Geometry1=boostMultiPolygon,
              Geometry2=boostMultiPolygon,
              SelectionMap=std::map<boost::geometry::ring_identifier,properties>,
              RingCollection=ring_container_type
          ]
          c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\intersection\interface.hpp(57) : see reference to function template instantiation 'OutputIterator boost::geometry::detail::overlay::overlay<Geometry1,Geometry2,Reverse1,Reverse2,ReverseOut,GeometryOut,Direction>::apply<RobustPolicy,std::back_insert_iterator<_Container>,Strategy>(const Geometry1 &,const Geometry2 &,const RobustPolicy &,OutputIterator,const Strategy &)' being compiled
          with
          [
              OutputIterator=std::back_insert_iterator<std::deque<boostMultiPolygon>>,
              Geometry1=boostMultiPolygon,
              Geometry2=boostMultiPolygon,
              Reverse1=false,
              Reverse2=false,
              ReverseOut=false,
              GeometryOut=OneOut,
              Direction=overlay_intersection,
              RobustPolicy=rescale_policy_type,
              _Container=std::deque<boostMultiPolygon>,
              Strategy=boost::geometry::strategy_intersection<boost::geometry::cartesian_tag,boostMultiPolygon,boostMultiPolygon,boost::geometry::model::d2::point_xy<double>,rescale_policy_type>
          ]
          c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\intersection\interface.hpp(139) : see reference to function template instantiation 'bool boost::geometry::dispatch::intersection<Geometry1,Geometry2>::apply<rescale_policy_type,GeometryOut,boost::geometry::strategy_intersection<Tag,Geometry1,Geometry2,IntersectionPoint,RobustPolicy>>(const Geometry1 &,const Geometry2 &,const RobustPolicy &,GeometryOut &,const Strategy &)' being compiled
          with
          [
              Geometry1=boostMultiPolygon,
              Geometry2=boostMultiPolygon,
              GeometryOut=std::deque<boostMultiPolygon>,
              Tag=boost::geometry::cartesian_tag,
              IntersectionPoint=boost::geometry::model::d2::point_xy<double>,
              RobustPolicy=rescale_policy_type,
              Strategy=boost::geometry::strategy_intersection<boost::geometry::cartesian_tag,boostMultiPolygon,boostMultiPolygon,boost::geometry::model::d2::point_xy<double>,rescale_policy_type>
          ]
          c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\intersection\interface.hpp(300) : see reference to function template instantiation 'bool boost::geometry::resolve_variant::intersection<Geometry1,Geometry2>::apply<GeometryOut>(const Geometry1 &,const Geometry2 &,GeometryOut &)' being compiled
          with
          [
              Geometry1=boostMultiPolygon,
              Geometry2=boostMultiPolygon,
              GeometryOut=std::deque<boostMultiPolygon>
          ]
          c:\boost_test\test1\runtest2\runtest2.cpp(65) : see reference to function template instantiation 'bool boost::geometry::intersection<boostMultiPolygon,boostMultiPolygon,std::deque<_Ty>>(const Geometry1 &,const Geometry2 &,GeometryOut &)' being compiled
          with
          [
              _Ty=boostMultiPolygon,
              Geometry1=boostMultiPolygon,
              Geometry2=boostMultiPolygon,
              GeometryOut=std::deque<boostMultiPolygon>
          ]
c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\convert_ring.hpp(41): error C2866: 'boost::geometry::detail::overlay::convert_ring<Tag>::mpl_assertion_in_line_80' : a const static data member of a managed type must be initialized at the point of declaration
          with
          [
              Tag=tag_out
          ]
c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\add_rings.hpp(47): error C2039: 'apply' : is not a member of 'boost::geometry::detail::overlay::convert_ring<Tag>'
          with
          [
              Tag=tag_out
          ]
c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\add_rings.hpp(47): error C3861: 'apply': identifier not found
c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\add_rings.hpp(53): error C2039: 'apply' : is not a member of 'boost::geometry::detail::overlay::convert_ring<Tag>'
          with
          [
              Tag=tag_out
          ]
c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\add_rings.hpp(53): error C3861: 'apply': identifier not found
c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\add_rings.hpp(59): error C2039: 'apply' : is not a member of 'boost::geometry::detail::overlay::convert_ring<Tag>'
          with
          [
              Tag=tag_out
          ]
c:\sourcecode\commoncomponents\boost\boost_1_59_0\boost\geometry\algorithms\detail\overlay\add_rings.hpp(59): error C3861: 'apply': identifier not found

最佳答案

您的评论具有误导性:

// A deque required by boost.

不是:

Collection of geometries (e.g. std::vector, std::deque, boost::geometry::multi*) of which the value_type fulfills a Point, LineString or Polygon concept, or it is the output geometry (e.g. for a box)

boostMultiPolygon output;

修复它

关于c++ - boost multi_polygon 相交不编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34419694/

相关文章:

c++ - OpenCV C++ Mat 类行和列 - 它们是成员变量(和相关问题)吗?

c++ - 检查路径是否有效,即使它不存在

c++ - 将一个类分离成cpp和头文件(C++)

python - 在 Python 中,如何获得两个列表的交集,同时保留交集的顺序?

c++ - 改进替代解析器的使用

c++ - 在 boost 中从 graphviz 读取的问题

c++ - 循环静态

java - 检测线的交叉点

java - 有效地确定两个集合是否在 Java 中有任何共同的项目

visual-studio - 为什么 Visual Studio 找不到 'tr1/unordered_map?