Favicon

Cascaded Union Aggregate function

For those people who have unions to do that are slow, feel free to try out
this aggregate union function.

I haven't tested it enough for it to make it into 1.3.4, but have included a
link to the source code in the wiki.  It should work just fine on PostGIS
versions 1.2.2 and above.

http://postgis.refractions.net/support/wiki/index.php?PL%2FPGSQL%20Pseudo%20
Cascade%20Union%20Aggregate%20Function

Let me know if you run into any problems with it.  It has worked well for
the samples I have used it on.

Thanks,
Regina
Favicon

RE: Cascaded Union Aggregate function


Oops sorry about that.

Just realized I had ugly spaces in the link.  I've changed it.  Use this one

http://postgis.refractions.net/support/wiki/index.php?upgis_cascadeunion

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Paragon
Corporation
Sent: Saturday, October 04, 2008 7:44 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Cascaded Union Aggregate function

For those people who have unions to do that are slow, feel free to try out
this aggregate union function.

I haven't tested it enough for it to make it into 1.3.4, but have included a
link to the source code in the wiki.  It should work just fine on PostGIS
versions 1.2.2 and above.

http://postgis.refractions.net/support/wiki/index.php?PL%2FPGSQL%20Pseudo%20
Cascade%20Union%20Aggregate%20Function

Let me know if you run into any problems with it.  It has worked well for
the samples I have used it on.

Thanks,
Regina
(Continue reading)

Dane Springmeyer | 5 Oct 07:47
Favicon

Re: Cascaded Union Aggregate function

Hi Regina,

Thank you so much for the wiki posting. I've been using your code from  
your august 12th email with great success, if not joy. What an amazing  
speed improvement, especially for such a critical function. This was  
your exact email of code I have working: http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003412.html

I've just downloaded the new code off the wiki, but I'm getting an  
error of 'Unknown Geometry Type: 0'. I'll paste the whole error below  
in case you have an idea what might be going on. I'm running mac 10.5  
with these details:

             postgis_version
---------------------------------------
  1.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

--------------------------------------------------------------
  PostgreSQL 8.3.3 on i386-apple-darwin9.4.0, compiled by GCC

Cheers,

Dane

-- full error:
test=# select upgis_cascadeunion(the_geom) from npsa group by  
wholedrain;

ERROR:  Unknown geometry type: 0
CONTEXT:  SQL function "upgis_dump_collect_garray" statement 1
(Continue reading)

Favicon

RE: Cascaded Union Aggregate function

Dane,
Dane,
Oops sorry about that .  I just posted a revised version.  Can you try that
out?  Thanks.

Also can you send me a sample of your data off list.  I think the issue was
I was experimenting with array_append vs. st_geom_accum and I had gotten the
error you described below, but then was unable to replicate it again.

It could be the detoasting affect of st_geom_accum that Mark had described
was the difference between the two. 

Thanks,
Regina

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane
Springmeyer
Sent: Sunday, October 05, 2008 1:47 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Hi Regina,

Thank you so much for the wiki posting. I've been using your code from your
august 12th email with great success, if not joy. What an amazing speed
improvement, especially for such a critical function. This was your exact
email of code I have working:
http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003412.ht
(Continue reading)

Dane Springmeyer | 5 Oct 18:41
Favicon

Re: Cascaded Union Aggregate function

You bet,

Here is the data: http://riverchange.org/opendatashare/north_pacific_watersheds.zip
And it is in this projection: http://spatialreference.org/ref/user/north-pacific-albers-conic-equal-area/

Dane

On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

> Dane,
> Dane,
> Oops sorry about that .  I just posted a revised version.  Can you  
> try that
> out?  Thanks.
>
> Also can you send me a sample of your data off list.  I think the  
> issue was
> I was experimenting with array_append vs. st_geom_accum and I had  
> gotten the
> error you described below, but then was unable to replicate it again.
>
> It could be the detoasting affect of st_geom_accum that Mark had  
> described
> was the difference between the two.
>
> Thanks,
> Regina
>
> -----Original Message-----
> From: postgis-users-bounces <at> postgis.refractions.net
(Continue reading)

Favicon

RE: Cascaded Union Aggregate function

Dane,

Thanks.  Did you try the revised version by chance and did it work or give
the same error? It's the same as before except replace st_append  with
st_geom_accum.

Anyrate I'll play around with this set of data you have provided.

Thanks,
Regina

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane
Springmeyer
Sent: Sunday, October 05, 2008 12:42 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

You bet,

Here is the data:
http://riverchange.org/opendatashare/north_pacific_watersheds.zip
And it is in this projection:
http://spatialreference.org/ref/user/north-pacific-albers-conic-equal-area/

Dane

On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

(Continue reading)

Dane Springmeyer | 5 Oct 18:58
Favicon

Re: Cascaded Union Aggregate function

Regina,

Great, my query now works with your amended upgis function posting.

So, here are my timing outputs for the dataset on watersheds I just sent a reference to:

select count(*) from npsa;
--3162 records

select st_cascadeunion(the_geom) from npsa group by wholedrain;
-- 48.39 sec

select upgis_cascadeunion(the_geom) from npsa group by wholedrain;
-- 50.91 sec

select ST_Union(the_geom) from npsa group by wholedrain;
-- 2.49 minutes

select ST_Collect(the_geom) from npsa group by wholedrain;
-- 10.73 seconds

Next chance I get I'll take a look at the actual results.

