我有自己的观点
class LocationWayPoint
{
public:
latlong_container location;
WORD index;
PWeakBasicStation station;
};
namespace boost { namespace geometry { namespace traits {
BOOST_GEOMETRY_DETAIL_SPECIALIZE_POINT_TRAITS(LocationWayPoint, 2, double, cs::cartesian)
template<> struct access<LocationWayPoint, 0> {
static inline double get(LocationWayPoint const& p) {return p.location.longitude; }
static inline void set(LocationWayPoint& p, double const& value) {p.location.longitude = value; }
};
template<> struct access<LocationWayPoint, 1> {
static inline double get(LocationWayPoint const& p) {return p.location.latitude; }
static inline void set(LocationWayPoint& p, double const& value) {p.location.latitude = value; }
};
}}}
typedef bg::model::linestring<LocationWayPoint> location_linestring_t;
...
location_linestring_t ls1;
我像这样完成这一点(循环中)
LocationWayPoint point;
/* point.index = counter; */
point.index = 7777;
point.location.longitude = (lo_type == mongo::NumberDouble) ? point_record.getField("lo").Double() : std::atof(point_record.getField("lo").String().c_str());
point.location.latitude = (lo_type == mongo::NumberDouble) ? point_record.getField("lat").Double() : std::atof(point_record.getField("lat").String().c_str());
ls1.push_back(point);
当我使用 ls1.push_back(point); 时我可以访问索引值
LOG4CPLUS_DEBUG(logger, "LocationWay::LoaderWay in " << bg::get<0>(ls1[0]) << " d2 " << bg::get<1>(ls1[0]) << " index "<< ls1[0].index);
out = DEBUG - LocationWay::LoaderWay in xxx d2 xxx index 7777
但是当我调用替换push_back方法时
bg::append(ls1, point);
我明白了
DEBUG - LocationWay::LoaderWay in xxx d2 xxx index 17 <--uninit value
当我调用 bg::buffer 时
boost::geometry::model::multi_polygon<location_polygon_t> result;
boost::geometry::buffer(ls1, result,
distance_strategy, side_strategy,
join_strategy, end_strategy, circle_strategy);
任何没有位置的值设置为未初始化(
最佳答案
我认为您已经直接诊断了问题:使用算法“丢失”附加的外部信息,原因很简单,创建的点是新点。
顺便说一句,这是初始化所有成员数据的一个很好的理由 - 即使在 POD 结构中也是如此。
因此,您的问题似乎是假设,即缓冲区算法以某种方式保留原始点 - 只是移动它们并保留其余的包含值。这个假设不正确。
我可以推测原因:也许是为了适应使用共享点/几何图形和(因此?)不可变数据的自定义几何模型。
文档支持
文档没有直接描述这个(作为一个)限制。但这是关键点:它没有描述任何允许/处理无关数据的点概念,这是该库不处理的明确标志。这是Point Concept ,例如:
请注意它确实如何具有traits::access
,但它没有克隆点的概念(以包含无关数据?)。
关于c++ - boost 缓冲区调用后丢失自定义点类型的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46676309/