Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split() with polygon and linestring adds area outside of original polygon #1988

Open
valgarf opened this issue Feb 12, 2024 · 1 comment
Open

Comments

@valgarf
Copy link

valgarf commented Feb 12, 2024

Expected behavior and actual behavior.

Expected split() to only split the input geometry, not add additional areas.

Steps to reproduce the problem.

from shapely import ops, wkt

poly = wkt.loads(
    "POLYGON ((570.1990000000001 972.8950000000001, 579.11 972.8950000000001, 579.11 1028.8950000000002, 581.61 1028.8950000000002, 581.61 1062.8950000000002, 1331.61 1062.8950000000002, 1331.61 1067.3900000000003, 2653.8999999999996 1067.39, 2653.9 425.9100000000003, 2679.8010000000004 425.9100000000003, 2679.8010000000004 -484.29599999999994, 920.1990000000001 -484.29599999999994, 920.1990000000001 42.70400000000001, 734.11 42.70400000000001, 734.11 112.11499999999998, 570.1990000000001 112.11499999999998, 570.1990000000001 524.895, 579.11 524.895, 579.11 580.895, 581.61 580.895, 581.61 614.895, 734.11 614.895, 734.11 727.1150000000001, 570.1990000000001 727.1150000000001, 570.1990000000001 972.8950000000001))"
)
line = wkt.loads(
    "LINESTRING (579.11 -640.4646, 579.11 1223.5586000000003, 581.61 1223.5586000000003, 581.61 -640.4646, 734.11 -640.4646, 734.11 1223.5586000000003, 920.1990000000001 1223.5586000000003, 920.1990000000001 -640.4646, 1331.61 -640.4646, 1331.61 1223.5586000000003, 2653.9 1223.5586000000003, 2653.9 -640.4646)"
)
result = ops.split(poly, line)
print(f"{poly.bounds[3]:0.2f}, {line.bounds[3]:0.2f}, {result.bounds[3]:0.2f}")

Output:
1067.39, 1223.56, 1223.56, i.e. the result has a larger bound than the input polygon.

Visualization:
additional_area
Green area is the original polygon, the red line is the splitter, and the violet area is not part of the original polygon but it is returned by the split function.

Operating system

Ubuntu 22.04

Shapely version and provenance

2.0.2 installed from PyPI

@valgarf
Copy link
Author

valgarf commented Feb 12, 2024

Some additional investigation: The split produces a really strange polygon.
Internally, split() uses representative_point() to get an internal point of the newly created polygon and uses that point to check if the new polygon belongs to the original one.

The strange polygon fails at producing a valid representative point:

poly = wkt.loads(
    "POLYGON ((2653.9 425.9100000000003, 2653.8999999999996 1067.39, 1331.61 1067.3900000000003, 1331.61 1223.5586000000003, 2653.9 1223.5586000000003, 2653.9 425.9100000000003))"
)
rp = poly.representative_point()
print(poly.covers(rp)) # prints "False"

The polygon is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant