[postgis-users] ST_Split precision issue?

Nicol Hermann postgis at geoworld.de
Sun Apr 25 07:36:03 PDT 2021


Hello List,

I am trying to split a linestring at an intersection to another line
into it's two segments.
This works as expected with "dummy" coordinates, but fails with "real-
world" coordinates.

This:

SELECT ST_AsText( ST_Split (ST_GeomFromText('LINESTRING(0 0,2 2)'),
ST_GeomFromText('POINT(1 1)') ) ) as lsegments;

gives me the expected output:

                          lsegments                          
-------------------------------------------------------------
 GEOMETRYCOLLECTION(LINESTRING(0 0,1 1),LINESTRING(1 1,2 2))
(1 Zeile)


When I am trying this with real world coordinates I am always getting
the un-splitted original linesting back.
Sample:

SELECT ST_AsText(ST_intersection(aline, bline)) AS
wktcut                                                                 
                                                 
FROM (SELECT
    ST_GeomFromText('LINESTRING(8.39567520433486
49.4224277276901,8.39591232763397 49.4198517063953)') As aline,
    ST_GeomFromText('LINESTRING(8.39481293779266
49.4206708596104,8.39717339245195 49.4208001995917)') As bline ) As
foo;

returns
POINT(8.39583178549713 49.4207266868819)

If I am using this in the split command

SELECT ST_AsText( ST_Split
(ST_GeomFromText('LINESTRING(8.39567520433486
49.4224277276901,8.39591232763397 49.4198517063953)'),
ST_GeomFromText('POINT(8.39583178549713 49.4207266868819)') ) ) as
lsegments;

the result is 
lsegments                                              
----------------------------------------------------------------------
 GEOMETRYCOLLECTION(LINESTRING(8.39567520433486
49.4224277276901,8.39591232763397 49.4198517063953))
(1 Zeile)

which es equal to the input.

Is this a precision issue between differen postgis functions and how
can I solve this?

If I'am adding ST_Snap it returns a linestring which only represents
one of the 2 segments I would expect.

See:

SELECT 
 ST_AsText( 
  ST_Split ( 
   ST_Snap ( 
     ST_GeomFromText('LINESTRING(8.39567520433486
49.4224277276901,8.39591232763397 49.4198517063953)'),
ST_GeomFromText('POINT(8.39583178549713 49.4207266868819)'), 1 ), 
  ST_GeomFromText('POINT(8.39583178549713 49.4207266868819)') )
);
) ) 
as lsegments;

response is:

lsegemts                                               
----------------------------------------------------------------------
 GEOMETRYCOLLECTION(LINESTRING(8.39567520433486
49.4224277276901,8.39583178549713 49.4207266868819))


Any hints, or do I have a misconception how ST_Split should work?

Thanks
Nicol



More information about the postgis-users mailing list