Discussion:
[Boost-users] [geometry] Cannot compile boost::geometry::intersection
Stanley Friesen
2016-11-16 18:40:07 UTC
Permalink
I am using boost library version 1.54 with gcc --std=c++11.

I am trying a simple use of geometry::intersection as follows:

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon.hpp>

using namespace boost::geometry;
......
typedef model::d2::point_xy<double> point_xy;
model::polygon<point_xy> clipBounds;
// add points to clipBounds
model::polygon<point_xy> area;
// add points to area
model::polygon<point_xy> result;
if(boost::geometry::intersection(area, clipBounds, result))
{
std::cout << std::endl << "Boost intersection, size = " <<
num_points(result) << std::endl;
}

If I comment out the call to intersection, everything compiles. With it I
get:
In file included from /usr/include/boost/serialization/level.hpp:28:0,
from /usr/include/boost/serialization/nvp.hpp:31,
from ...:
/usr/include/boost/mpl/eval_if.hpp: In instantiation of ‘struct
boost::mpl::eval_if_c<false,
boost::range_const_iterator&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> > >,
boost::range_mutable_iterator<boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> > > >’:
/usr/include/boost/range/iterator.hpp:63:63: required from ‘struct
boost::range_iterator<boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> > >’
/usr/include/boost/range/value_type.hpp:30:12: required from ‘struct
boost::range_value<boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> > >’
/usr/include/boost/geometry/algorithms/intersection.hpp:97:64: required
from ‘static bool boost::geometry::dispatch::intersection<Geometry1,
Geometry2, Tag1, Tag2, Reverse>::apply(const Geometry1&, const Geometry2&,
GeometryOut&, const Strategy&) [with GeometryOut =
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> >; Strategy =
boost::geometry::strategy_intersection<boost::geometry::cartesian_tag,
boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> >,
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> >,
boost::geometry::model::d2::point_xy<double,
boost::geometry::cs::cartesian>, void>; Geometry1 =
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> >; Geometry2 =
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> >; Tag1 = boost::geometry::polygon_tag; Tag2
= boost::geometry::polygon_tag; bool Reverse = false]’
/usr/include/boost/geometry/algorithms/intersection.hpp:201:67: required
from ‘bool boost::geometry::intersection(const Geometry1&, const Geometry2&,
GeometryOut&) [with Geometry1 =
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> >; Geometry2 =
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> >; GeometryOut =
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> >]’
/home/stanley/workspace/worldmodel/metric/map/GISCache.cpp:2492:62:
required from here
/usr/include/boost/mpl/eval_if.hpp:60:31: error: no type named ‘type’ in
‘boost::mpl::eval_if_c<false,
boost::range_const_iterator&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> > >,
boost::range_mutable_iterator<boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> > > >::f_ {aka struct
boost::range_mutable_iterator<boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> > >}’
typedef typename f_::type type;

Since my code is virtually identical to the sample code in the
documentation, I am very puzzled by this. What have I missed? How do I get
this to compile?

(I do find it odd that this error refers to boost/serialization rather than
boost/geometry, but I suppose that has to do with the order of inclusion).




--
View this message in context: http://boost.2283326.n4.nabble.com/geometry-Cannot-compile-boost-geometry-intersection-tp4689954.html
Sent from the Boost - Users mailing list archive at Nabble.com.
Barend Gehrels
2016-11-16 21:07:29 UTC
Permalink
Hi Stanley,
Post by Stanley Friesen
I am using boost library version 1.54 with gcc --std=c++11.
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_polygon.hpp>
using namespace boost::geometry;
......
typedef model::d2::point_xy<double> point_xy;
model::polygon<point_xy> clipBounds;
// add points to clipBounds
model::polygon<point_xy> area;
// add points to area
model::polygon<point_xy> result;
if(boost::geometry::intersection(area, clipBounds, result))
{
std::cout << std::endl << "Boost intersection, size = " <<
num_points(result) << std::endl;
}
If I comment out the call to intersection, everything compiles. With it I
In file included from /usr/include/boost/serialization/level.hpp:28:0,
from /usr/include/boost/serialization/nvp.hpp:31,
/usr/include/boost/mpl/eval_if.hpp: In instantiation of ‘struct
boost::mpl::eval_if_c<false,
boost::range_const_iterator&lt;boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
boost::geometry::cs::cartesian> > >,
boost::range_mutable_iterator<boost::geometry::model::polygon&lt;boost::geometry::model::d2::point_xy&lt;double,
[...]
Since my code is virtually identical to the sample code in the
documentation, I am very puzzled by this. What have I missed? How do I get
this to compile?
(I do find it odd that this error refers to boost/serialization rather than
boost/geometry, but I suppose that has to do with the order of inclusion).
Yes, it is odd that it refers to boost/serialization - we don't include
that in Boost.Geometry. So how does it come there? Is your include list
accurate?

Do you need the Boost.Polygon adaptation? Apparently you don't need it
so it can be omitted, but I doubt if that is relevant.

Anyway, I think that the error is here:

model::polygon<point_xy> result;

But Intersection needs to output to a vector of polygons, or a
multi-polygon (that must be like that in the documentation...)

Regards, Barend
Stanley Friesen
2016-11-16 22:02:04 UTC
Permalink
The reference to boost/serialization comes about since the module in question
also makes use of a logging facility that uses boost serialization for
output, and the include file for the logger is before the include files for
geometry.

Thanks for the answer, I will try that and see if it works. In fact I had
completely forgotten that an intersection can generate disjoint pieces,
since most of the data I have doesn't do that. (We are parceling map areas
onto a rectangular grid, the clip bound is the current rectangle boundary,
and the area is the map data).




--
View this message in context: http://boost.2283326.n4.nabble.com/geometry-Cannot-compile-boost-geometry-intersection-tp4689954p4689960.html
Sent from the Boost - Users mailing list archive at Nabble.com.
Barend Gehrels
2016-11-17 11:03:32 UTC
Permalink
Hi Stanley,
Post by Stanley Friesen
The reference to boost/serialization comes about since the module in question
also makes use of a logging facility that uses boost serialization for
output, and the include file for the logger is before the include files for
geometry.
In the meantime I noticed that we depend on ublas for some matrix
operations and ublas depends on serialization, so it is there anyway.
Post by Stanley Friesen
Thanks for the answer, I will try that and see if it works. In fact I had
completely forgotten that an intersection can generate disjoint pieces,
since most of the data I have doesn't do that. (We are parceling map areas
onto a rectangular grid, the clip bound is the current rectangle boundary,
and the area is the map data).
Regards, Barend
Stanley Friesen
2016-11-17 15:56:21 UTC
Permalink
Well, the good news is that it now compiles and runs correctly. However, I
now discovered my downstream code does not handle disjoint regions properly.
But that is not a Boost issue, so this thread is resolved.



--
View this message in context: http://boost.2283326.n4.nabble.com/geometry-Cannot-compile-boost-geometry-intersection-tp4689954p4689967.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Loading...