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

BUG: The union_all feature generates an unexpected result #2028

Open
thomas-leduc opened this issue Mar 25, 2024 · 1 comment
Open

BUG: The union_all feature generates an unexpected result #2028

thomas-leduc opened this issue Mar 25, 2024 · 1 comment
Labels

Comments

@thomas-leduc
Copy link

Please note

Expected behavior and actual behavior.

The union_all feature produces a MultiLineString with not 2 but 3 LineStrings.

Steps to reproduce the problem.

from shapely import LineString, union_all

geoms = [
	LineString([ (355041.15, 6688781.25, 0), (355040.9629213488, 6688781.437078651, 9.7) ]),
	LineString([ (355041.1500000001, 6688781.25, 0), (354841.1500000001, 6688781.25, 0) ])
]

result = union_all(geoms)

assert len(result.geoms) == len(geoms), "Bug"

Operating system

Ubuntu 22.04.4 LTS (x86_64)

Shapely version and provenance

2.0.3

@theroggy
Copy link
Contributor

theroggy commented Mar 26, 2024

I think your code sample isn't ideal, as the lines don't have a common point, but you are right anyway that union_all doesn't union/merge lines.

Not sure why this is split up (I asked if it is intentional here libgeos/geos#1063), but to union/merge lines you need to use shapely.line_merge:

from shapely import LineString, MultiLineString, line_merge, union_all

geoms = [
	LineString([ (355041.15, 6688781.25, 0), (355040.9629213488, 6688781.437078651, 9.7) ]),
	LineString([ (355041.15, 6688781.25, 0), (354841.1500000001, 6688781.25, 0) ])
]

line_merge_result = line_merge(MultiLineString(geoms))
print(line_merge_result)
# LINESTRING Z (354841.1500000001 6688781.25 0, 355041.15 6688781.25 0, 355040.9629213488 6688781.437078651 9.7)

union_all_result = union_all(geoms)
print(union_all_result)
# MULTILINESTRING Z ((355041.15 6688781.25 0, 355040.9629213488 6688781.437078651 9.7), (355041.15 6688781.25 0, 354841.1500000001 6688781.25 0))

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

No branches or pull requests

3 participants