jiayuasu opened a new issue, #2800: URL: https://github.com/apache/sedona/issues/2800
## Summary Add `ST_SharedPaths(geom1, geom2)` function that returns a `GeometryCollection` containing the paths shared between two linear geometries. This is the PostGIS equivalent of [`ST_SharedPaths`](https://postgis.net/docs/ST_SharedPaths.html). **Parent issue:** #2230 ## Design JTS does **not** provide a `SharedPathFinder` class, so this requires a custom implementation. The algorithm: 1. Compute the intersection of the two lineal geometries (`g1.intersection(g2)`) 2. Extract individual line components from the intersection result 3. For each shared segment, determine if it has the **same direction** in both input geometries or the **opposite direction** 4. Return a `GeometryCollection` with two child `MultiLineString`s: - Element 0: paths shared in the same direction - Element 1: paths shared in the opposite direction ### Signature ```sql ST_SharedPaths(geometry lineal1, geometry lineal2) → geometry (GeometryCollection) ``` ### Implementation layers 1. **Java core** (`Functions.java`): Custom algorithm using `intersection()` + direction comparison 2. **Scala Expression** (`Functions.scala`): `InferredExpression` case class 3. **Catalog registration** (`Catalog.scala`) 4. **Scala API** (`st_functions.scala`): Column wrappers 5. **Python API** (`st_functions.py`): Python wrapper 6. **Tests**: Scala + Python ### Example ```sql SELECT ST_SharedPaths( ST_GeomFromWKT('LINESTRING(0 0, 10 0, 10 10)'), ST_GeomFromWKT('LINESTRING(0 0, 10 0)') ); -- GEOMETRYCOLLECTION (MULTILINESTRING ((0 0, 10 0)), MULTILINESTRING EMPTY) ``` ### Direction detection For each shared segment, walk along the segment in the direction it appears in `g1`. Check if the same segment traversal direction appears in `g2`. If same → element 0; if reversed → element 1. ## Edge cases - Non-lineal geometries: throw `IllegalArgumentException` - No shared paths: return `GEOMETRYCOLLECTION(MULTILINESTRING EMPTY, MULTILINESTRING EMPTY)` - Empty geometries: return null - Self-intersecting lines: handle correctly by comparing individual segments -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
