<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>RE: [postgis-devel] More Cascade Union Adventures</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Martin,<BR>
Haven't looked at the code yet, but just realized that yes that I think&nbsp; you are describing can be expressed in just SQL with what I will<BR>
call a CROSS JOIN boolean_or (g would be the geometries all dumped out into their constituent geometries)<BR>
<BR>
So looks something like this<BR>
<BR>
SELECT ST_Collect(s.geom) As newgeom<BR>
FROM (SELECT g1.id, g1.geom, boolean_or(g1.geom &amp;&amp; g2.geom) As has_intersect<BR>
FROM g As g1 CROSS JOIN g As g2<BR>
WHERE g1.id &lt;&gt; g2.id<BR>
GROUP BY g1.id, g1.geom) As s<BR>
GROUP BY<BR>
CASE WHEN s.has_intersect<BR>
THEN s.id ELSE -1 END<BR>
<BR>
Would collect together all parts that have no intersections&nbsp; and leave the others as separate individual geometries, then I perform my union operation against the above new set.<BR>
<BR>
Not sure how efficient the above would be to do, but I suspect if I do in batches which are ordered, may be quite efficient.<BR>
<BR>
Anyrate I'll give it a go.<BR>
<BR>
Thanks,<BR>
Regina<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: postgis-devel-bounces@postgis.refractions.net on behalf of Martin Davis<BR>
Sent: Thu 8/14/2008 11:55 AM<BR>
To: PostGIS Development Discussion<BR>
Subject: Re: [postgis-devel] More Cascade Union Adventures<BR>
<BR>
You can download JTS 1.9 (with src) from Sourceforge:<BR>
<BR>
<A HREF="http://sourceforge.net/projects/jts-topo-suite/">http://sourceforge.net/projects/jts-topo-suite/</A><BR>
<BR>
Obe, Regina wrote:<BR>
&gt;<BR>
&gt; Martin,<BR>
&gt; Well there is plpgsql too which is very procedural so doesn't have to<BR>
&gt; be expressed in sql per se. I use sql because it is generally<BR>
&gt; speedwise faster for the planner to integrate and easier to prototype<BR>
&gt; with (at least for me since I can get my thoughts down more succinctly<BR>
&gt; granted probably harder to read for others) than plpgsql.<BR>
&gt;<BR>
&gt; If we replace the garray accum with a custom append - it can also look<BR>
&gt; at the geometries as they are coming in and perhaps do a collect<BR>
&gt; instead of an append and do some other conditional stuff.<BR>
&gt;<BR>
&gt; Where would I download this code to see what it looks like (JTS site<BR>
&gt; only seems to go to JTS 1.8).&nbsp; I'm having a hard time picturing what<BR>
&gt; you are saying.&nbsp; But if I see it in Java I can probably figure out the<BR>
&gt; most efficient translation in sql/plpgsql.<BR>
&gt;<BR>
&gt; Thanks,<BR>
&gt; Regina<BR>
&gt;<BR>
&gt; -----Original Message-----<BR>
&gt; From: postgis-devel-bounces@postgis.refractions.net on behalf of<BR>
&gt; Martin Davis<BR>
&gt; Sent: Wed 8/13/2008 8:08 PM<BR>
&gt; To: PostGIS Development Discussion<BR>
&gt; Subject: Re: [postgis-devel] More Cascade Union Adventures<BR>
&gt;<BR>
&gt; While pondering OJ's failure to complete the union on this dataset, I<BR>
&gt; realized that one trick that CascadedUnion uses is that when unioning<BR>
&gt; two MultiPolygons, it *avoids* unioning polygon components which lie<BR>
&gt; outside the intersection of the envelopes of the two input geometries.<BR>
&gt; Those polygon components will be left unchanged by the union, and so can<BR>
&gt; just be added in afterwards.&nbsp; This can make a big difference when large<BR>
&gt; far-flung polygons are being unioned - as is the case with this dataset.<BR>
&gt;<BR>
&gt; Not sure if you can use this technique in your algorithm - seems like it<BR>
&gt; might be tricky to express in SQL.<BR>
&gt;<BR>
&gt; Obe, Regina wrote:<BR>
&gt; &gt;<BR>
&gt; &gt; Try this set.&nbsp; - this has 2895 records<BR>
&gt; &gt;<BR>
&gt; &gt; My timings are<BR>
&gt; &gt; ---time 161,047 ms = SELECT 161047/1000.0/60 = 2.68 minutes<BR>
&gt; &gt; SELECT ST_CascadeUnion(the_geom)<BR>
&gt; &gt; from usstatebounds;<BR>
&gt; &gt;<BR>
&gt; &gt; --time 121719 ms = SELECT 121719/1000.0/60 = 2.02 minutes<BR>
&gt; &gt; SELECT st_unitecascade_garray_sort(ARRAY(SELECT the_geom FROM<BR>
&gt; &gt; usstatebounds));<BR>
&gt; &gt;<BR>
&gt; &gt; In OJ - it gets to the last round and then fails with a Java out of<BR>
&gt; &gt; Heap space error.<BR>
&gt; &gt;<BR>
&gt; &gt;<BR>
&gt; &gt; ------------------------------------------------------------------------<BR>
&gt; &gt;<BR>
&gt; &gt; *The substance of this message, including any attachments, may be<BR>
&gt; &gt; confidential, legally privileged and/or exempt from disclosure<BR>
&gt; &gt; pursuant to Massachusetts law. It is intended solely for the<BR>
&gt; &gt; addressee. If you received this in error, please contact the sender<BR>
&gt; &gt; and delete the material from any computer. *<BR>
&gt; &gt;<BR>
&gt; &gt; ------------------------------------------------------------------------<BR>
&gt; &gt;<BR>
&gt; &gt; * Help make the earth a greener place. If at all possible resist<BR>
&gt; &gt; printing this email and join us in saving paper. *<BR>
&gt; &gt;<BR>
&gt; &gt; * *<BR>
&gt; &gt;<BR>
&gt; &gt; * *<BR>
&gt; &gt;<BR>
&gt; &gt; ------------------------------------------------------------------------<BR>
&gt; &gt;<BR>
&gt; &gt; _______________________________________________<BR>
&gt; &gt; postgis-devel mailing list<BR>
&gt; &gt; postgis-devel@postgis.refractions.net<BR>
&gt; &gt; <A HREF="http://postgis.refractions.net/mailman/listinfo/postgis-devel">http://postgis.refractions.net/mailman/listinfo/postgis-devel</A><BR>
&gt; &gt;&nbsp;<BR>
&gt;<BR>
&gt; --<BR>
&gt; Martin Davis<BR>
&gt; Senior Technical Architect<BR>
&gt; Refractions Research, Inc.<BR>
&gt; (250) 383-3022<BR>
&gt;<BR>
&gt; _______________________________________________<BR>
&gt; postgis-devel mailing list<BR>
&gt; postgis-devel@postgis.refractions.net<BR>
&gt; <A HREF="http://postgis.refractions.net/mailman/listinfo/postgis-devel">http://postgis.refractions.net/mailman/listinfo/postgis-devel</A><BR>
&gt;<BR>
&gt;<BR>
&gt; ------------------------------------------------------------------------<BR>
&gt;<BR>
&gt; _______________________________________________<BR>
&gt; postgis-devel mailing list<BR>
&gt; postgis-devel@postgis.refractions.net<BR>
&gt; <A HREF="http://postgis.refractions.net/mailman/listinfo/postgis-devel">http://postgis.refractions.net/mailman/listinfo/postgis-devel</A><BR>
&gt;&nbsp;&nbsp;<BR>
<BR>
--<BR>
Martin Davis<BR>
Senior Technical Architect<BR>
Refractions Research, Inc.<BR>
(250) 383-3022<BR>
<BR>
_______________________________________________<BR>
postgis-devel mailing list<BR>
postgis-devel@postgis.refractions.net<BR>
<A HREF="http://postgis.refractions.net/mailman/listinfo/postgis-devel">http://postgis.refractions.net/mailman/listinfo/postgis-devel</A><BR>
<BR>
<BR>
<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>