Thanks!
Dane


On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

Dane,
Dane,
Oops sorry about that .  I just posted a revised version.  Can you try that
out?  Thanks.

Also can you send me a sample of your data off list.  I think the issue was
I was experimenting with array_append vs. st_geom_accum and I had gotten the
error you described below, but then was unable to replicate it again.

It could be the detoasting affect of st_geom_accum that Mark had described
was the difference between the two.

Thanks,
Regina

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane
Springmeyer
Sent: Sunday, October 05, 2008 1:47 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Hi Regina,

Thank you so much for the wiki posting. I've been using your code from your
august 12th email with great success, if not joy. What an amazing speed
improvement, especially for such a critical function. This was your exact
email of code I have working:
http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003412.ht
ml

I've just downloaded the new code off the wiki, but I'm getting an error of
'Unknown Geometry Type: 0'. I'll paste the whole error below in case you
have an idea what might be going on. I'm running mac 10.5 with these
details:

            postgis_version
---------------------------------------
 1.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

--------------------------------------------------------------
 PostgreSQL 8.3.3 on i386-apple-darwin9.4.0, compiled by GCC


Cheers,

Dane


-- full error:
test=# select upgis_cascadeunion(the_geom) from npsa group by wholedrain;

ERROR:  Unknown geometry type: 0
CONTEXT:  SQL function "upgis_dump_collect_garray" statement 1
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [s] As geom FROM
generate_series(1,  $2 ) As s WHERE NOT (s = ANY( $3 )) ),  
st_unite_garray(ARRAY(SELECT  $1 [s] As geom FROM generate_series(1,   
$2 ) As s WHERE s = ANY( $3 ) ) ) ) )"
PL/pgSQL function "st_collect_unite_garray" line 29 at assignment SQL
statement "SELECT  upgis_unitecascade_garray(ARRAY(SELECT
st_collect_unite_garray( $1 [i:least(i +  $2  - 1, $3 )]) As geom FROM
generate_series(1,  $3 , $2 ) As i),  $4  + 1,  $5 , false)"
PL/pgSQL function "upgis_unitecascade_garray" line 48 at assignment
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [ $2 [s]] As geom
FROM generate_series(1, array_upper( $2 ,1)) As s ),
upgis_unitecascade_garray(ARRAY(SELECT  $1 [s] As geom FROM  
generate_series(1,  $3 ) As s WHERE NOT (s = ANY( $2 )) ),  $4  + 1,   
$5 , true) ) )"
PL/pgSQL function "upgis_unitecascade_garray" line 33 at assignment SQL
function "upgis_unitecascade_garray_sort" statement 1


On Oct 4, 2008, at 4:53 PM, Paragon Corporation wrote:


Oops sorry about that.

Just realized I had ugly spaces in the link.  I've changed it.  Use
this one

http://postgis.refractions.net/support/wiki/index.php?upgis_cascadeuni
on

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of
Paragon Corporation
Sent: Saturday, October 04, 2008 7:44 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Cascaded Union Aggregate function

For those people who have unions to do that are slow, feel free to try
out this aggregate union function.

I haven't tested it enough for it to make it into 1.3.4, but have
included a link to the source code in the wiki.  It should work just
fine on PostGIS versions 1.2.2 and above.

http://postgis.refractions.net/support/wiki/index.php?PL%2FPGSQL%20Pse
udo%20 Cascade%20Union%20Aggregate%20Function

Let me know if you run into any problems with it.  It has worked well
for the samples I have used it on.

Thanks,
Regina


_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Favicon

RE: Cascaded Union Aggregate function

Dane,
 
Nice to hear.  I ran on your set too, but ran thru the whole thing
 
SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa_albers
 
Took SELECT 259329/1000.0/60 ms => 4.322 minutes
 
N Points after = 163,612;
N Points Before = 1,069,320;
 
I was afraid to try this using the current ST_Union (you remember by chance how long your below takes with ST_Union?)
 
I tried unioning the shape in OpenJump version that has the cascade union and it took about 5 minutes. 
 
I'll have to try that again since in all the tests
I have run OpenJump has always been faster (unfortunately where I am at the moment, my PostgreSQL is running on server and OpenJump with shape locally, so that may not have been a fair test).  But it seems to end up with the same number of points of 163,612.
 
Thanks,
Regina
 
 
 
 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Sunday, October 05, 2008 12:59 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Great, my query now works with your amended upgis function posting.

So, here are my timing outputs for the dataset on watersheds I just sent a reference to:

select count(*) from npsa;
--3162 records

select st_cascadeunion(the_geom) from npsa group by wholedrain;
-- 48.39 sec

select upgis_cascadeunion(the_geom) from npsa group by wholedrain;
-- 50.91 sec

select ST_Union(the_geom) from npsa group by wholedrain;
-- 2.49 minutes

select ST_Collect(the_geom) from npsa group by wholedrain;
-- 10.73 seconds

Next chance I get I'll take a look at the actual results.

Thanks!
Dane


On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

Dane,
Dane,
Oops sorry about that .  I just posted a revised version.  Can you try that
out?  Thanks.

Also can you send me a sample of your data off list.  I think the issue was
I was experimenting with array_append vs. st_geom_accum and I had gotten the
error you described below, but then was unable to replicate it again.

It could be the detoasting affect of st_geom_accum that Mark had described
was the difference between the two.

Thanks,
Regina

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane
Springmeyer
Sent: Sunday, October 05, 2008 1:47 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Hi Regina,

