[postgis-users] ST_Split precision issue?

Martin Davis mtnclimb at gmail.com
Fri Apr 30 12:27:57 PDT 2021


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:

WITH line(geom) AS (VALUES
('LINESTRING(8.39567520433486 49.4224277276901,8.39591232763397
49.4198517063953)'::geometry)
)
SELECT ST_AsText(
  ST_LineSubstring( geom, 0, ST_LineLocatePoint(geom,
'POINT(8.39583178549713 49.4207266868819)'::geometry))
) AS part1,
ST_AsText(
  ST_LineSubstring( geom, ST_LineLocatePoint(geom, 'POINT(8.39583178549713
49.4207266868819)'::geometry), 1)
) AS part2
FROM line;


On Sun, Apr 25, 2021 at 7:49 AM Nicol Hermann <postgis at geoworld.de> wrote:

> 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
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20210430/b1489ecd/attachment.html>


More information about the postgis-users mailing list