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.
Parent issue: #2230
Design
JTS does not provide a SharedPathFinder class, so this requires a custom implementation. The algorithm:
- Compute the intersection of the two lineal geometries (
g1.intersection(g2))
- Extract individual line components from the intersection result
- For each shared segment, determine if it has the same direction in both input geometries or the opposite direction
- Return a
GeometryCollection with two child MultiLineStrings:
- Element 0: paths shared in the same direction
- Element 1: paths shared in the opposite direction
Signature
ST_SharedPaths(geometry lineal1, geometry lineal2) → geometry (GeometryCollection)
Implementation layers
- Java core (
Functions.java): Custom algorithm using intersection() + direction comparison
- Scala Expression (
Functions.scala): InferredExpression case class
- Catalog registration (
Catalog.scala)
- Scala API (
st_functions.scala): Column wrappers
- Python API (
st_functions.py): Python wrapper
- Tests: Scala + Python
Example
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
Summary
Add
ST_SharedPaths(geom1, geom2)function that returns aGeometryCollectioncontaining the paths shared between two linear geometries.This is the PostGIS equivalent of
ST_SharedPaths.Parent issue: #2230
Design
JTS does not provide a
SharedPathFinderclass, so this requires a custom implementation. The algorithm:g1.intersection(g2))GeometryCollectionwith two childMultiLineStrings:Signature
Implementation layers
Functions.java): Custom algorithm usingintersection()+ direction comparisonFunctions.scala):InferredExpressioncase classCatalog.scala)st_functions.scala): Column wrappersst_functions.py): Python wrapperExample
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 ing2. If same → element 0; if reversed → element 1.Edge cases
IllegalArgumentExceptionGEOMETRYCOLLECTION(MULTILINESTRING EMPTY, MULTILINESTRING EMPTY)