<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="3074" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='color:#1F497D'>Awesome. That worked.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>OK, so<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
...FROM boundary neww, boundary_old oldd;</span><span style='color:#1F497D'><o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>is an implicit Cartesian product,
and that gets performed before the union, hence why we put the union into the
FROM statement. I had no idea I had been using so many implicit Cartesian
products… . Otherwise we are collecting a pairwise collection of
all records. So, if we wanted to retain some of the original tabular information,
we might skip the Cartesian product altogether (which is a fine option if we
just want the gross difference between a unioned version of all the geometries
in each of the tables) and do join based on bounding box instead?<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>BTW, thanks too for the tip on
ST_Collect.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Steve<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<div>
<p class=MsoNormal><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
stroked="f">
<v:stroke joinstyle="miter" />
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0" />
<v:f eqn="sum @0 1 0" />
<v:f eqn="sum 0 0 @1" />
<v:f eqn="prod @2 1 2" />
<v:f eqn="prod @3 21600 pixelWidth" />
<v:f eqn="prod @3 21600 pixelHeight" />
<v:f eqn="sum @0 0 1" />
<v:f eqn="prod @6 1 2" />
<v:f eqn="prod @7 21600 pixelWidth" />
<v:f eqn="sum @8 21600 0" />
<v:f eqn="prod @7 21600 pixelHeight" />
<v:f eqn="sum @10 21600 0" />
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" />
<o:lock v:ext="edit" aspectratio="t" />
</v:shapetype><v:shape id="_x0000_s1027" type="#_x0000_t75" alt="http://www.clemetparks.com/images/esig/cmp-ms-90x122.png"
style='position:absolute;margin-left:1.5pt;margin-top:0;width:67.5pt;height:91.5pt;
z-index:2;visibility:visible;mso-wrap-style:square;mso-wrap-distance-left:9pt;
mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;
mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;
mso-position-horizontal-relative:text;mso-position-vertical:absolute;
mso-position-vertical-relative:text'>
<v:imagedata src="cid:image001.png@01CC8D83.15DB5670" o:href="http://www.clemetparks.com/images/esig/cmp-ms-90x122.png" />
<w:wrap type="square"/>
</v:shape><![endif]--><![if !vml]><img width=90 height=122
src="cid:image001.png@01CC8D83.15DB5670" align=left hspace=12
alt="http://www.clemetparks.com/images/esig/cmp-ms-90x122.png" v:shapes="_x0000_s1027"><![endif]><span
style='font-size:14.0pt;font-family:"Arial","sans-serif";color:#006C56'>Stephen
Mather<br>
</span><span style='font-family:"Arial","sans-serif";color:#006C56'>Geographic
Information Systems (GIS) Manager<br>
</span><span style='font-size:9.0pt;font-family:"Arial","sans-serif";
color:#006C56'>(216) 635-3243<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:9.0pt;font-family:"Arial","sans-serif";
color:#006C56'>svm@clevelandmetroparks.com<br>
</span><span style='color:#1F497D'><a href="http://www.clemetparks.com/"><span
style='font-size:9.0pt;font-family:"Arial","sans-serif";color:blue'>clevelandmetroparks.com</span></a><o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
</div>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<div>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
postgis-users-bounces@postgis.refractions.net
[mailto:postgis-users-bounces@postgis.refractions.net] <b>On Behalf Of </b>Paragon
Corporation<br>
<b>Sent:</b> Monday, October 17, 2011 9:31 PM<br>
<b>To:</b> 'PostGIS Users Discussion'<br>
<b>Subject:</b> Re: [postgis-users] ST_SymDifference<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:blue'>Stephen, </span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:blue'>It takes a brave man to admit he is using antiquated technology. I
applaud you :).</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:blue'>I see one major issue here. You are doing a cartesian product
before unioning / collecting.</span><span style='font-size:12.0pt;font-family:
"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:blue'>That means for every new.the_geom you have you are creating n
copies of it where n is the number of boundary_old records you have and then
unioning that permutation. You'll get the right answer, but it will be
really slow the more geometries you have. </span><span style='font-size:
12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";
color:blue'>Try this:</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'> SELECT
ST_SymDifference(new.geom, oldd.geom)</span><span style='font-size:12.0pt;
font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Courier New"'>FROM
</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>(SELECT
ST_Union(the_geom) As geom FROM boundary) AS neww</span><o:p></o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'> CROSS JOIN
(SELECT ST_Union(the_geom) As geom FROM boundary_old) AS oldd;</span><o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>The above should be
faster, but depending on how many geometries you have could still be slow.</span><o:p></o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>In 1.4 and above,
aggregation speed and ST_Unionspeed got wicked faster than 1.3 especially
when you are talking about a lot of geometries.</span><o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>That would be one
reason to upgrade.</span><o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>As far as using
ST_Collect vs. ST_Union. If you are dealing with polygons you are much
safer using ST_Union since ST_Collect will create invalid multipolygons if any
of your geometries intersect.</span><o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>Hope that helps,</span><o:p></o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>Regina</span><o:p></o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'><a
href="http://www.postgis.us">http://www.postgis.us</a></span><o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p class=MsoNormal> <o:p></o:p></p>
<p class=MsoNormal> <span style='font-family:"Courier New"'><o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
<blockquote style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p> </o:p></span></p>
<div class=MsoNormal align=center style='text-align:center'><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'>
<hr size=2 width="100%" align=center>
</span></div>
<p class=MsoNormal style='margin-bottom:12.0pt'><b><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'> postgis-users-bounces@postgis.refractions.net
[mailto:postgis-users-bounces@postgis.refractions.net] <b>On Behalf Of </b>Stephen
V. Mather<br>
<b>Sent:</b> Monday, October 17, 2011 5:03 PM<br>
<b>To:</b> postgis-users@postgis.refractions.net<br>
<b>Subject:</b> [postgis-users] ST_SymDifference</span><span style='font-size:
12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal>Hi All,<o:p></o:p></p>
<p class=MsoNormal>
True confession, I’m running PostGIS 1.3.5, so throw the tomatoes gently
if A) I’m doing a bad query, or B) I’m dredging up old news on
(in)efficiency, and I really should upgrade to 1.5.x, thank you very
much… . Admittedly, it is time for that, but hopefully that’s
a separate issue.<o:p></o:p></p>
<p class=MsoNormal>
I’m trying to calculate the symmetrical difference on a pair of
geometries, and my query runs slowly:<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
SELECT ST_SymDifference(<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
ST_Collect(neww.the_geom),<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
ST_Collect(oldd.the_geom) <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
) AS the_geom<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
FROM boundary neww, boundary_old oldd;<o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='text-indent:.5in'>Now, if I were to be entirely
honest, I’d confess that this was my cludge of an original query:<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
SELECT ST_SymDifference(<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
ST_Union(ST_Buffer(neww.the_geom, 0)),<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
ST_Union(ST_Buffer(oldd.the_geom, 0)) <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
) AS the_geom<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-family:"Courier New"'>
FROM boundary neww, boundary_old oldd;<o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>but who would admit to running a query like that, should
they know better. Not I.<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>So, why is my query sooooo slooooow? Is it A), B), or
some yet to be known to me C). BTW, (now I’m just to being
provocative,) when I run a symmetrical difference in ArcGIS, it runs very
quickly… :).<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Best,<o:p></o:p></p>
<p class=MsoNormal>Thanks,<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><!--[if gte vml 1]><v:shape id="cmp-ms-90x122.png" o:spid="_x0000_s1026"
type="#_x0000_t75" alt="http://www.clemetparks.com/images/esig/cmp-ms-90x122.png"
style='position:absolute;margin-left:1.5pt;margin-top:0;width:67.5pt;height:91.5pt;
z-index:1;visibility:visible'>
<v:imagedata src="http://www.clemetparks.com/images/esig/cmp-ms-90x122.png" />
<w:wrap type="square"/>
</v:shape><![endif]--><![if !vml]><img width=90 height=122
src="http://www.clemetparks.com/images/esig/cmp-ms-90x122.png" align=left
hspace=12 alt="http://www.clemetparks.com/images/esig/cmp-ms-90x122.png"
v:shapes="cmp-ms-90x122.png"><![endif]><span style='font-size:14.0pt;
font-family:"Arial","sans-serif";color:#006C56'>Stephen Mather<br>
</span><span style='font-family:"Arial","sans-serif";color:#006C56'>Geographic
Information Systems (GIS) Manager<br>
</span><span style='font-size:9.0pt;font-family:"Arial","sans-serif";
color:#006C56'>(216) 635-3243<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:9.0pt;font-family:"Arial","sans-serif";
color:#006C56'>svm@clevelandmetroparks.com<br>
</span><a href="http://www.clemetparks.com/"><span style='font-size:9.0pt;
font-family:"Arial","sans-serif"'>clevelandmetroparks.com</span></a><o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
</blockquote>
</div>
</body>
</html>