Thank you so much for the wiki posting. I've been using your code from your
august 12th email with great success, if not joy. What an amazing speed
improvement, especially for such a critical function. This was your exact
email of code I have working:
http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003412.ht
ml

I've just downloaded the new code off the wiki, but I'm getting an error of
'Unknown Geometry Type: 0'. I'll paste the whole error below in case you
have an idea what might be going on. I'm running mac 10.5 with these
details:

            postgis_version
---------------------------------------
 1.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

--------------------------------------------------------------
 PostgreSQL 8.3.3 on i386-apple-darwin9.4.0, compiled by GCC


Cheers,

Dane


-- full error:
test=# select upgis_cascadeunion(the_geom) from npsa group by wholedrain;

ERROR:  Unknown geometry type: 0
CONTEXT:  SQL function "upgis_dump_collect_garray" statement 1
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [s] As geom FROM
generate_series(1,  $2 ) As s WHERE NOT (s = ANY( $3 )) ),  
st_unite_garray(ARRAY(SELECT  $1 [s] As geom FROM generate_series(1,   
$2 ) As s WHERE s = ANY( $3 ) ) ) ) )"
PL/pgSQL function "st_collect_unite_garray" line 29 at assignment SQL
statement "SELECT  upgis_unitecascade_garray(ARRAY(SELECT
st_collect_unite_garray( $1 [i:least(i +  $2  - 1, $3 )]) As geom FROM
generate_series(1,  $3 , $2 ) As i),  $4  + 1,  $5 , false)"
PL/pgSQL function "upgis_unitecascade_garray" line 48 at assignment
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [ $2 [s]] As geom
FROM generate_series(1, array_upper( $2 ,1)) As s ),
upgis_unitecascade_garray(ARRAY(SELECT  $1 [s] As geom FROM  
generate_series(1,  $3 ) As s WHERE NOT (s = ANY( $2 )) ),  $4  + 1,   
$5 , true) ) )"
PL/pgSQL function "upgis_unitecascade_garray" line 33 at assignment SQL
function "upgis_unitecascade_garray_sort" statement 1


On Oct 4, 2008, at 4:53 PM, Paragon Corporation wrote:


Oops sorry about that.

Just realized I had ugly spaces in the link.  I've changed it.  Use
this one

http://postgis.refractions.net/support/wiki/index.php?upgis_cascadeuni
on

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of
Paragon Corporation
Sent: Saturday, October 04, 2008 7:44 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Cascaded Union Aggregate function

For those people who have unions to do that are slow, feel free to try
out this aggregate union function.

I haven't tested it enough for it to make it into 1.3.4, but have
included a link to the source code in the wiki.  It should work just
fine on PostGIS versions 1.2.2 and above.

http://postgis.refractions.net/support/wiki/index.php?PL%2FPGSQL%20Pse
udo%20 Cascade%20Union%20Aggregate%20Function

Let me know if you run into any problems with it.  It has worked well
for the samples I have used it on.

Thanks,
Regina


_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Dane Springmeyer | 6 Oct 07:11
Favicon

Re: Cascaded Union Aggregate function

Regina,

Okay, I've finished running your fuller test query included on the wiki.

Both of the variations on your cascade union timed the same, and astonishingly faster that ST_Union:


SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
-- 4.05 minutes
-- points before = 163612
-- points after = 1069320

