简体   繁体   English

boost :: geometry :: intersects对不同的几何类型不起作用?

[英]boost::geometry::intersects doesn't work for different geometry types?

I am trying to use boost::geometry::intersects to check if a segment intersects a polygon. 我正在尝试使用boost::geometry::intersects来检查线段是否与多边形相交。 The following code works well: 以下代码运行良好:

#include <boost/geometry/algorithms/correct.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <iostream>

namespace bg = boost::geometry;

int main(int argc, char** argv) {
  typedef bg::model::point<double, 2, bg::cs::cartesian> Point;
  bg::model::ring<Point> poly1, poly2;
  bg::model::segment<Point> s1, s2;

  bg::read_wkt("POLYGON((0.0 0.0, 1.0 1.0, 0.0 2.0, 2.0 1.0))", poly1);
  bg::correct(poly1);

  bg::read_wkt("POLYGON((1.5 0.0, 1.5 2.0, 3.0 1.0))", poly2);
  bg::correct(poly2);

  bg::read_wkt("SEGMENT(0.0 0.0,0.0 2.0)", s1);
  bg::read_wkt("SEGMENT(-1.0 1.0,2.0 1.0)", s2);

  std::cout << "Polygons intersect " << bg::intersects(poly1, poly2) << std::endl;
  std::cout << "Segments intersect " << bg::intersects(s1, s2) << std::endl;
  //std::cout << "Polygon and segment intersect " << bg::intersects(poly1, s1) << std::endl;

  return 0;
}

However, if I uncomment the line with bg::intersects(poly1, s1) I get the following compiling errors: 但是,如果取消对bg::intersects(poly1, s1)注释,则会出现以下编译错误:

g++    -c -g -I/opt/local/include -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o main.cpp
In file included from main.cpp:8:
In file included from /opt/local/include/boost/geometry/algorithms/correct.hpp:36:
In file included from /opt/local/include/boost/geometry/algorithms/disjoint.hpp:33:
In file included from /opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:56:
/opt/local/include/boost/geometry/algorithms/detail/sections/sectionalize.hpp:542:5: error: no matching function for call to 'assertion_failed'
    BOOST_MPL_ASSERT_MSG
    ^~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/mpl/assert.hpp:434:48: note: expanded from macro 'BOOST_MPL_ASSERT_MSG'
#define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
                                               ^
