<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16481" name=GENERATOR>
<STYLE>@page Section1 {size: 612.0pt 792.0pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; }
P.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0pt; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0pt; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0pt; FONT-FAMILY: "Times New Roman"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: Arial
}
DIV.Section1 {
        page: Section1
}
</STYLE>
</HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>How have you failed?  Did you get an error or some 
unexpected result.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>ST_Difference takes as input 2 geometries - 
ST_Difference(geom1, geom2)  and returns that portion of geom1 that is not 
in geom2.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>I generally use it in conjunction with 
intersection.  If 2 geometries are Disjoint - do not intersect then 
ST_Difference returns just geom1 I believe which is not terribly interesting and 
a bit of a waste fo processing speed since there are easier ways to return 
that.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT><FONT face=Arial color=#0000ff 
size=2><SPAN class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>So you would use it something like this - for example 
if you wanted to know that portion of a land parcel that is not built on, then 
you would do something like</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>SELECT ST_Difference(l.the_geom, 
b.the_geom)</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>FROM parcels l INNER JOIN buildings b ON 
ST_Intersects(l.the_geom, b.the_geom)</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>Note here I am making the wrong assumption that only 
one building lies on a parcel - so this example is a bit flawed (but simpler 
than my real query), but hopefully will give you an idea of how it is 
used.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT><FONT face=Arial color=#0000ff 
size=2><SPAN class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>Note: There is the less popular ST_SymDifference(geom1, 
geom2) that returns that portion of geom1 + geom2 that is not shared.  
Thus it is called Symmetric Difference since the order of the arguments does not 
matter.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>Hope that helps,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007>Regina</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN 
class=095542920-22102007></SPAN></FONT> </DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> 
postgis-users-bounces@postgis.refractions.net 
[mailto:postgis-users-bounces@postgis.refractions.net] <B>On Behalf Of 
</B>Richard Heimann [C]<BR><B>Sent:</B> Monday, October 22, 2007 3:47 
PM<BR><B>To:</B> postgis-users@postgis.refractions.net<BR><B>Subject:</B> 
[postgis-users] ST_Difference Syntax<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Arial size=2><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">PostGIS users,</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I have failed at constructing the 
ST_Differnece operation. Can someone expose the proper syntax? 
Thanks</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Richard</SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT> </P>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN 
style="FONT-SIZE: 12pt"></SPAN></FONT> </P></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>