我试图找到多边形内部的线串部分。我尝试了intersection
函数,但它似乎只是找到实际的交点,而不是与多边形重叠的线串部分。有没有办法得到这个对象?
以下是演示情况:
#include <iostream>
#include <fstream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/svg/svg_mapper.hpp>
#include <boost/geometry/geometries/linestring.hpp>
using point_type = boost::geometry::model::d2::point_xy<double>;
using polygon_type = boost::geometry::model::polygon<point_type>;
using linestring_type = boost::geometry::model::linestring<point_type>;
int main()
{
polygon_type polygon;
polygon.outer().push_back(point_type{10,10});
polygon.outer().push_back(point_type{12,10});
polygon.outer().push_back(point_type{12,12});
polygon.outer().push_back(point_type{10,12});
polygon.outer().push_back(point_type{10,10});
linestring_type linestring;
linestring.push_back(point_type{11,9});
linestring.push_back(point_type{11,11});
linestring.push_back(point_type{13,11});
// Expected intersections at (11, 10) and (12, 11)
std::ofstream svg("both.svg");
linestring_type output;
boost::geometry::intersection(polygon, linestring, output);
for(auto iter = output.begin(); iter != output.end(); ++iter) {
std::cout << boost::geometry::get<0>(*iter) << " " << boost::geometry::get<1>(*iter) << std::endl;
}
// The output is:
// 11 10
// 12 11
// But I want it to be:
// 11 10
// 11 11
// 12 11
return 0;
}
答案 0 :(得分:3)
您似乎必须使用multi_linestring作为输出类型:
small.ints <- to.dfs(1:1000)
out <- from.dfs(small.ints)
out