Skip to content

Conversation

@yutannihilation
Copy link
Contributor

This pull request implements ST_LineMerge.

https://postgis.net/docs/en/ST_LineMerge.html

This is mostly straightforward using GEOS's LineMerge via the geos crate. One thing to note is that, the direction-aware version (.line_merge_directed()) requires GEOS >= v3.11, which was released 3.5 years ago. I don't think this is a difficult requirement, but I'm not really sure.

https://github.com/georust/geos/blob/47afbad2483e489911ddb456417808340e9342c3/src/geometry.rs#L2796-L2802

> SELECT ST_LineMerge(ST_GeomFromWKT('MULTILINESTRING ((0 0, 1 0), (1 0, 1 1))'));
┌────────────────────────────────────────────────────────────────────────────────┐
│ st_linemerge(st_geomfromwkt(Utf8("MULTILINESTRING ((0 0, 1 0), (1 0, 1 1))"))) │
│                                    geometry                                    │
╞════════════════════════════════════════════════════════════════════════════════╡
│ LINESTRING(0 0,1 0,1 1)                                                        │
└────────────────────────────────────────────────────────────────────────────────┘

@yutannihilation yutannihilation marked this pull request as ready for review January 10, 2026 07:45
Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Did you want to add a Python integration test for this here? (I can also file a follow-up issue so we don't forget)

Comment on lines +1814 to +1818
# Note that the behaviour on non-multilinestring geometry is not documented.
# But, we test such cases here as well to detect if there's any difference.
("POINT (0 0)", "GEOMETRYCOLLECTION EMPTY"),
("LINESTRING (0 0, 1 0)", "LINESTRING (0 0, 1 0)"),
("POLYGON ((0 0, 0 1, 1 0, 0 0))", "LINESTRING (0 0, 0 1, 1 0, 0 0)"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. The docs say "Other geometry types return an empty GeometryCollection" in the note. Though that doesn't seem to be the case for POLYGON or LINESTRING input 🤷.

Could we test some empty geometries, for both of these tests? Those can often catch weird edge cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching. I simply didn't notice the note...

I'll add empty cases.

@yutannihilation
Copy link
Contributor Author

Did you want to add a Python integration test for this here?

Do you mean benchmark tests? I just forgot to do so, but now I don't immediately see how to add tests as it probably requires specific inputs of touching line segments.

Copy link
Collaborator

@petern48 petern48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I will leave this for @paleolimbot to clarify what he meant and answer this: #503 (comment), given there were python integration tests already).

Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to note is that, the direction-aware version (.line_merge_directed()) requires GEOS >= v3.11

I think our current minimum is 3.12 (for M coordinates), so this is no problem. We could try harder to support older GEOS with some feature flags or defines if this comes up.

Did you want to add a Python integration test for this here?

That was just me reviewing too fast 🤦 . Sorry!

@paleolimbot paleolimbot merged commit c259361 into apache:main Jan 11, 2026
15 checks passed
@yutannihilation
Copy link
Contributor Author

I see. Thanks for clarifying!

@yutannihilation yutannihilation deleted the feat/st_linemerge branch January 11, 2026 02:42
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

Successfully merging this pull request may close these issues.

3 participants