-
Notifications
You must be signed in to change notification settings - Fork 755
Closed
Milestone
Description
Expected behavior
ST_LineMerge should return a LineString unchanged when given a single LineString as input, consistent with PostGIS and GEOS (GEOSLineMerge).
A single LineString is already "merged" — there is nothing to merge.
PostGIS / GEOS behavior
SELECT ST_AsText(ST_LineMerge('LINESTRING(0 0, 1 1)'));
-- Returns: LINESTRING(0 0, 1 1)>>> from shapely import line_merge
>>> from shapely.geometry import LineString
>>> line_merge(LineString([(0, 0), (1, 1)]))
<LINESTRING (0 0, 1 1)>Actual behavior
Sedona returns GEOMETRYCOLLECTION EMPTY for LineString input:
>>> df.selectExpr("ST_LineMerge(ST_GeomFromText('LINESTRING(0 0, 1 1)'))").show()
# Returns: GEOMETRYCOLLECTION EMPTYRoot cause
In Functions.java line 1198, lineMerge only handles MultiLineString and falls through to returning an empty GeometryCollection for all other types — including LineString:
public static Geometry lineMerge(Geometry geometry) {
if (geometry instanceof MultiLineString) {
// ... merge logic ...
}
return geometry.getFactory().createGeometryCollection(); // <-- LineString hits this
}Suggested fix
Add a check for LineString before the MultiLineString block:
public static Geometry lineMerge(Geometry geometry) {
if (geometry instanceof LineString) {
return geometry; // A single LineString is already merged
}
if (geometry instanceof MultiLineString) {
// ... existing merge logic ...
}
return geometry.getFactory().createGeometryCollection();
}Environment
- Sedona version: 1.9.0-SNAPSHOT (master)
- Found while implementing geopandas
line_merge()wrapper ([EPIC] Implement More Geopandas Functions #2230, [GH-2230] Implement GeoSeries: reverse, normalize, representative_point #2701)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels