| 1 | The Pseudo Cascade Union aggregate function is intended as a drop in replacement |
| 2 | for the current PostGIS ST_Union aggregate function. It should work in PostGIS versions |
| 3 | 1.2.2 -- 1.3.4. Although I have only tested on 1.3.3 and 1.3.4SVN. Seems to work in general 5-10 times faster than built in ST_Union, but I haven't really hammered it to ensure |
| 4 | it achieves the desired result in all cases. |
| 5 | |
| 6 | In general I have found it to be 5-10 times faster than the built-in ST_Union aggregate function and also it finishes to completion in many cases where the built-in one runs out of memory. |
| 7 | |
| 8 | The code can be downloaded from [http://www.bostongis.com/downloads/upgis_cascadeunion_functions_plpgsql.zip | http://www.bostongis.com/downloads/upgis_cascadeunion_functions_plpgsql.zip] |
| 9 | |
| 10 | It is loosely based on the concepts used in JTS 1.9 Union Operator (aka Cascaded Union) which is described at |
| 11 | |
| 12 | [http://lin-ear-th-inking.blogspot.com/2007/11/fast-polygon-merging-in-jts-using.html | http://lin-ear-th-inking.blogspot.com/2007/11/fast-polygon-merging-in-jts-using.html] |
| 13 | |
| 14 | Example use: |
| 15 | |
| 16 | This completes in 47,578 ms = 0.75 minutes |
| 17 | |
| 18 | |
| 19 | {{{ |
| 20 | SELECT state, upgis_cascadeunion(the_geom) as new_geom, |
| 21 | SUM(ST_NPoints(the_geom)) As numpointsbefore, |
| 22 | ST_NPoints(upgis_cascadeunion(the_geom)) As numpointsafter |
| 23 | FROM usstatebounds |
| 24 | GROUP BY state |
| 25 | ORDER BY state; |
| 26 | |
| 27 | }}} |
| 28 | |
| 29 | |
| 30 | vs. Original ST_Union version - 830,625 (13.8 minutes) |
| 31 | |
| 32 | {{{ |
| 33 | |
| 34 | SELECT state, ST_Union(the_geom) as the_geom, |
| 35 | SUM(ST_NPoints(the_geom)) As numpointsbefore, |
| 36 | ST_NPoints(ST_Union(the_geom)) As numpointsafter |
| 37 | FROM usstatebounds |
| 38 | GROUP BY state |
| 39 | ORDER BY state; |
| 40 | |
| 41 | }}} |