<HTML dir=ltr><HEAD><TITLE>[postgis-users] Semantics of difference() function</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.2900.3314" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText47463 dir=ltr>
<DIV dir=ltr><FONT size=2>Martin,</FONT></DIV>
<DIV dir=ltr><FONT size=2>Thanks for the explanations.  Regarding the below see my comments below</FONT></DIV>
<DIV dir=ltr><FONT size=2></FONT> </DIV>
<DIV dir=ltr><FONT size=2>>Note - touches() implies intersects().  As I mentioned above, you need<BR>>to be thinking in terms of testing Interior Intersection.  There are no<BR>>named predicates which do this - you have to work with the DE-9IM<BR>>pattern directly.  (I have added an interiorsIntersect predicate to JTS<BR>>to do just this, since it's useful in some situations.<BR>>> More disturbing is why when I cut a polygon with a line I get (shall we<BR>>> say bizarre results).  A slightly larger polygon.<BR>>>  <BR>>This is a weird one. Can you post the actual geometries?  In JTS when I<BR>>try differencing a line from a circular point buffer, I get a single<BR>>polygon (with extra vertices where the line cut it).  This is the<BR>>expected behaviour.  I don't know why PostGIS/GEOS is doing something<BR>>different.</FONT></DIV>
<DIV dir=ltr><FONT size=2></FONT> </DIV>
<DIV dir=ltr><FONT size=2>Actually the PostGIS/GEOS behavior is consistent with your JTS I think.  What I was getting was a single Polygon too with extra vertices</FONT></DIV>
<DIV dir=ltr><FONT size=2>where the line cut throw.  It was when I was trying to figure out what the difference was between my original</FONT></DIV>
<DIV dir=ltr><FONT size=2>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.</FONT></DIV>
<DIV dir=ltr><FONT size=2></FONT> </DIV>
<DIV dir=ltr><FONT size=2>new polygon = old polygon - line</FONT></DIV>
<DIV dir=ltr><FONT size=2>old polygon - new polygon = empty collection</FONT></DIV>
<DIV dir=ltr><FONT size=2>new polygon - old polygon = multipolygon (with 2 polygons)</FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT size=2>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.</FONT>   I was suspecting something like this but nice to get verification.</DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr>For those interested - the test case is</DIV>
<DIV dir=ltr><PRE><SPAN class=syntax0><SPAN class=syntax8>SELECT</SPAN> <SPAN class=syntax5>1</SPAN> <SPAN class=syntax8>As</SPAN> gid, g.geom1, g.geom2, <SPAN class=syntax6>ST_Difference</SPAN>(g.geom1, g.geom2) <SPAN class=syntax8>As</SPAN> diff_geom12, 
<SPAN class=syntax6>ST_Difference</SPAN>(g.geom2, g.geom1) <SPAN class=syntax8>As</SPAN> diff_geom21, <SPAN class=syntax6>ST_SymDifference</SPAN>(g.geom1,g.geom2) <SPAN class=syntax8>As</SPAN> diff_symgeom12
<SPAN class=syntax8>INTO</SPAN> diftest2
<SPAN class=syntax8>FROM</SPAN> (<SPAN class=syntax8>SELECT</SPAN> <SPAN class=syntax6>ST_Buffer</SPAN>(<SPAN class=syntax6>ST_MakePoint</SPAN>(<SPAN class=syntax5>9</SPAN>,<SPAN class=syntax5>3</SPAN>),<SPAN class=syntax5>2</SPAN>) <SPAN class=syntax8>As</SPAN> geom1, 
    <SPAN class=syntax6>ST_MakeLine</SPAN>(<SPAN class=syntax6>ST_MakePoint</SPAN>(<SPAN class=syntax5>8</SPAN>,<SPAN class=syntax5>0</SPAN>), <SPAN class=syntax6>ST_MakePoint</SPAN>(<SPAN class=syntax5>10</SPAN>,<SPAN class=syntax5>9</SPAN>)) <SPAN class=syntax8>As</SPAN> geom2) <SPAN class=syntax8>As</SPAN> g;
</SPAN></PRE><PRE><SPAN class=syntax0><PRE><SPAN class=syntax0><SPAN class=syntax8>SELECT</SPAN> <SPAN class=syntax6>ST_Area</SPAN>(geom1) <SPAN class=syntax18>=</SPAN> <SPAN class=syntax6>ST_Area</SPAN>(diff_geom12) <SPAN class=syntax8>As</SPAN> is_areasame, 
    <SPAN class=syntax6>St_AsBinary</SPAN>(geom1) <SPAN class=syntax18>=</SPAN> <SPAN class=syntax6>St_AsBinary</SPAN>(diff_geom12) <SPAN class=syntax8>As</SPAN> binary_equal, 
        <SPAN class=syntax6>ST_Equals</SPAN>(geom1,diff_geom12)  <SPAN class=syntax8>As</SPAN> spatially_equal,
    <SPAN class=syntax6>ST_GeometryType</SPAN>(geom1) <SPAN class=syntax8>As</SPAN> geom1_type, 
    <SPAN class=syntax6>ST_GeometryType</SPAN>(diff_geom12) <SPAN class=syntax8>As</SPAN> geom12_type
<SPAN class=syntax8>FROM</SPAN> diftest2;</SPAN></PRE><PRE><SPAN class=syntax0></SPAN> </PRE><PRE><SPAN class=syntax0>yields</SPAN></PRE><PRE><SPAN class=syntax0><PRE>is_areasame | binary_equal | spatially_equal | geom1_type | geom12_type
-------------+--------------+-----------------+------------+-------------
 t           | f            | f               | ST_Polygon | ST_Polygon</PRE><PRE> </PRE><PRE> </PRE><PRE>---Comparing them with difference which probably adds </PRE><PRE><PRE><SPAN class=syntax0><SPAN class=syntax8>SELECT</SPAN> 
    <SPAN class=syntax6>ST_AsText</SPAN>(<SPAN class=syntax6>ST_Difference</SPAN>(geom1,diff_geom12)) <SPAN class=syntax8>As</SPAN> diff_geom1_geom12,
   <SPAN class=syntax6>ST_GeometryType</SPAN>(<SPAN class=syntax6>ST_Difference</SPAN>(diff_geom12,geom1)) <SPAN class=syntax8>As</SPAN> diff_geom12_geom1
<SPAN class=syntax8>FROM</SPAN> diftest2;
</SPAN></PRE><PRE><SPAN class=syntax0><PRE>    diff_geom1_geom12     | diff_geom12_geom1
--------------------------+-------------------
 GEOMETRYCOLLECTION EMPTY | ST_MultiPolygon</PRE><PRE> </PRE><PRE>thanks,</PRE><PRE>Regina</PRE></SPAN></PRE></PRE></SPAN></PRE></SPAN></PRE></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT size=2></FONT> </DIV>
<DIV dir=ltr><FONT size=2></FONT> </DIV></DIV></BODY></HTML>
<HTML><BODY><P><hr size=1></P>
<P><STRONG>
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.
</STRONG></P></BODY></HTML>

<P><hr size=1></P>
<P><STRONG><font size="2" color="339900"> Help make the earth a greener place. If at all possible resist printing this email and join us in saving paper. </p> <p> </font></STRONG></P>