我正在尝试通过增强几何来合并所有单个多边形。但奇怪的是,结果似乎在 windows 和 centOS 之间有所不同。
结果在 Windows 中是正确的(我期望的),但在 linux 中很奇怪。在 linux 中,它将结果显示为两个分割的多边形。
在 Windows 中我得到
MULTIPOLYGON(((0 -0,0 2996,1490 2996,2980 2996,2980 -0,0 -0)))
但在 centOS 相同的一组输入中,给出的结果为
MULTIPOLYGON(((1490 2996,2980 2996,2980 -0,1490 -0,1490 2996)),((0 2996,1490 2996,1490 -0,0 -0,0 2996)))
这让我感到莫名其妙,因为尝试计算多边形联合的代码是相同的。我不明白为什么 linux 输出在多边形之间出现分割线。这不是联合输出应有的样子。
谁能指出我在下面的代码中做错了什么?或任何其他我可以尝试查看问题所在的指针。
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
namespace boost {
namespace geometry {
typedef model::d2::point_xy<double> Point;
typedef model::polygon<Point> Polygon;
typedef model::segment<Point> Line;
};
};
int main()
{
using multi_polygon = boost::geometry::model::multi_polygon<boost::geometry::Polygon>;
boost::geometry::Polygon one, two,green;
boost::geometry::read_wkt("POLYGON((0 2996, 1490 2996, 1490 -0, 0 -0, 0 2996))", one);
boost::geometry::read_wkt("POLYGON((1490 2996, 2980 2996, 2980 -0, 1490 -0, 1490 2996))", two);
multi_polygon polyUnion;
std::vector<boost::geometry::Polygon> vectorOfPolygons;
vectorOfPolygons.emplace_back(one);
vectorOfPolygons.emplace_back(two);
// Create the union of all the polygons of the datasets
for (const boost::geometry::Polygon& p : vectorOfPolygons) {
multi_polygon tmp;
boost::geometry::union_(polyUnion, p, tmp);
polyUnion = tmp;
boost::geometry::clear(tmp);
}
std::string str;
bool valid = boost::geometry::is_valid(polyUnion, str);
if (!valid)
{
boost::geometry::correct(polyUnion);
}
std::cout << "Result of union" << boost::geometry::wkt(polyUnion) << "\n";
}