|
Geometry : |
Subject: [geometry] Integrating OGR library with Boost.Geometry
From: Eric MSP Veith (eveith_at_[hidden])
Date: 2015-01-07 12:34:56
[ Disclaimer: This is a cross-post; a similar question has been posted on
stackoverflow.com: <http://stackoverflow.com/questions/27767656/how-to-register-a-boost-geometry-distance-strategy-for-ogrpoint-and-ogrlinestrin> ]
Hello list!
I am a first-time user of Boost.Geometry. My goal is to use Boost.Geometry's
rtree implementation with OGRGeometry instances [0]. To that end, I've adapted
the necessary OGR classes (OGRPoint, OGRLineString, OGRLinearRing and
OGRPolygon) to Boost.Geometry's model. Iterating, etc. works good.
However, the current version of Boost.Geometry has no support for different
map projections, which is why I'm forced to stick with OGRGeometry in general.
Also, the existing codebase makes heavy use of the OGR* interfaces.
What I am looking for is to use Boost.Geometry's tag/dispatch feature to call
OGRGeometry::Distance() whenever I (or rtree) uses bg::distance(),
OGRGeometry::Crosses() when bg::crosses() is used, and so an. Basically, the
Boost.Geometry predicates are then nothing more than wrappers around the
corresponding OGR* counterparts.
I've begun with bg::distance for OGRPoint to OGRPoint, and it worked. However,
I'm stuck with bg::distance(OGRPoint &, OGRLineString &), with a compile
error. My guess is that it stems from Boost.Geometry's concept of a
linestring, which is nothing more than an ordered collection of points.
Is there any kind of template specialisation I can use so that a call to
bg::distance(OGRGeometry const&, OGRGeometry const&) is dispatched to
OGRGeometry::Distance(...)?
What follows is the template instanciation that makes me believe that my
dispatching does not work due to a Boost.Geometry linestring being a
collection of points, the full error message, and my current code:
---%<---
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>
--->%---
The full error message is:
--->%---
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
---%<---
And this is my current attempt on a distance strategy:
---%<---
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
--->%---
Thanks a lot in advance for any hints!
Kind Regards,
Eric
[0] http://www.gdal.org/classOGRGeometry.html
Geometry list run by mateusz at loskot.net