boost::geometry::model::linestring与boost:的交集:geometry::model
Intersection of boost::geometry::model::linestring with boost::geometry::model::polygon
我正试图找到位于多边形内部的行字符串部分。我尝试了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;
}
似乎必须使用multi_linestring作为输出类型:
#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/multi/geometries/multi_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>;
using multi_linestring_type = boost::geometry::model::multi_linestring<linestring_type>;
int main()
{
polygon_type polygon;
polygon.outer().push_back(point_type{10,10});
polygon.outer().push_back(point_type{10,12});
polygon.outer().push_back(point_type{12,12});
polygon.outer().push_back(point_type{12,10});
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)
multi_linestring_type intersection;
boost::geometry::intersection(polygon, linestring, intersection);
for(auto intersectionIter = intersection.begin(); intersectionIter != intersection.end(); ++intersectionIter) {
linestring_type intersectionPiece = *intersectionIter;
std::cout << "Piece:" << std::endl;
for(auto intersectionPieceIter = intersectionPiece.begin(); intersectionPieceIter != intersectionPiece.end(); ++intersectionPieceIter) {
std::cout << boost::geometry::get<0>(*intersectionPieceIter) << " " << boost::geometry::get<1>(*intersectionPieceIter) << std::endl;
}
}
return 0;
}
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- 为什么 boost::geometry::d istance 使用 model::d 2::p oint_xy<float> 返回双精度而不是浮点数?
- 从 2D C 列表创建 boost.geometry.model.polygon
- 需要帮助理解 Boost.Atomic Memory Model 'memory_order_release' 示例
- boost::geometry::model::模板点类型的分段构造函数
- 如何从boost::geometry::model::point继承
- 无法构建 Boost 1.59 错误:功能 "deduced-address-model" : "32" "64" : "propagated" "optional" "composite" "hid
- 如何从svg读取boost::geometry::model::polygon
- boost::geometry::model::linestring与boost:的交集:geometry::model