Repository navigation
Closed
Description
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
GeometryCollectionwith two childMultiLineStrings:- 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 usingintersection()+ direction comparison - Scala Expression (
Functions.scala):InferredExpressioncase 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
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-][GH-2230] Add ST_SharedPaths function[/-][+]Add ST_SharedPaths function[/+][apacheGH-2800] Add detailed shared paths diagrams
[apacheGH-2800] Harden shared path edge cases
[apacheGH-2800] Enforce geometry-only Snowflake functions
[apacheGH-2800] Preserve GeoSeries binary operation metadata
[apacheGH-2800] Clarify shared path edge behavior
[apacheGH-2800] Expand shared path examples
[apacheGH-2800] Short-circuit disjoint shared paths
[GH-2800] Add ST_SharedPaths across engines and GeoPandas (#3250)
[apacheGH-2800] Fix Snowflake tester failures for empty geometries
[GH-2800] Fix Snowflake tester failures for empty geometries (#3272)