我正在创建一个包装器,允许使用带有Boost.Geometry的OGR类。到目前为止,我已经创建了必要的迭代器外观,并使用Boost.Geometry注册了OGR的几何类(OGRPoint
,OGRLineString
,OGRLinearRing
和OGRPolygon
)。
现在,我想使用带有boost的OGRGeometry::Distance()
等OGR类谓词而不是Boost.Geometry使用的谓词(因为,例如,股票Boost.Geometry 1.57.0没有任何概念地图投影)。它适用于boost::geometry::distance(OGRPoint, OGRPoint)
,但不适用于bg::distance(OGRPoint, OGRLineString)
或任何其他积分。我的猜测是因为Boost.Geometry将线串,环和多边形视为迭代的有序点集合,因为编译器试图实例化以下模板:
struct boost::geometry::strategy::distance::services::default_strategy<
boost::geometry::point_tag,
boost::geometry::segment_tag,
OGRPoint, // NOTE: Twice OGRPoint!
OGRPoint,
MyCode::OGRCoordinateSystemTag,
MyCode::OGRCoordinateSystemTag, void>
完整的错误消息如下:
In file included from /usr/include/boost/geometry/strategies/strategies.hpp:30:0,
from /usr/include/boost/geometry/geometry.hpp:43,
from /usr/include/boost/geometry.hpp:17,
from ../../../winzent/test/simulation/OGRLineStringAdapterTest.cpp:7:
/usr/include/boost/geometry/strategies/distance.hpp: In instantiation of 'struct boost::geometry::strategy::distance::services::default_strategy<boost::geometry::point_tag, boost::geometry::segment_tag, OGRPoint, OGRPoint, Winzent::Simulation::boost::OGRCoordinateSystemTag, Winzent::Simulation::boost::OGRCoordinateSystemTag, void>':
/usr/include/boost/geometry/algorithms/detail/distance/default_strategies.hpp:57:8: required from 'struct boost::geometry::detail::distance::default_strategy<OGRPoint, OGRLineString, boost::geometry::pointlike_tag, boost::geometry::linestring_tag, false>'
/usr/include/boost/geometry/algorithms/detail/distance/default_strategies.hpp:73:8: required from 'struct boost::geometry::detail::distance::default_strategy<OGRLineString, OGRPoint, boost::geometry::linestring_tag, boost::geometry::pointlike_tag, true>'
/usr/include/boost/geometry/strategies/distance_result.hpp:60:8: required from 'struct boost::geometry::resolve_strategy::distance_result<OGRLineString, OGRPoint, boost::geometry::default_strategy>'
/usr/include/boost/geometry/strategies/distance_result.hpp:79:8: required from 'struct boost::geometry::resolve_variant::distance_result<OGRLineString, OGRPoint, boost::geometry::default_strategy>'
/usr/include/boost/geometry/strategies/distance_result.hpp:199:8: required from 'struct boost::geometry::distance_result<OGRLineString, OGRPoint, boost::geometry::default_strategy>'
/usr/include/boost/geometry/strategies/distance_result.hpp:205:8: required from 'struct boost::geometry::distance_result<OGRLineString, OGRPoint, void>'
/usr/include/boost/geometry/strategies/default_distance_result.hpp:35:8: required from 'struct boost::geometry::default_distance_result<OGRLineString, OGRPoint>'
/usr/include/boost/geometry/algorithms/detail/distance/interface.hpp:392:1: required by substitution of 'template<class Geometry1, class Geometry2> typename boost::geometry::default_distance_result<Geometry1, Geometry2>::type boost::geometry::distance(const Geometry1&, const Geometry2&) [with Geometry1 = OGRLineString; Geometry2 = OGRPoint]'
../../../winzent/test/simulation/OGRLineStringAdapterTest.cpp:71:62: required from here
/usr/include/boost/geometry/strategies/distance.hpp:97:456: error: no matching function for call to 'assertion_failed(mpl_::failed************ (boost::geometry::strategy::distance::services::default_strategy<boost::geometry::point_tag, boost::geometry::segment_tag, OGRPoint, OGRPoint, Winzent::Simulation::boost::OGRCoordinateSystemTag, Winzent::Simulation::boost::OGRCoordinateSystemTag, void>::NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE_COMBINATION::************)(mpl_::assert_::types<OGRPoint, OGRPoint, Winzent::Simulation::boost::OGRCoordinateSystemTag, Winzent::Simulation::boost::OGRCoordinateSystemTag>))'
BOOST_MPL_ASSERT_MSG
所以我尝试专门为struct boost::geometry::detail::distance::default_strategy<OGRPoint, OGRLineString, boost::geometry::pointlike_tag, boost::geometry::linestring_tag, false>
提供模板专门化,但没有运气---相同的错误信息占优势。
这是我的代码:
namespace boost {
namespace geometry {
namespace detail {
namespace distance {
template <>
struct default_strategy<
OGRPoint,
OGRLineString,
pointlike_tag,
linestring_tag,
false>
{
typedef OGRPointToLineStringDistanceStrategy type;
};
} // namespace distance
} // namespace detail
} // namespace geometry
} // namespace boost
如何“拦截”导致使用迭代器/范围概念的模板实例并直接使用OGRGeometry::Distance()
?
答案 0 :(得分:1)
事实证明,问题与使用两种不同算法的OGR和Boost无关。相反,这是我的适配器代码应该责备。更具体地说,我编写的迭代器外观是为了使OGRLineString
,OGRLinearRing
和最终OGRPolygon
适应Boost.Geometry代码。我在发现问题后立即发布了一个问题:Create a well-behaved iterator for a write-to-pointer API。
我目前工作的(和最终版)版本以a GitHub project的形式提供。也许有人觉得它很有用。