union_ of two valid polygons sharing an edge returns empty (argument order dependent)

オープン
#1,506 コメント 1 件 リアクション 1 件 担当者 1 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@barendgehrels がすでに取り組んでいます。

2026年11月6日 から。

  • #1507 @barendgehrels による — オープン

評価

この issue はまだ評価されていません。

説明

Two valid, non-overlapping cartesian polygons that share one edge. union_(a, b) and union_(b, a) should both return one polygon with area(a) + area(b). With union_(b, a) the result is empty on all versions I tried, including develop.

The vertices of a along the shared side are nearly collinear (the shared edge lies on a line through three of them). The data comes from a land cover coverage after ST_CoverageSimplify (GEOS); GEOS computes the union correctly.

#include <boost/geometry.hpp>
#include <iostream>
namespace bg = boost::geometry;
typedef bg::model::d2::point_xy<double> Point;
typedef bg::model::polygon<Point> Polygon;
typedef bg::model::multi_polygon<Polygon> MultiPolygon;

int main() {
    MultiPolygon a, b, u1, u2;
    bg::read_wkt("MULTIPOLYGON(((7.5766965679702691 55.1955384390566266,7.5769710638206007 55.1955418668735760,"
                 "7.5776907371234223 55.1955508539257096,7.5777041477885838 55.1955510213938609,"
                 "7.5724506758568699 55.1833987553893692,7.5766965679702691 55.1955384390566266)))", a);
    bg::read_wkt("MULTIPOLYGON(((7.5776907371234223 55.1955508539257096,7.5769710638206007 55.1955418668735760,"
                 "7.5786734102424926 55.1979584470965179,7.5776907371234223 55.1955508539257096)))", b);
    bg::correct(a); bg::correct(b);
    bg::union_(a, b, u1);
    bg::union_(b, a, u2);
    std::cout << "valid " << bg::is_valid(a) << bg::is_valid(b)
              << ", area a+b " << bg::area(a) + bg::area(b)
              << ", union(a,b) " << u1.size() << " polygon(s) area " << bg::area(u1)
              << ", union(b,a) " << u2.size() << " polygon(s) area " << bg::area(u2) << "\n";
}
Boost.Geometry union(a, b) union(b, a)
1.83 1 polygon, area of a only (b dropped) empty
1.83 with BOOST_GEOMETRY_USE_RESCALING correct correct
1.87 b dropped empty
1.89, 1.92 correct empty
develop (fd21a751b2, 2026-11-04) correct empty

Expected area: 6.951063106e-06 (a: 6.089138509e-06, b: 8.619245973e-07, intersection area 0).
Compiled with g++ 14.2, -O2 -std=c++17 (newer versions: Boost.Geometry and Boost.Core headers of that tag, rest of Boost 1.83).

Context: tilemaker combines adjacent polygons of the same class with union_ (binary reduction). On a land cover coverage this drops whole polygons; on OpenStreetMap land use data it happens rarely (2 cases in an extract of Denmark).

主要言語
C++
スター
519
フォーク
241
平均マージ
4日 15時間
マージ済み PR(30日)
9

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/geometry のほかの issue

boostorg/geometry の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。