/opt/local/include/boost/mpl/assert.hpp:428:9: note: expanded from macro '\
BOOST_MPL_ASSERT_MSG_IMPL'
        boost::mpl::assertion_failed<(c)>( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/mpl/assert.hpp:59:58: note: expanded from macro '\
BOOST_MPL_AUX_ASSERT_CONSTANT'
#   define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) enum { expr }
                                                         ^
/opt/local/include/boost/geometry/algorithms/detail/sections/sectionalize.hpp:661:5: note: in instantiation of template class 'boost::geometry::dispatch::sectionalize<boost::geometry::segment_tag, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, false, boost::geometry::sections<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, 2, 10>' requested here
    sectionalizer_type::apply(geometry, sections, ring_id);
    ^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:453:9: note: in instantiation of function template specialization 'boost::geometry::sectionalize<false, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::sections<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2> >' requested here
        geometry::sectionalize<Reverse1>(geometry1, sec1, 0);
        ^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:877:18: note: in instantiation of member function 'boost::geometry::detail::get_turns::get_turns_generic<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, false, false, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::overlay::get_turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, boost::geometry::detail::disjoint::assign_disjoint_policy>, boost::geometry::detail::disjoint::disjoint_interrupt_policy>::apply' requested here
        >::type::apply(
                 ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:118:9: note: in instantiation of function template specialization 'boost::geometry::get_turns<false, false, boost::geometry::detail::disjoint::assign_disjoint_policy, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::disjoint::disjoint_interrupt_policy>' requested here
        geometry::get_turns
        ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:159:54: note: in instantiation of member function 'boost::geometry::detail::disjoint::disjoint_linear<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
        if (! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2))
                                                     ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:261:16: note: in instantiation of member function 'boost::geometry::detail::disjoint::general_areal<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
            >::apply(g2, g1);
               ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:344:54: note: in instantiation of member function 'boost::geometry::dispatch::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2, boost::geometry::ring_tag, boost::geometry::segment_tag, true>::apply' requested here
    return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
                                                     ^
/opt/local/include/boost/geometry/algorithms/intersects.hpp:99:14: note: in instantiation of function template specialization 'boost::geometry::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
    return ! geometry::disjoint(geometry1, geometry2);
             ^
main.cpp:49:52: note: in instantiation of function template specialization 'boost::geometry::intersects<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
  std::cout << "Polygon and segment intersect " << bg::intersects(poly1,s1) << std::endl;
                                                   ^
/opt/local/include/boost/mpl/assert.hpp:82:5: note: candidate function [with C = false] not viable: no known conversion from 'boost::mpl::failed ************(boost::geometry::dispatch::sectionalize<boost::geometry::segment_tag, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, false, boost::geometry::sections<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, 2, 10>::NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE::************)(types<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >)' to 'typename assert<false>::type' (aka 'mpl_::assert<false>') for 1st argument
int assertion_failed( typename assert<C>::type );
    ^
In file included from main.cpp:8:
In file included from /opt/local/include/boost/geometry/algorithms/correct.hpp:36:
In file included from /opt/local/include/boost/geometry/algorithms/disjoint.hpp:33:
In file included from /opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:35:
/opt/local/include/boost/geometry/views/detail/range_type.hpp:39:5: error: no matching function for call to 'assertion_failed'
    BOOST_MPL_ASSERT_MSG
    ^~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/mpl/assert.hpp:434:48: note: expanded from macro 'BOOST_MPL_ASSERT_MSG'
#define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
                                               ^
/opt/local/include/boost/mpl/assert.hpp:428:9: note: expanded from macro '\
BOOST_MPL_ASSERT_MSG_IMPL'
        boost::mpl::assertion_failed<(c)>( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/boost/mpl/assert.hpp:59:58: note: expanded from macro '\
BOOST_MPL_AUX_ASSERT_CONSTANT'
#   define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) enum { expr }
                                                         ^
/opt/local/include/boost/geometry/views/detail/range_type.hpp:94:32: note: in instantiation of template class 'boost::geometry::dispatch::range_type<boost::geometry::segment_tag, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
    typedef typename dispatch::range_type
                               ^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:104:22: note: in instantiation of template class 'boost::geometry::detail::range_type<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
            typename range_type<Geometry1>::type const,
                     ^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:408:20: note: in instantiation of template class 'boost::geometry::detail::get_turns::get_turns_in_sections<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, false, false, boost::geometry::section<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, boost::geometry::section<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::overlay::get_turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, boost::geometry::detail::disjoint::assign_disjoint_policy>, boost::geometry::detail::disjoint::disjoint_interrupt_policy>' requested here
            return get_turns_in_sections
                   ^
/opt/local/include/boost/geometry/algorithms/detail/partition.hpp:415:29: note: in instantiation of function template specialization 'boost::geometry::detail::get_turns::section_visitor<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, false, false, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::overlay::get_turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, boost::geometry::detail::disjoint::assign_disjoint_policy>, boost::geometry::detail::disjoint::disjoint_interrupt_policy>::apply<boost::geometry::section<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2> >' requested here
                    visitor.apply(*it1, *it2);
                            ^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:464:9: note: in instantiation of function template specialization 'boost::geometry::partition<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::detail::get_turns::get_section_box, boost::geometry::detail::get_turns::ovelaps_section_box, boost::geometry::visit_no_policy>::apply<boost::geometry::sections<boost::geometry::model::box<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2>, boost::geometry::detail::get_turns::section_visitor<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, false, false, std::__1::deque<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, std::__1::allocator<boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> > > >, boost::geometry::detail::overlay::get_turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_info<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, boost::geometry::detail::overlay::turn_operation, boost::array<boost::geometry::detail::overlay::turn_operation, 2> >, boost::geometry::detail::disjoint::assign_disjoint_policy>, boost::geometry::detail::disjoint::disjoint_interrupt_policy> >' requested here
        geometry::partition
        ^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:877:18: note: (skipping 2 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
        >::type::apply(
                 ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:159:54: note: in instantiation of member function 'boost::geometry::detail::disjoint::disjoint_linear<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
        if (! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2))
                                                     ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:261:16: note: in instantiation of member function 'boost::geometry::detail::disjoint::general_areal<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
            >::apply(g2, g1);
               ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:344:54: note: in instantiation of member function 'boost::geometry::dispatch::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2, boost::geometry::ring_tag, boost::geometry::segment_tag, true>::apply' requested here
    return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
                                                     ^
/opt/local/include/boost/geometry/algorithms/intersects.hpp:99:14: note: in instantiation of function template specialization 'boost::geometry::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
    return ! geometry::disjoint(geometry1, geometry2);
             ^
main.cpp:49:52: note: in instantiation of function template specialization 'boost::geometry::intersects<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
  std::cout << "Polygon and segment intersect " << bg::intersects(poly1,s1) << std::endl;
                                                   ^
/opt/local/include/boost/mpl/assert.hpp:82:5: note: candidate function [with C = false] not viable: no known conversion from 'boost::mpl::failed ************(boost::geometry::dispatch::range_type<boost::geometry::segment_tag, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >::NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE::************)(types<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >)' to 'typename assert<false>::type' (aka 'mpl_::assert<false>') for 1st argument
int assertion_failed( typename assert<C>::type );
    ^
In file included from main.cpp:8:
In file included from /opt/local/include/boost/geometry/algorithms/correct.hpp:23:
In file included from /opt/local/include/boost/range.hpp:26:
In file included from /opt/local/include/boost/range/functions.hpp:18:
In file included from /opt/local/include/boost/range/begin.hpp:24:
In file included from /opt/local/include/boost/range/iterator.hpp:23:
/opt/local/include/boost/mpl/eval_if.hpp:60:26: error: no type named 'type' in 'boost::range_const_iterator<int>'
    typedef typename f_::type type;
            ~~~~~~~~~~~~~^~~~
/opt/local/include/boost/range/iterator.hpp:61:18: note: in instantiation of template class 'boost::mpl::eval_if_c<true, boost::range_const_iterator<int>, boost::range_mutable_iterator<const int> >' requested here
            mpl::eval_if_c< is_const<C>::value,
                 ^
/opt/local/include/boost/geometry/views/identity_view.hpp:38:29: note: in instantiation of template class 'boost::range_iterator<const int>' requested here
    typedef typename boost::range_iterator<Range const>::type const_iterator;
                            ^
/opt/local/include/boost/range/const_iterator.hpp:36:9: note: in instantiation of template class 'boost::geometry::identity_view<const int>' requested here
        BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( const_iterator )
        ^
/opt/local/include/boost/range/detail/extract_optional_type.hpp:45:82: note: expanded from macro 'BOOST_RANGE_EXTRACT_OPTIONAL_TYPE'
    , BOOST_DEDUCED_TYPENAME boost::range_detail::exists< BOOST_DEDUCED_TYPENAME C::a_typedef >::type \
                                                                                 ^
/opt/local/include/boost/range/const_iterator.hpp:36:9: note: during template argument deduction for class template partial specialization 'extract_const_iterator<type-parameter-0-0, typename exists<typename type-parameter-0-0::const_iterator>::type>' [with C = boost::geometry::identity_view<const int>]
        BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( const_iterator )
        ^
/opt/local/include/boost/range/detail/extract_optional_type.hpp:44:12: note: expanded from macro 'BOOST_RANGE_EXTRACT_OPTIONAL_TYPE'
    struct extract_ ## a_typedef< C                                            \
           ^
<scratch space>:16:1: note: expanded from here
extract_const_iterator
^
/opt/local/include/boost/mpl/eval_if.hpp:60:22: note: in instantiation of template class 'boost::range_const_iterator<boost::geometry::identity_view<const int> >' requested here
    typedef typename f_::type type;
                     ^
/opt/local/include/boost/range/iterator.hpp:61:18: note: (skipping 7 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
            mpl::eval_if_c< is_const<C>::value,
                 ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:159:54: note: in instantiation of member function 'boost::geometry::detail::disjoint::disjoint_linear<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
        if (! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2))
                                                     ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:261:16: note: in instantiation of member function 'boost::geometry::detail::disjoint::general_areal<boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator> >::apply' requested here
            >::apply(g2, g1);
               ^
/opt/local/include/boost/geometry/algorithms/disjoint.hpp:344:54: note: in instantiation of member function 'boost::geometry::dispatch::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> >, 2, boost::geometry::ring_tag, boost::geometry::segment_tag, true>::apply' requested here
    return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2);
                                                     ^
/opt/local/include/boost/geometry/algorithms/intersects.hpp:99:14: note: in instantiation of function template specialization 'boost::geometry::disjoint<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
    return ! geometry::disjoint(geometry1, geometry2);
             ^
main.cpp:49:52: note: in instantiation of function template specialization 'boost::geometry::intersects<boost::geometry::model::ring<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>, true, true, std::vector, std::allocator>, boost::geometry::model::segment<boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> > >' requested here
  std::cout << "Polygon and segment intersect " << bg::intersects(poly1,s1) << std::endl;
                                                   ^
In file included from main.cpp:8:
In file included from /opt/local/include/boost/geometry/algorithms/correct.hpp:23:
In file included from /opt/local/include/boost/range.hpp:26:
In file included from /opt/local/include/boost/range/functions.hpp:18:
In file included from /opt/local/include/boost/range/begin.hpp:24:
In file included from /opt/local/include/boost/range/iterator.hpp:23:
/opt/local/include/boost/mpl/eval_if.hpp:60:26: error: no type named 'type' in 'boost::range_const_iterator<boost::geometry::identity_view<const int> >'
    typedef typename f_::type type;
            ~~~~~~~~~~~~~^~~~
/opt/local/include/boost/range/iterator.hpp:61:18: note: in instantiation of template class 'boost::mpl::eval_if_c<true, boost::range_const_iterator<boost::geometry::identity_view<const int> >, boost::range_mutable_iterator<const boost::geometry::identity_view<const int> > >' requested here
            mpl::eval_if_c< is_const<C>::value,
                 ^
/opt/local/include/boost/geometry/algorithms/detail/overlay/get_turns.hpp:124:29: note: in instantiation of template class 'boost::range_iterator<const boost::geometry::identity_view<const int> >' requested here
    typedef typename boost::range_iterator
                            ^
...

8 errors generated.
make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

Is that a bug or am I forgetting something? 那是一个错误还是我忘记了什么?

This question is a bit old but the other answer wasn't great. 这个问题有点老了,但另一个答案并不好。 My solution is to convert them both to line strings and then find out if they intersect (if you think about it the result should be the same, but it won't work for intersection) 我的解决方案是将它们都转换为线串,然后找出它们是否相交(如果您考虑过,结果应该是相同的,但不适用于相交)

#include <boost/geometry/algorithms/correct.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <iostream>

namespace bg = boost::geometry;

int main(int argc, char** argv) {
  typedef bg::model::point<double, 2, bg::cs::cartesian> Point;
  typedef bg::model::linestring<Point> linestring;
  bg::model::ring<Point> poly1, poly2;
  bg::model::segment<Point> s1, s2; 

  bg::read_wkt("POLYGON((0.0 0.0, 1.0 1.0, 0.0 2.0, 2.0 1.0))", poly1);
  bg::correct(poly1);

  bg::read_wkt("POLYGON((1.5 0.0, 1.5 2.0, 3.0 1.0))", poly2);
  bg::correct(poly2);

  bg::read_wkt("SEGMENT(0.0 0.0,0.0 2.0)", s1);
  bg::read_wkt("SEGMENT(-1.0 1.0,2.0 1.0)", s2);

  std::cout << "Polygons intersect " << bg::intersects(poly1, poly2) << std::endl;
  std::cout << "Segments intersect " << bg::intersects(s1, s2) << std::endl;
  std::vector<Point> v{s1.first,s1.second};
  std::cout << "Polygon and segment intersect " << bg::intersects(linestring(poly1.begin(),poly1.end()), linestring(v.begin(),v.end())) << std::endl;

  return 0;
}

It seems your thought that "maybe they didn't implement it for all possible pairs" is indeed the issue. 您似乎认为“也许他们没有对所有可能的对都实施”确实是问题所在。 boost::geometry::intersects calls boost::geometry::disjoint under the hood, and there are indeed template specializations for testing disjoint with different model types, including Segment + Box and Linestring + Box , but there does not appear to be one for Segment + Ring (though there is also one for Linestring + Segment , and though the templates are a bit tricky to walk through there does appear to be a middleman template that will switch the order of type parameters around to match, which means if you're having an issue with those two there might be some deeper issue). boost::geometry::intersects在引擎盖下调用boost::geometry::disjoint ,确实存在模板专业化,用于测试不同模型类型(包括Segment + BoxLinestring + Box不相交,但似乎并没有一个对于Segment + Ring (尽管Linestring + Segment也有一个),尽管模板有些棘手,但似乎确实存在一个中间人模板,该模板将切换类型参数的顺序以匹配它们,这意味着如果您这两个人可能有更深层次的问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM