PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Postgis + boost::geometry + C++

Ich bezweifle, dass Sie für diesen Vorgang PostGIS benötigen.

Ich bezweifle auch, dass es einen Weg gibt, "es gültig zu machen". Weil das Polygon einen klaren Selbstschnittpunkt hat:

So führen Sie die Validierung und Korrektur in Boost Geometry selbst durch:

Live auf Coliru

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/io/io.hpp>
#include <boost/geometry/algorithms/equals.hpp>
#include <iostream>

namespace bg = boost::geometry;
namespace bgm = boost::geometry::model;

template<typename G>
bool check(G const& g) {
    std::string reason;
    bool valid = bg::is_valid(g, reason);

    if (valid) std::cout << "Valid (dsv): " << bg::dsv(g) << "\n";
    else       std::cout << "Invalid: " << reason << "\n";

    return valid;
}

int main() {
    using pt = bgm::d2::point_xy<double>;
    using poly = bgm::polygon<pt>;

    poly p;
    bg::read_wkt("POLYGON((0 0, 10 0, 10 11, 11 10, 0 10))", p);

    while (!check(p)) {
        auto same = p;
        bg::correct(p);

        if (bg::equals(p, same)) {
            std::cout << "Out of ideas\n";
            break;
        }
    }
}

Beachten Sie die Ausgabe:

Invalid: Geometry is defined as closed but is open
Invalid: Geometry has invalid self-intersections. A self-intersection point was found at (10, 10); method: i; operations: u/i; segment IDs {source, multi, ring, segment}: {0, -1, -1, 1}/{0, -1, -1, 3}
Out of ideas

Wenn Ihre Quelle tatsächlich solche Selbstüberschneidungen enthält, ist es schwer zu sagen, was Sie möchten. Vielleicht möchten Sie sich

ansehen