SELECT ST_NPoints(ST_Union(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
--161.85 min
-- points before = 163612
-- points after = 1069320

SELECT ST_NPoints(st_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
-- 4.06 minutes
-- points before = 163612
-- points after = 1069320



Dane



On Oct 5, 2008, at 10:29 AM, Paragon Corporation wrote:

Dane,
 
Nice to hear.  I ran on your set too, but ran thru the whole thing
 
SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa_albers
 
Took SELECT 259329/1000.0/60 ms => 4.322 minutes
 
N Points after = 163,612;
N Points Before = 1,069,320;
 
I was afraid to try this using the current ST_Union (you remember by chance how long your below takes with ST_Union?)
 
I tried unioning the shape in OpenJump version that has the cascade union and it took about 5 minutes. 
 
I'll have to try that again since in all the tests
I have run OpenJump has always been faster (unfortunately where I am at the moment, my PostgreSQL is running on server and OpenJump with shape locally, so that may not have been a fair test).  But it seems to end up with the same number of points of 163,612.
 
Thanks,
Regina
 
 
 
 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Sunday, October 05, 2008 12:59 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Great, my query now works with your amended upgis function posting.

So, here are my timing outputs for the dataset on watersheds I just sent a reference to:

select count(*) from npsa;
--3162 records

select st_cascadeunion(the_geom) from npsa group by wholedrain;
-- 48.39 sec

select upgis_cascadeunion(the_geom) from npsa group by wholedrain;
-- 50.91 sec

select ST_Union(the_geom) from npsa group by wholedrain;
-- 2.49 minutes

select ST_Collect(the_geom) from npsa group by wholedrain;
-- 10.73 seconds

Next chance I get I'll take a look at the actual results.

Thanks!
Dane


On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

Dane,
Dane,
Oops sorry about that .  I just posted a revised version.  Can you try that
out?  Thanks.

Also can you send me a sample of your data off list.  I think the issue was
I was experimenting with array_append vs. st_geom_accum and I had gotten the
error you described below, but then was unable to replicate it again.

It could be the detoasting affect of st_geom_accum that Mark had described
was the difference between the two.

Thanks,
Regina

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane
Springmeyer
Sent: Sunday, October 05, 2008 1:47 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Hi Regina,

Thank you so much for the wiki posting. I've been using your code from your
august 12th email with great success, if not joy. What an amazing speed
improvement, especially for such a critical function. This was your exact
email of code I have working:
http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003412.ht
ml

I've just downloaded the new code off the wiki, but I'm getting an error of
'Unknown Geometry Type: 0'. I'll paste the whole error below in case you
have an idea what might be going on. I'm running mac 10.5 with these
details:

            postgis_version
---------------------------------------
 1.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

--------------------------------------------------------------
 PostgreSQL 8.3.3 on i386-apple-darwin9.4.0, compiled by GCC


Cheers,

Dane


-- full error:
test=# select upgis_cascadeunion(the_geom) from npsa group by wholedrain;

ERROR:  Unknown geometry type: 0
CONTEXT:  SQL function "upgis_dump_collect_garray" statement 1
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [s] As geom FROM
generate_series(1,  $2 ) As s WHERE NOT (s = ANY( $3 )) ),  
st_unite_garray(ARRAY(SELECT  $1 [s] As geom FROM generate_series(1,   
$2 ) As s WHERE s = ANY( $3 ) ) ) ) )"
PL/pgSQL function "st_collect_unite_garray" line 29 at assignment SQL
statement "SELECT  upgis_unitecascade_garray(ARRAY(SELECT
st_collect_unite_garray( $1 [i:least(i +  $2  - 1, $3 )]) As geom FROM
generate_series(1,  $3 , $2 ) As i),  $4  + 1,  $5 , false)"
PL/pgSQL function "upgis_unitecascade_garray" line 48 at assignment
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [ $2 [s]] As geom
FROM generate_series(1, array_upper( $2 ,1)) As s ),
upgis_unitecascade_garray(ARRAY(SELECT  $1 [s] As geom FROM  
generate_series(1,  $3 ) As s WHERE NOT (s = ANY( $2 )) ),  $4  + 1,   
$5 , true) ) )"
PL/pgSQL function "upgis_unitecascade_garray" line 33 at assignment SQL
function "upgis_unitecascade_garray_sort" statement 1


On Oct 4, 2008, at 4:53 PM, Paragon Corporation wrote:


Oops sorry about that.

Just realized I had ugly spaces in the link.  I've changed it.  Use
this one

http://postgis.refractions.net/support/wiki/index.php?upgis_cascadeuni
on

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of
Paragon Corporation
Sent: Saturday, October 04, 2008 7:44 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Cascaded Union Aggregate function

For those people who have unions to do that are slow, feel free to try
out this aggregate union function.

I haven't tested it enough for it to make it into 1.3.4, but have
included a link to the source code in the wiki.  It should work just
fine on PostGIS versions 1.2.2 and above.

http://postgis.refractions.net/support/wiki/index.php?PL%2FPGSQL%20Pse
udo%20 Cascade%20Union%20Aggregate%20Function

Let me know if you run into any problems with it.  It has worked well
for the samples I have used it on.

Thanks,
Regina


_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Favicon

RE: Cascaded Union Aggregate function

Dan,
 
Disregard my last email except the OpenJump part.  I was reading out of order.
 
Thanks,
Regina

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Monday, October 06, 2008 1:12 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Okay, I've finished running your fuller test query included on the wiki.

Both of the variations on your cascade union timed the same, and astonishingly faster that ST_Union:


SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
-- 4.05 minutes
-- points before = 163612
-- points after = 1069320

