Skip to content

Wrong intersection of polygon and linestring #1406

@vissarion

Description

@vissarion

The following code

#include <iostream>
#include <vector>
#include <boost/geometry.hpp>

namespace bg = boost::geometry;

int main() {
    // Define the polygon
    bg::model::polygon<bg::model::d2::point_xy<double>> polygon;
    bg::read_wkt("POLYGON((1 1.5,3.5 4.5,4 6,2.5 4.5,1 1.5))", polygon);

    // Define the linestring
    bg::model::linestring<bg::model::d2::point_xy<double>> linestring;
    bg::read_wkt("LINESTRING(1.5 1.5,0.5 1.5)", linestring);

    // Compute the intersection
    std::tuple<
        bg::model::multi_point<bg::model::d2::point_xy<double>>,
        bg::model::multi_linestring<bg::model::linestring<bg::model::d2::point_xy<double>>>
    > output;
    bg::intersection(polygon, linestring, output);

    // Print the results
    auto linestrings = std::get<1>(output);
    auto points = std::get<0>(output);
    std::cout << "Intersection linestrings: " << bg::wkt(linestrings) << std::endl;
    std::cout << "Intersection points: " << bg::wkt(points) << std::endl;

    return 0;
}

Gives the following incorrect output:

Intersection linestrings: MULTILINESTRING((1 1.5,0.5 1.5))
Intersection points: MULTIPOINT()

on current develop with clang-15 on ubuntu 22.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions