[geos-devel] [GEOS] #501: Snap operation: wrong snapping

GEOS geos-trac at osgeo.org
Sat Dec 10 13:01:59 EST 2011


#501: Snap operation: wrong snapping
------------------------+---------------------------------------------------
 Reporter:  aperi2007   |       Owner:  geos-devel@…              
     Type:  defect      |      Status:  new                       
 Priority:  major       |   Milestone:  3.3.2                     
Component:  Default     |     Version:  3.3.0                     
 Severity:  Unassigned  |    Keywords:                            
------------------------+---------------------------------------------------
 Hi I notice, using postgis that the Snap algoritm sometimes will wrong to
 snap geometries causing the born of invalid polygon or disallowing polygon
 otherwise perfectly touching each other.

 To produce a test-case I use linestrings

 Starting with this two linestrings:

 The geometry to snap (two only vertex)
 SELECT ST_GeomFromText('LINESTRING(0 0, 10 0)');

 Image:
        *--------------------*

 And the geometry used as reference (4 vertex)
 SELECT ST_GeomFromText('LINESTRING(0 0, 9 0, 10 0, 11 0)');

 Image:
        *-----------------*--*--*

 Please notice every vertex has a distance of 1 or more from other vertexs.
 And notice also the first geometry has its vertexs coords exactly as in
 the second geometry.

 Now I try to snap the first geometry on the second (the reference
 geometry) with a buffer of 2 meters:

 {{{
 Select ST_AsText(ST_Snap(ST_GeomFromText('LINESTRING(0 0, 10
 0)'),ST_GeomFromText('LINESTRING(0 0, 9 0, 10 0, 11 0)'),2));
 }}}

 I see that the result is:
 LINESTRING(0 0,11 0,10 0,9 0)

 Image:
        *----------->--->-----*
                         *-<-*

 I guess this is really a bug.

 I guess the right result should be always:
 LINESTRING(0 0, 10 0)

 Or also I guess another valid result could be this
 LINESTRING(0 0,9 0,10 0)
 Where I admit the snap was for segment.

 ----
 Perhaps an optional fourth parameter could allow choose if snap for
 "segments" or for "vertex", and default to "segment" because surely it is
 the more useful.
 ----

 However surely the result the Snap give at now:
 LINESTRING(0 0,11 0,10 0,9 0)
 is no the right result.

 I don't know how the Snap algorithm work, but I guess It seem to stop at
 the first vertex inside the buffer interval.
 I guess it should be search always the nearest vertex . So it will find
 that there is a vertex on exactly the same coords (10 0) and so it will
 produce a result like
 Linestring(0 0, I guess the Snap() method should always search the nearest
 vertex instead of stop to the first vertex inside the buffer interval.

 If it search go to find the nearest vertex it will find that there is a
 vertex exactly on the same coords (10 0), and so it will give as result

 ST_Snap('LINESTRING(0 0, 10 0)', LINESTRING(0 0, 9 0, 10 0, 11 0), 2) =
 LINESTRING(0 0, 9 0, 10 0)  (for segment)
 ST_Snap('LINESTRING(0 0, 10 0)', LINESTRING(0 0, 9 0, 10 0, 11 0), 2) =
 LINESTRING(0 0, 10 0)  (for vertex)

 --------

 Thx,
 Andrea.

-- 
Ticket URL: <http://trac.osgeo.org/geos/ticket/501>
GEOS <http://geos.refractions.net/>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).


More information about the geos-devel mailing list