SELECT ST_NPoints(ST_Union(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
--161.85 min
-- points before = 163612
-- points after = 1069320

SELECT ST_NPoints(st_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
-- 4.06 minutes
-- points before = 163612
-- points after = 1069320



Dane



On Oct 5, 2008, at 10:29 AM, Paragon Corporation wrote:

Dane,
 
Nice to hear.  I ran on your set too, but ran thru the whole thing
 
SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa_albers
 
Took SELECT 259329/1000.0/60 ms => 4.322 minutes
 
N Points after = 163,612;
N Points Before = 1,069,320;
 
I was afraid to try this using the current ST_Union (you remember by chance how long your below takes with ST_Union?)
 
I tried unioning the shape in OpenJump version that has the cascade union and it took about 5 minutes. 
 
I'll have to try that again since in all the tests
I have run OpenJump has always been faster (unfortunately where I am at the moment, my PostgreSQL is running on server and OpenJump with shape locally, so that may not have been a fair test).  But it seems to end up with the same number of points of 163,612.
 
Thanks,
Regina
 
 
 
 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Sunday, October 05, 2008 12:59 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Great, my query now works with your amended upgis function posting.

So, here are my timing outputs for the dataset on watersheds I just sent a reference to:

select count(*) from npsa;
--3162 records

select st_cascadeunion(the_geom) from npsa group by wholedrain;
-- 48.39 sec

select upgis_cascadeunion(the_geom) from npsa group by wholedrain;
-- 50.91 sec

select ST_Union(the_geom) from npsa group by wholedrain;
-- 2.49 minutes

select ST_Collect(the_geom) from npsa group by wholedrain;
-- 10.73 seconds

Next chance I get I'll take a look at the actual results.

Thanks!
Dane


On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

Dane,
Dane,
Oops sorry about that .  I just posted a revised version.  Can you try that
out?  Thanks.

Also can you send me a sample of your data off list.  I think the issue was
I was experimenting with array_append vs. st_geom_accum and I had gotten the
error you described below, but then was unable to replicate it again.

It could be the detoasting affect of st_geom_accum that Mark had described
was the difference between the two.

Thanks,
Regina

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane
Springmeyer
Sent: Sunday, October 05, 2008 1:47 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Hi Regina,

Thank you so much for the wiki posting. I've been using your code from your
august 12th email with great success, if not joy. What an amazing speed
improvement, especially for such a critical function. This was your exact
email of code I have working:
http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003412.ht
ml

I've just downloaded the new code off the wiki, but I'm getting an error of
'Unknown Geometry Type: 0'. I'll paste the whole error below in case you
have an idea what might be going on. I'm running mac 10.5 with these
details:

            postgis_version
---------------------------------------
 1.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

--------------------------------------------------------------
 PostgreSQL 8.3.3 on i386-apple-darwin9.4.0, compiled by GCC


Cheers,

Dane


-- full error:
test=# select upgis_cascadeunion(the_geom) from npsa group by wholedrain;

ERROR:  Unknown geometry type: 0
CONTEXT:  SQL function "upgis_dump_collect_garray" statement 1
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [s] As geom FROM
generate_series(1,  $2 ) As s WHERE NOT (s = ANY( $3 )) ),  
st_unite_garray(ARRAY(SELECT  $1 [s] As geom FROM generate_series(1,   
$2 ) As s WHERE s = ANY( $3 ) ) ) ) )"
PL/pgSQL function "st_collect_unite_garray" line 29 at assignment SQL
statement "SELECT  upgis_unitecascade_garray(ARRAY(SELECT
st_collect_unite_garray( $1 [i:least(i +  $2  - 1, $3 )]) As geom FROM
generate_series(1,  $3 , $2 ) As i),  $4  + 1,  $5 , false)"
PL/pgSQL function "upgis_unitecascade_garray" line 48 at assignment
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [ $2 [s]] As geom
FROM generate_series(1, array_upper( $2 ,1)) As s ),
upgis_unitecascade_garray(ARRAY(SELECT  $1 [s] As geom FROM  
generate_series(1,  $3 ) As s WHERE NOT (s = ANY( $2 )) ),  $4  + 1,   
$5 , true) ) )"
PL/pgSQL function "upgis_unitecascade_garray" line 33 at assignment SQL
function "upgis_unitecascade_garray_sort" statement 1


On Oct 4, 2008, at 4:53 PM, Paragon Corporation wrote:


Oops sorry about that.

Just realized I had ugly spaces in the link.  I've changed it.  Use
this one

http://postgis.refractions.net/support/wiki/index.php?upgis_cascadeuni
on

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of
Paragon Corporation
Sent: Saturday, October 04, 2008 7:44 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Cascaded Union Aggregate function

For those people who have unions to do that are slow, feel free to try
out this aggregate union function.

I haven't tested it enough for it to make it into 1.3.4, but have
included a link to the source code in the wiki.  It should work just
fine on PostGIS versions 1.2.2 and above.

http://postgis.refractions.net/support/wiki/index.php?PL%2FPGSQL%20Pse
udo%20 Cascade%20Union%20Aggregate%20Function

Let me know if you run into any problems with it.  It has worked well
for the samples I have used it on.

Thanks,
Regina


_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Obe, Regina | 6 Oct 13:02
Favicon

RE: Cascaded Union Aggregate function

Dane,
 
I just ran the full union set in OpenJump and it took 55 seconds. 
 
Running your below for me with the OpenJump that contains the Cascade Union functionality takes 30 seconds.
 
So don't know what was wrong with the other pc I was on.  Maybe I had too much going on or there is something flawed with the snapshot I was using on that box (it was definitely cascade union though because the non-cascade one has a count down and ran out of memory when trying to do the whole set).  OpenJump cascade union still wins hands down :).
 
I tried unioning on this same box with my PostGIS install for good comparison and my timings for the
 
--69 secs
select upgis_cascadeunion(the_geom) from npsa_albers group by wholedrain;
 
and
--  61 secs
select ST_NPoints(upgis_cascadeunion(the_geom)) from npsa_albers group by wholedrain;
 
I'm going to assume its a bit slower on this box because I haven't tweaked my postgresql.conf on this machine.
 
Next I'll test on my linux 1.3.4 SVN install.
 
Thanks,
Regina
 
 
 
 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Paragon Corporation
Sent: Monday, October 06, 2008 5:30 AM
To: 'PostGIS Users Discussion'
Subject: RE: [postgis-users] Cascaded Union Aggregate function

Dan,
 
Disregard my last email except the OpenJump part.  I was reading out of order.
 
Thanks,
Regina

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Monday, October 06, 2008 1:12 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Okay, I've finished running your fuller test query included on the wiki.

Both of the variations on your cascade union timed the same, and astonishingly faster that ST_Union:


SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
-- 4.05 minutes
-- points before = 163612
-- points after = 1069320

