[postgis-users] Semantics of difference() function

Obe, Regina robe.dnd at cityofboston.gov
Wed Jun 4 09:33:33 PDT 2008


Martin,
Thanks for the explanations.  Regarding the below see my comments below
 
>Note - touches() implies intersects().  As I mentioned above, you need
>to be thinking in terms of testing Interior Intersection.  There are no
>named predicates which do this - you have to work with the DE-9IM
>pattern directly.  (I have added an interiorsIntersect predicate to JTS
>to do just this, since it's useful in some situations.
>> More disturbing is why when I cut a polygon with a line I get (shall we
>> say bizarre results).  A slightly larger polygon.
>>  
>This is a weird one. Can you post the actual geometries?  In JTS when I
>try differencing a line from a circular point buffer, I get a single
>polygon (with extra vertices where the line cut it).  This is the
>expected behaviour.  I don't know why PostGIS/GEOS is doing something
>different.
 
Actually the PostGIS/GEOS behavior is consistent with your JTS I think.  What I was getting was a single Polygon too with extra vertices
where the line cut throw.  It was when I was trying to figure out what the difference was between my original
polygon and this new polgon difference line.  Simply overlaying them on a screen I couldn't tell the difference so I differenced them and was shocked when my old polygon was completely contained by new polygon and new polygon was bigger by 2 super small polygons.  I thought it was more funny than anything.
 
new polygon = old polygon - line
old polygon - new polygon = empty collection
new polygon - old polygon = multipolygon (with 2 polygons)
 
If you look at the attached image of these blobs.  It is caused by those extra vertices added on to the polygon as you mentioned I think.   I was suspecting something like this but nice to get verification.
 
For those interested - the test case is
SELECT 1 As gid, g.geom1, g.geom2, ST_Difference(g.geom1, g.geom2) As diff_geom12, 
ST_Difference(g.geom2, g.geom1) As diff_geom21, ST_SymDifference(g.geom1,g.geom2) As diff_symgeom12
INTO diftest2
FROM (SELECT ST_Buffer(ST_MakePoint(9,3),2) As geom1, 
    ST_MakeLine(ST_MakePoint(8,0), ST_MakePoint(10,9)) As geom2) As g;

SELECT ST_Area(geom1) = ST_Area(diff_geom12) As is_areasame, 
    St_AsBinary(geom1) = St_AsBinary(diff_geom12) As binary_equal, 
        ST_Equals(geom1,diff_geom12)  As spatially_equal,
    ST_GeometryType(geom1) As geom1_type, 
    ST_GeometryType(diff_geom12) As geom12_type
FROM diftest2;
 
yields
is_areasame | binary_equal | spatially_equal | geom1_type | geom12_type
-------------+--------------+-----------------+------------+-------------
 t           | f            | f               | ST_Polygon | ST_Polygon
 
 
---Comparing them with difference which probably adds 
SELECT 
    ST_AsText(ST_Difference(geom1,diff_geom12)) As diff_geom1_geom12,
   ST_GeometryType(ST_Difference(diff_geom12,geom1)) As diff_geom12_geom1
FROM diftest2;

    diff_geom1_geom12     | diff_geom12_geom1
--------------------------+-------------------
 GEOMETRYCOLLECTION EMPTY | ST_MultiPolygon
 
thanks,
Regina
 
 
 


-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080604/14e940a5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: st_diffdiffgeomline.png
Type: image/x-png
Size: 4130 bytes
Desc: st_diffdiffgeomline.png
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080604/14e940a5/attachment.bin>


More information about the postgis-users mailing list