3

I am not able to st_split a line with a point on it.

I have a linestring and a point in epsg:3857 coordinate system. Their distance is 0:

select st_distance( st_geomfromtext('LineString (2121053.78109818324446678 6023680.98843276314437389, 2121127.97553879721090198 6023651.31408391986042261)',3857), st_geomfromtext('Point (2121091.12965324986726046 6023666.05073604825884104)',3857) ); st_distance ------------- 0 (1 row) 

The split returns the original line:

select st_astext(st_split( st_geomfromtext('LineString (2121053.78109818324446678 6023680.98843276314437389, 2121127.97553879721090198 6023651.31408391986042261)',3857), st_geomfromtext('Point (2121091.12965324986726046 6023666.05073604825884104)',3857) )); st_astext ---------------------------------------------------------------------------------------------------- GEOMETRYCOLLECTION(LINESTRING(2121053.78109818 6023680.98843276,2121127.9755388 6023651.31408392)) (1 row) 

The same result if I try to snap the point on the line with st_closestpoint:

select st_Astext(st_split( st_geomfromtext('LineString (2121053.78109818324446678 6023680.98843276314437389, 2121127.97553879721090198 6023651.31408391986042261)',3857), st_closestpoint( st_geomfromtext('LineString (2121053.78109818324446678 6023680.98843276314437389, 2121127.97553879721090198 6023651.31408391986042261)',3857), st_geomfromtext('Point (2121091.12965324986726046 6023666.05073604825884104)',3857) ))); st_astext ---------------------------------------------------------------------------------------------------- GEOMETRYCOLLECTION(LINESTRING(2121053.78109818 6023680.98843276,2121127.9755388 6023651.31408392)) (1 row) 

Postgis version:

 postgis_full_version --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- POSTGIS="2.3.2 r15302" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.3, released 2015/09/16" LIBXML="2.9.3" LIBJSON="0.11.99" RASTER (1 row) 

I'm on Debian 16.04 xenial and postgresql-9.6-postgis-2.3 from pgdg repository.

This might be related (this is why I upgraded from postgis 2.2.1):

http://trac.osgeo.org/postgis/ticket/3422

2
  • 17 places of precision with a unit of meters brings you to a distance of hundredths of femtometers (roughy one twentieth of proton radius). I doubt your data is that precise. Commented Mar 21, 2017 at 23:37
  • Yes, my data is not that precise. However the points I try to split the line with are calculated by postgis using st_intersection. Anyhow the rounding to any precision should solve this and seemingly it does not. Commented Mar 22, 2017 at 14:04

1 Answer 1

2

The ST_Split http://postgis.net/docs/ST_Split.html document page suggest to use ST_Snap http://www.postgis.org/docs/ST_Snap.html for better robustness. It seems to be a good suggestion:

select st_astext(st_split( st_snap( st_geomfromtext('LineString (2121053.78109818324446678 6023680.98843276314437389, 2121127.97553879721090198 6023651.31408391986042261)',3857), st_geomfromtext('Point (2121091.12965324986726046 6023666.05073604825884104)',3857),0.001), st_geomfromtext('Point (2121091.12965324986726046 6023666.05073604825884104)',3857) )); "GEOMETRYCOLLECTION(LINESTRING(2121053.78109818 6023680.98843276,2121091.12965325 6023666.05073605),LINESTRING(2121091.12965325 6023666.05073605,2121127.9755388 6023651.31408392))" 
1
  • Thanks for this. I actually have tried st_snap before. Your example snaps the line to the point then splits it. What I tried is to st_snap the point to the line which does not work as it tried to snap to a line vertex (with great tolerance given) instead of snapping to the interior line points. This latter is needed of course. That is why I stick with st_closestpoint. Commented Mar 22, 2017 at 7:28

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.