SELECT ST_NPoints(ST_Union(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
--161.85 min
-- points before = 163612
-- points after = 1069320

SELECT ST_NPoints(st_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
-- 4.06 minutes
-- points before = 163612
-- points after = 1069320



Dane



On Oct 5, 2008, at 10:29 AM, Paragon Corporation wrote:

Dane,
 
Nice to hear.  I ran on your set too, but ran thru the whole thing
 
SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa_albers
 
Took SELECT 259329/1000.0/60 ms => 4.322 minutes
 
N Points after = 163,612;
N Points Before = 1,069,320;
 
I was afraid to try this using the current ST_Union (you remember by chance how long your below takes with ST_Union?)
 
I tried unioning the shape in OpenJump version that has the cascade union and it took about 5 minutes. 
 
I'll have to try that again since in all the tests
I have run OpenJump has always been faster (unfortunately where I am at the moment, my PostgreSQL is running on server and OpenJump with shape locally, so that may not have been a fair test).  But it seems to end up with the same number of points of 163,612.
 
Thanks,
Regina
 
 
 
 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Sunday, October 05, 2008 12:59 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Great, my query now works with your amended upgis function posting.

So, here are my timing outputs for the dataset on watersheds I just sent a reference to:

select count(*) from npsa;
--3162 records

select st_cascadeunion(the_geom) from npsa group by wholedrain;
-- 48.39 sec

select upgis_cascadeunion(the_geom) from npsa group by wholedrain;
-- 50.91 sec

select ST_Union(the_geom) from npsa group by wholedrain;
-- 2.49 minutes

select ST_Collect(the_geom) from npsa group by wholedrain;
-- 10.73 seconds

Next chance I get I'll take a look at the actual results.

Thanks!
Dane


On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

Dane,
Dane,
Oops sorry about that .  I just posted a revised version.  Can you try that
out?  Thanks.

Also can you send me a sample of your data off list.  I think the issue was
I was experimenting with array_append vs. st_geom_accum and I had gotten the
error you described below, but then was unable to replicate it again.

It could be the detoasting affect of st_geom_accum that Mark had described
was the difference between the two.

Thanks,
Regina

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane
Springmeyer
Sent: Sunday, October 05, 2008 1:47 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Hi Regina,

Thank you so much for the wiki posting. I've been using your code from your
august 12th email with great success, if not joy. What an amazing speed
improvement, especially for such a critical function. This was your exact
email of code I have working:
http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003412.ht
ml

I've just downloaded the new code off the wiki, but I'm getting an error of
'Unknown Geometry Type: 0'. I'll paste the whole error below in case you
have an idea what might be going on. I'm running mac 10.5 with these
details:

            postgis_version
---------------------------------------
 1.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

--------------------------------------------------------------
 PostgreSQL 8.3.3 on i386-apple-darwin9.4.0, compiled by GCC


Cheers,

Dane


-- full error:
test=# select upgis_cascadeunion(the_geom) from npsa group by wholedrain;

ERROR:  Unknown geometry type: 0
CONTEXT:  SQL function "upgis_dump_collect_garray" statement 1
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [s] As geom FROM
generate_series(1,  $2 ) As s WHERE NOT (s = ANY( $3 )) ),  
st_unite_garray(ARRAY(SELECT  $1 [s] As geom FROM generate_series(1,   
$2 ) As s WHERE s = ANY( $3 ) ) ) ) )"
PL/pgSQL function "st_collect_unite_garray" line 29 at assignment SQL
statement "SELECT  upgis_unitecascade_garray(ARRAY(SELECT
st_collect_unite_garray( $1 [i:least(i +  $2  - 1, $3 )]) As geom FROM
generate_series(1,  $3 , $2 ) As i),  $4  + 1,  $5 , false)"
PL/pgSQL function "upgis_unitecascade_garray" line 48 at assignment
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [ $2 [s]] As geom
FROM generate_series(1, array_upper( $2 ,1)) As s ),
upgis_unitecascade_garray(ARRAY(SELECT  $1 [s] As geom FROM  
generate_series(1,  $3 ) As s WHERE NOT (s = ANY( $2 )) ),  $4  + 1,   
$5 , true) ) )"
PL/pgSQL function "upgis_unitecascade_garray" line 33 at assignment SQL
function "upgis_unitecascade_garray_sort" statement 1


On Oct 4, 2008, at 4:53 PM, Paragon Corporation wrote:


Oops sorry about that.

Just realized I had ugly spaces in the link.  I've changed it.  Use
this one

http://postgis.refractions.net/support/wiki/index.php?upgis_cascadeuni
on

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of
Paragon Corporation
Sent: Saturday, October 04, 2008 7:44 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Cascaded Union Aggregate function

For those people who have unions to do that are slow, feel free to try
out this aggregate union function.

I haven't tested it enough for it to make it into 1.3.4, but have
included a link to the source code in the wiki.  It should work just
fine on PostGIS versions 1.2.2 and above.

http://postgis.refractions.net/support/wiki/index.php?PL%2FPGSQL%20Pse
udo%20 Cascade%20Union%20Aggregate%20Function

Let me know if you run into any problems with it.  It has worked well
for the samples I have used it on.

Thanks,
Regina


_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

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.

Help make the earth a greener place. If at all possible resist printing this email and join us in saving paper.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Obe, Regina | 6 Oct 13:46
Favicon

RE: Cascaded Union Aggregate function

Okay I tried on my slightly tweaked OpenSUSE 10.3, 8.2.6, 1.3.4SVN, Geos 3.0.0 VM install.
 
SELECT  242014/1000.0/60 - 4.03 minutes
SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
 
--51.2 secs
SELECT wholedrain, ST_NPoints(upgis_cascadeunion(the_geom)) As numpoints
FROM npsa
GROUP BY wholedrain;
 
I'll have to retest with some of the other tables I've been testing when I have more time.
 
Thanks,
Regina

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Obe, Regina
Sent: Monday, October 06, 2008 7:02 AM
To: PostGIS Users Discussion
Subject: RE: [postgis-users] Cascaded Union Aggregate function

Dane,
 
I just ran the full union set in OpenJump and it took 55 seconds. 
 
Running your below for me with the OpenJump that contains the Cascade Union functionality takes 30 seconds.
 
So don't know what was wrong with the other pc I was on.  Maybe I had too much going on or there is something flawed with the snapshot I was using on that box (it was definitely cascade union though because the non-cascade one has a count down and ran out of memory when trying to do the whole set).  OpenJump cascade union still wins hands down :).
 
I tried unioning on this same box with my PostGIS install for good comparison and my timings for the
 
--69 secs
select upgis_cascadeunion(the_geom) from npsa_albers group by wholedrain;
 
and
--  61 secs
select ST_NPoints(upgis_cascadeunion(the_geom)) from npsa_albers group by wholedrain;
 
I'm going to assume its a bit slower on this box because I haven't tweaked my postgresql.conf on this machine.
 
Next I'll test on my linux 1.3.4 SVN install.
 
Thanks,
Regina
 
 
 
 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Paragon Corporation
Sent: Monday, October 06, 2008 5:30 AM
To: 'PostGIS Users Discussion'
Subject: RE: [postgis-users] Cascaded Union Aggregate function

Dan,
 
Disregard my last email except the OpenJump part.  I was reading out of order.
 
Thanks,
Regina

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Monday, October 06, 2008 1:12 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Okay, I've finished running your fuller test query included on the wiki.

Both of the variations on your cascade union timed the same, and astonishingly faster that ST_Union:


SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
-- 4.05 minutes
-- points before = 163612
-- points after = 1069320

SELECT ST_NPoints(ST_Union(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
--161.85 min
-- points before = 163612
-- points after = 1069320

SELECT ST_NPoints(st_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa;
-- 4.06 minutes
-- points before = 163612
-- points after = 1069320



Dane



On Oct 5, 2008, at 10:29 AM, Paragon Corporation wrote:

Dane,
 
Nice to hear.  I ran on your set too, but ran thru the whole thing
 
SELECT ST_NPoints(upgis_cascadeunion(the_geom)) As afterpoints, Sum(ST_NPoints(the_geom)) as beforepoints
FROM  npsa_albers
 
Took SELECT 259329/1000.0/60 ms => 4.322 minutes
 
N Points after = 163,612;
N Points Before = 1,069,320;
 
I was afraid to try this using the current ST_Union (you remember by chance how long your below takes with ST_Union?)
 
I tried unioning the shape in OpenJump version that has the cascade union and it took about 5 minutes. 
 
I'll have to try that again since in all the tests
I have run OpenJump has always been faster (unfortunately where I am at the moment, my PostgreSQL is running on server and OpenJump with shape locally, so that may not have been a fair test).  But it seems to end up with the same number of points of 163,612.
 
Thanks,
Regina
 
 
 
 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Sunday, October 05, 2008 12:59 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Great, my query now works with your amended upgis function posting.

So, here are my timing outputs for the dataset on watersheds I just sent a reference to:

select count(*) from npsa;
--3162 records

select st_cascadeunion(the_geom) from npsa group by wholedrain;
-- 48.39 sec

select upgis_cascadeunion(the_geom) from npsa group by wholedrain;
-- 50.91 sec

select ST_Union(the_geom) from npsa group by wholedrain;
-- 2.49 minutes

select ST_Collect(the_geom) from npsa group by wholedrain;
-- 10.73 seconds

Next chance I get I'll take a look at the actual results.

Thanks!
Dane


On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

Dane,
Dane,
Oops sorry about that .  I just posted a revised version.  Can you try that
out?  Thanks.

Also can you send me a sample of your data off list.  I think the issue was
I was experimenting with array_append vs. st_geom_accum and I had gotten the
error you described below, but then was unable to replicate it again.

It could be the detoasting affect of st_geom_accum that Mark had described
was the difference between the two.

Thanks,
Regina

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane
Springmeyer
Sent: Sunday, October 05, 2008 1:47 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Hi Regina,

Thank you so much for the wiki posting. I've been using your code from your
august 12th email with great success, if not joy. What an amazing speed
improvement, especially for such a critical function. This was your exact
email of code I have working:
http://postgis.refractions.net/pipermail/postgis-devel/2008-August/003412.ht
ml

I've just downloaded the new code off the wiki, but I'm getting an error of
'Unknown Geometry Type: 0'. I'll paste the whole error below in case you
have an idea what might be going on. I'm running mac 10.5 with these
details:

            postgis_version
---------------------------------------
 1.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

--------------------------------------------------------------
 PostgreSQL 8.3.3 on i386-apple-darwin9.4.0, compiled by GCC


Cheers,

Dane


-- full error:
test=# select upgis_cascadeunion(the_geom) from npsa group by wholedrain;

ERROR:  Unknown geometry type: 0
CONTEXT:  SQL function "upgis_dump_collect_garray" statement 1
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [s] As geom FROM
generate_series(1,  $2 ) As s WHERE NOT (s = ANY( $3 )) ),  
st_unite_garray(ARRAY(SELECT  $1 [s] As geom FROM generate_series(1,   
$2 ) As s WHERE s = ANY( $3 ) ) ) ) )"
PL/pgSQL function "st_collect_unite_garray" line 29 at assignment SQL
statement "SELECT  upgis_unitecascade_garray(ARRAY(SELECT
st_collect_unite_garray( $1 [i:least(i +  $2  - 1, $3 )]) As geom FROM
generate_series(1,  $3 , $2 ) As i),  $4  + 1,  $5 , false)"
PL/pgSQL function "upgis_unitecascade_garray" line 48 at assignment
SQL statement "SELECT   
upgis_dump_collect_garray( array_append(ARRAY(SELECT  $1 [ $2 [s]] As geom
FROM generate_series(1, array_upper( $2 ,1)) As s ),
upgis_unitecascade_garray(ARRAY(SELECT  $1 [s] As geom FROM  
generate_series(1,  $3 ) As s WHERE NOT (s = ANY( $2 )) ),  $4  + 1,   
$5 , true) ) )"
PL/pgSQL function "upgis_unitecascade_garray" line 33 at assignment SQL
function "upgis_unitecascade_garray_sort" statement 1


