Opened 4 years ago

Last modified 4 years ago

#4765 new defect

ST_ClipByBox2D: Incorrect clipping of lines

Reported by: Algunenano Owned by: pramsey
Priority: medium Milestone: PostGIS GEOS
Component: postgis Version: master
Keywords: Cc:

Description

It seems there is some kind of bug when clipping lines that are around the borders of the bbox in ST_ClipByBox2D.

Query:

WITH geom AS
(
    SELECT 'LINESTRING(0 0,0 10, 10 10,1 1)'::geometry as geom
    UNION ALL
    SELECT 'LINESTRING(0 0, 0 15, 15 15, 1 1)'::geometry as geom
),
box AS
(
    SELECT ST_MakeEnvelope(0,0,10,10) AS box
)
SELECT
    ST_AsText(geom) as geom,
    ST_AsText(box::box2d) as box,
    ST_AsText(ST_ClipByBox2D(geom, box)) as clip,
    ST_AsText(ST_Intersection(geom, box)) as intersection
FROM geom, box

Output:

              geom              |                box                 |              clip              |                     intersection                     
--------------------------------+------------------------------------+--------------------------------+------------------------------------------------------
 LINESTRING(0 0,0 10,10 10,1 1) | POLYGON((0 0,0 10,10 10,10 0,0 0)) | LINESTRING(0 0,0 10,10 10,1 1) | MULTILINESTRING((0 0,0 10),(0 10,10 10),(10 10,1 1))
 LINESTRING(0 0,0 15,15 15,1 1) | POLYGON((0 0,0 10,10 10,10 0,0 0)) | LINESTRING(10 10,1 1)          | MULTILINESTRING((0 0,0 10),(10 10,1 1))
(2 rows)

In the first case things look normal, both when you clip using ST_Intersect or ST_ClipByBox2D, but in the second case the ST_ClipByBox2D output is clearly wrong as it's missing a whole lien, while ST_Intersection is returning a valid value.

I haven't reproduced the issue with polygons, just lines.

It's likely a GEOS issue, but I haven't tried to isolate it yet to report it there if necessary. Tested with Postgis 3.0 and master, GEOS 3.8.2 and master (with and without overlayNG).

Change History (2)

comment:1 by komzpa, 4 years ago

I have a vague feeling that this is in order to have ST_Subdivide left and right tiles not both have a single segment of line - it only goes to one side.

comment:2 by Algunenano, 4 years ago

Milestone: PostGIS 3.0.3PostGIS GEOS
Note: See TracTickets for help on using tickets.