Ticket #501 (new defect)
Snap operation: wrong snapping
| Reported by: | aperi2007 | Owned by: | geos-devel@… |
|---|---|---|---|
| Priority: | major | Milestone: | GEOS Future |
| Component: | Default | Version: | svn-trunk |
| Severity: | Unassigned | Keywords: | jtsfail |
| Cc: |
Description
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.