On Oct 4, 2008, at 4:53 PM, Paragon Corporation wrote:


Oops sorry about that.

Just realized I had ugly spaces in the link.  I've changed it.  Use
this one

http://postgis.refractions.net/support/wiki/index.php?upgis_cascadeuni
on

-----Original Message-----
From: postgis-users-bounces <at> postgis.refractions.net
[mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of
Paragon Corporation
Sent: Saturday, October 04, 2008 7:44 PM
To: 'PostGIS Users Discussion'
Subject: [postgis-users] Cascaded Union Aggregate function

For those people who have unions to do that are slow, feel free to try
out this aggregate union function.

I haven't tested it enough for it to make it into 1.3.4, but have
included a link to the source code in the wiki.  It should work just
fine on PostGIS versions 1.2.2 and above.

http://postgis.refractions.net/support/wiki/index.php?PL%2FPGSQL%20Pse
udo%20 Cascade%20Union%20Aggregate%20Function

Let me know if you run into any problems with it.  It has worked well
for the samples I have used it on.

Thanks,
Regina


_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

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.

Help make the earth a greener place. If at all possible resist printing this email and join us in saving paper.

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.

Help make the earth a greener place. If at all possible resist printing this email and join us in saving paper.

_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Dane Springmeyer | 6 Oct 21:49
Favicon

Re: Cascaded Union Aggregate function


On Oct 6, 2008, at 4:02 AM, Obe, Regina wrote:

Dane,
 
I just ran the full union set in OpenJump and it took 55 seconds. 
 

Yes, 42 seconds for the full union. wow.

Running your below for me with the OpenJump that contains the Cascade Union functionality takes 30 seconds.

Yes, 32 seconds here.



Dane


_______________________________________________
postgis-users mailing list
postgis-users <at> postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Dane Springmeyer | 6 Oct 07:46
Favicon

Re: Cascaded Union Aggregate function

Regina,


On Oct 5, 2008, at 10:29 AM, Paragon Corporation wrote:

 
I was afraid to try this using the current ST_Union (you remember by chance how long your below takes with ST_Union?)
 

Oh, I missed addressing this question in my last email. Yes, I indicated how long ST_Union took below (it took 2.49 minutes).

I tried unioning the shape in OpenJump version that has the cascade union and it took about 5 minutes. 


I've never used  OpenJump  before but just loaded it up and went  to TOOLS> Analysis > Union by attribute value. Then I ran that tool with all the options checked using the same attribute field of 'wholedrain'.

I figure this is the equivalent of this query: 'select upgis_cascadeunion(the_geom) from npsa group by wholedrain' which ran in 50.91 seconds. The OpenJump query took 46.3 seconds.


Cheers,

Dane


 
I'll have to try that again since in all the tests
I have run OpenJump has always been faster (unfortunately where I am at the moment, my PostgreSQL is running on server and OpenJump with shape locally, so that may not have been a fair test).  But it seems to end up with the same number of points of 163,612.
 
Thanks,
Regina
 
 
 
 

From: postgis-users-bounces <at> postgis.refractions.net [mailto:postgis-users-bounces <at> postgis.refractions.net] On Behalf Of Dane Springmeyer
Sent: Sunday, October 05, 2008 12:59 PM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Cascaded Union Aggregate function

Regina,

Great, my query now works with your amended upgis function posting.

So, here are my timing outputs for the dataset on watersheds I just sent a reference to:

select count(*) from npsa;
--3162 records

select st_cascadeunion(the_geom) from npsa group by wholedrain;
-- 48.39 sec

select upgis_cascadeunion(the_geom) from npsa group by wholedrain;
-- 50.91 sec

select ST_Union(the_geom) from npsa group by wholedrain;
-- 2.49 minutes

select ST_Collect(the_geom) from npsa group by wholedrain;
-- 10.73 seconds

Next chance I get I'll take a look at the actual results.

Thanks!
Dane


On Oct 5, 2008, at 5:53 AM, Paragon Corporation wrote:

Dane,
Dane,
Oops sorry about that .  I just posted a revised version.  Can you try that
out?  Thanks.

Also can you send me a sample of your data off list.  I think the issue was
I was experimenting with array_append vs. st_geom_accum and I had gotten the
error you described below, but then was unable to replicate it again.

It could be the detoasting affect of st_geom_accum that Mark had described
was the diffe