<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Rebecca,<br><br>Sounds like you are doing this in a script, but you didn't specify your OS.<br><br>If so, then as each iteration completes, you can accumulate the id's of the polygons dealt to already, & test against this list to avoid creating the duplicates. Either in a file or in a table.<br><br>Along the lines of:<br><br>for polygon in <list of polygon ids> do<br>  if id not in list of unioned id's; then<br>    add ids to be unioned in this iteration to the list of unioned ones<br>    union them  <br>  end of if <br>move to next polygon id<br><br>You might consider making the unioned polygons a multipolygon, just in case some of them are.<br><br>There are improved functions & performance with later versions of postgres & postgis, so you might consider upgrading.<br><br>HTH,<br><br> 
 Brent Wood<br><br><br>--- On <b>Fri, 2/1/13, Rebecca Clarke <i><r.clarke83@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Rebecca Clarke <r.clarke83@gmail.com><br>Subject: [postgis-users] Advice on Unioning Polygons<br>To: postgis-users@lists.osgeo.org<br>Date: Friday, February 1, 2013, 11:40 PM<br><br><div id="yiv205058642"><div>Hi there</div><div><br></div><div>Looking for some advice.</div><div><br></div><div>I have a table with thousands of polygon records.</div><div><br></div><div>I want to union all intersecting polygons that have the same attributes into one polygon (So one record, rather than 10 or 20 etc.). </div>
<div><br></div><div>Can anyone recommend the best way to do this.</div><div><br></div><div>I can do a loop which goes through each record, unions its geometry with the geometry's of the other matching records that intersect with it, then move to the next record. Problem with this is that it creates duplicate polygons when it comes to a record that has already been unioned with a previous one record. I can easily delete any duplicate records generated, but I'm wondering if there's a less long winded way.</div>
<div><br></div><div>I hope I'm explaining myself correctly.</div><div><br></div><div>My details are:</div><div>postgis 1.3.5</div><div>PostgreSQL 8.3.8</div><div><br></div><div>Many thanks in advance.</div><div><br></div>
<div>Rebecca</div><div><br></div>
</div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>postgis-users mailing list<br><a ymailto="mailto:postgis-users@lists.osgeo.org" href="/mc/compose?to=postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br><a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br></div></blockquote></td></tr></table>