1

ブースト ジオメトリを介してすべての個々のポリゴンの結合を取得しようとしています。しかし、奇妙なことに、Windows と centOS の間で結果が異なるようです。

結果は、Windowsでは正しいもの(私が期待するもの)になりますが、Linuxでは奇妙です。Linux では、結果が 2 つの分割ポリゴンとして表示されます。

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";

}
4

2 に答える 2

0

同じバージョンのブーストを使用していない可能性があります。

比較:

multi_polygonこれは、ヘッダーさえある Boost の最も初期のバージョンです。

質問から正確な出力を取得できるかどうかを確認するために、さらにいくつかの組み合わせ(たとえば、と-ffast-math)を試しましたが、それを再現するにはさらに情報(バージョンとフラグ)が必要だと思います。

上場

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/multi_polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <iostream>
#include <vector>
namespace bg = boost::geometry;
namespace bgm = bg::model;

using Point     = bgm::d2::point_xy<double>;
using Polygon   = bgm::polygon<Point>;
using MultiPoly = bg::model::multi_polygon<Polygon>;

int main()
{
    auto check = [](auto name, auto& g) {
        if (std::string reason; !bg::is_valid(g, reason)) {
            std::cout << name << ": " << reason << "\n";
            bg::correct(g);
        }
    };

    Polygon one, two;
    bg::read_wkt("POLYGON((0 2996, 1490 2996, 1490 -0, 0 -0, 0 2996))", one);
    bg::read_wkt("POLYGON((1490 2996, 2980 2996, 2980 -0, 1490 -0, 1490 2996))", two);
    check("one", one);
    check("two", two);

    MultiPoly polyUnion;

    // Create the union of all the polygons of the datasets
    for (auto& p : {one, two}) {
        MultiPoly tmp;
        bg::union_(polyUnion, p, tmp);
        polyUnion = tmp;
    }

    check("polyUnion", polyUnion);

    std::cout << "polyUnion: " << bg::wkt(polyUnion) << "\n";
}
于 2021-11-13T17:11:04.457 に答える