My apologies for the bad title; I couldn't think of anything more descriptive.
I have been testing ST_Split
with a dataset, and found that even with points that are supposed to be exactly on a line (found by ST_Line_Interpolate_Point
) often the line doesn't get split.
select ST_AsText(ST_Split(ST_GeomFromText('LINESTRING(0 0, 100 100, 200 200, 400 400)'), ST_Line_Interpolate_Point(ST_GeomFromText('LINESTRING(0 0, 100 100, 200 200, 400 400)'), 0.2)))
Result:
GEOMETRYCOLLECTION(LINESTRING(0 0,80 80),LINESTRING(80 80,100 100,200 200,400 400))
Which is as expected. Now I introduce some decimals:
select ST_AsText(ST_Split(ST_GeomFromText('LINESTRING(0 0, 100.123456789 100.987654321, 200 200, 400 400)'), ST_Line_Interpolate_Point(ST_GeomFromText('LINESTRING(0 0, 100.123456789 100.987654321, 200 200, 400 400)'), 0.2)))
Result:
GEOMETRYCOLLECTION(LINESTRING(0 0,100.123456789 100.987654321,200 200,400 400))
Stripping some decimals:
select ST_AsText(ST_Split(ST_GeomFromText('LINESTRING(0 0, 100.123456 100.987654, 200 200, 400 400)'), ST_Line_Interpolate_Point(ST_GeomFromText('LINESTRING(0 0, 100.123456 100.987654, 200 200, 400 400)'), 0.2)))
Result:
GEOMETRYCOLLECTION(LINESTRING(0 0,79.6558670241487 80.3434026298966),LINESTRING(79.6558670241487 80.3434026298966,100.123456 100.987654,200 200,400 400))
Nearly all records in my dataset have a lot of decimals (which I think the problem is), meaning NONE of my lines get split, even though the point is supposed to be exactly on the line. Is there any way to work around this (quickly; I have to split 300k lines like this)? Preferably without modifying my dataset by using ST_SnapToGrid
?
I'm Using POSTGIS="2.0.3 r11132" GEOS="3.3.8-CAPI-1.7.8" PROJ="Rel. 4.8.0, 6 March 2012"