<div dir="ltr"><div>For working with points and lines it's probably better to use the linear referencing functions.  Here's a query which does what you require:</div><div><br></div><div>WITH line(geom) AS (VALUES<br>('LINESTRING(8.39567520433486 49.4224277276901,8.39591232763397 49.4198517063953)'::geometry)<br>)<br>SELECT ST_AsText( <br>  ST_LineSubstring( geom, 0, ST_LineLocatePoint(geom, 'POINT(8.39583178549713 49.4207266868819)'::geometry))<br>) AS part1,<br>ST_AsText( <br>  ST_LineSubstring( geom, ST_LineLocatePoint(geom, 'POINT(8.39583178549713 49.4207266868819)'::geometry), 1)<br>) AS part2<br>FROM line;<br></div><div><br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Apr 25, 2021 at 7:49 AM Nicol Hermann <<a href="mailto:postgis@geoworld.de">postgis@geoworld.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello List,<br>
<br>
I am trying to split a linestring at an intersection to another line<br>
into it's two segments.<br>
This works as expected with "dummy" coordinates, but fails with "real-<br>
world" coordinates.<br>
<br>
This:<br>
<br>
SELECT ST_AsText( ST_Split (ST_GeomFromText('LINESTRING(0 0,2 2)'),<br>
ST_GeomFromText('POINT(1 1)') ) ) as lsegments;<br>
<br>
gives me the expected output:<br>
<br>
                          lsegments                          <br>
-------------------------------------------------------------<br>
 GEOMETRYCOLLECTION(LINESTRING(0 0,1 1),LINESTRING(1 1,2 2))<br>
(1 Zeile)<br>
<br>
<br>
When I am trying this with real world coordinates I am always getting<br>
the un-splitted original linesting back.<br>
Sample:<br>
<br>
SELECT ST_AsText(ST_intersection(aline, bline)) AS<br>
wktcut                                                                 <br>
<br>
FROM (SELECT<br>
    ST_GeomFromText('LINESTRING(8.39567520433486<br>
49.4224277276901,8.39591232763397 49.4198517063953)') As aline,<br>
    ST_GeomFromText('LINESTRING(8.39481293779266<br>
49.4206708596104,8.39717339245195 49.4208001995917)') As bline ) As<br>
foo;<br>
<br>
returns<br>
POINT(8.39583178549713 49.4207266868819)<br>
<br>
If I am using this in the split command<br>
<br>
SELECT ST_AsText( ST_Split<br>
(ST_GeomFromText('LINESTRING(8.39567520433486<br>
49.4224277276901,8.39591232763397 49.4198517063953)'),<br>
ST_GeomFromText('POINT(8.39583178549713 49.4207266868819)') ) ) as<br>
lsegments;<br>
<br>
the result is <br>
lsegments                                              <br>
----------------------------------------------------------------------<br>
 GEOMETRYCOLLECTION(LINESTRING(8.39567520433486<br>
49.4224277276901,8.39591232763397 49.4198517063953))<br>
(1 Zeile)<br>
<br>
which es equal to the input.<br>
<br>
Is this a precision issue between differen postgis functions and how<br>
can I solve this?<br>
<br>
If I'am adding ST_Snap it returns a linestring which only represents<br>
one of the 2 segments I would expect.<br>
<br>
See:<br>
<br>
SELECT <br>
 ST_AsText( <br>
  ST_Split ( <br>
   ST_Snap ( <br>
     ST_GeomFromText('LINESTRING(8.39567520433486<br>
49.4224277276901,8.39591232763397 49.4198517063953)'),<br>
ST_GeomFromText('POINT(8.39583178549713 49.4207266868819)'), 1 ), <br>
  ST_GeomFromText('POINT(8.39583178549713 49.4207266868819)') )<br>
);<br>
) ) <br>
as lsegments;<br>
<br>
response is:<br>
<br>
lsegemts                                               <br>
----------------------------------------------------------------------<br>
 GEOMETRYCOLLECTION(LINESTRING(8.39567520433486<br>
49.4224277276901,8.39583178549713 49.4207266868819))<br>
<br>
<br>
Any hints, or do I have a misconception how ST_Split should work?<br>
<br>
Thanks<br>
Nicol<br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><br>
</blockquote></div></div>