Opened 12 years ago

Last modified 3 years ago

#2192 new enhancement

Add tolerance parameter to ST_Split for splitting lines by points

Reported by: michischolz Owned by: pramsey
Priority: medium Milestone: PostGIS Fund Me
Component: postgis Version: 2.0.x
Keywords: st_split, tolerance, gsoc Cc:

Description

Heho. ST_Split does not work well when splitting a line by a point. Consider the following example where the line is not split even though the blade is supposed to be a point on the line:

SELECT ST_AsText((ST_Dump(ST_Split(lin.geom, ST_Line_Interpolate_Point(lin.geom, 0.5)))).geom) AS geom
FROM (SELECT ST_GeomFromText('LINESTRING(604630.408 5792499.778,604623.849 5792500.886)') AS geom) AS lin

For the case of a line split by a point some kind of tolerance parameter would help. Until now I it is necessary first to ST_Snap your line to that interpolated point before splitting it by the point, which is not straightforward (thanks to strk for this hint). At least you could mention this hint in the documentation.

Attachments (1)

reference_processing.xml.patch (855 bytes ) - added by michischolz 12 years ago.
Patch of documentation for ST_Split

Download all attachments as: .zip

Change History (9)

comment:1 by robe, 12 years ago

Component: postgisdocumentation
Owner: changed from pramsey to robe

comment:2 by strk, 12 years ago

Component: documentationpostgis
Milestone: PostGIS 2.0.3PostGIS 2.1.0
Owner: changed from robe to pramsey

New parameter requires minor version upgrade. michischolz: a patch for documentation is welcome

by michischolz, 12 years ago

Patch of documentation for ST_Split

comment:3 by robe, 12 years ago

Keywords: gsoc added

Okay incorporated the doco patch for 2.0 at r11251 and 2.1 at r11252

adding feature to google summer of code candidate list. http://trac.osgeo.org/postgis/wiki/GoogleSummerCode

comment:4 by robe, 11 years ago

Milestone: PostGIS 2.1.0PostGIS 2.2.0

comment:5 by pramsey, 9 years ago

Milestone: PostGIS 2.2.0PostGIS Future

comment:6 by worthlutz, 8 years ago

I ran into this problem and this ticket showed up on Google. I was a bit confused trying to use ST_Snap as hinted at above. It took me a while to understand that I needed to snap the line to the point instead of the opposite. I am adding this comment to help others.

Here is my query:

SELECT
    ST_AsText( ST_LineInterpolatePoint(the_geom, 0.5) ) AS the_point_geom,
    
    ST_AsText(
        (ST_Dump(
            ST_Split( 
                ST_Snap( the_geom, ST_LineInterpolatePoint(the_geom, 0.5), 0.00000001 ), 
                ST_LineInterpolatePoint(the_geom, 0.5)
            )
        )).geom
    ) AS the_new_line_geom
    
FROM street_segments
WHERE id = 2085426
Last edited 8 years ago by worthlutz (previous) (diff)

comment:7 by robe, 7 years ago

Milestone: PostGIS FuturePostGIS Fund Me

Milestone renamed

comment:8 by mwtoews, 3 years ago

FYI, a simple implementation of this feature is:

CREATE OR REPLACE FUNCTION ST_Split(geom1 geometry, geom2 geometry, double precision)
  RETURNS geometry AS 'SELECT ST_Split(ST_Snap($1, $2, $3), $2)'
  LANGUAGE sql IMMUTABLE STRICT COST 10;

However, it's not ideal:

SELECT ST_AsText(ST_Split('LINESTRING(0 0, 2 0)', 'MULTIPOINT(0 0, 1 0.0001)', 0.001));
-- Returns: GEOMETRYCOLLECTION(LINESTRING(1 0.0001,2 0),LINESTRING(0 0,1 0.0001))
-- Expected: GEOMETRYCOLLECTION(LINESTRING(1 0,2 0),LINESTRING(0 0,1 0))

Ideally the C-level logic would use lwgeom_snap and lwline_interpolate_points to handle a third tolerance parameter.

Note: See TracTickets for help on using tickets.