<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">Negative, i tried that with the below as the function declaration to no avail.&nbsp; The handle all higher levels section isn't finding anything in the arrays.&nbsp; Anyone else have a suggestion on how to store data within a function without creating a temporary table?<br><br>Curtis<br><br>CREATE OR REPLACE FUNCTION intersection_all(in_polys geometry, OUT id int, OUT intersection_count int, OUT the_geom geometry)<br>&nbsp; RETURNS SETOF record AS<br>$BODY$<br>DECLARE<br>&nbsp;&nbsp;&nbsp; total_count int := 0;<br>&nbsp;&nbsp;&nbsp; current_level_count int := 0;<br>&nbsp;&nbsp;&nbsp; first_id_of_previous_level int := 0;<br>&nbsp;&nbsp;&nbsp; last_id_of_previous_level int:= 0;<br>&nbsp;&nbsp;&nbsp; num_intersections int[];<br>&nbsp;&nbsp;&nbsp; geometries
 geometry[];<br>BEGIN<br>&nbsp;&nbsp;&nbsp; -- handle level one by adding all input polygons<br>&nbsp;&nbsp;&nbsp; FOR i IN 1..NumGeometries(in_polys) LOOP<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; the_geom := GeometryN(in_polys,i);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; intersection_count := 1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; geometries := array_append(geometries, the_geom);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num_intersections := array_append(num_intersections, intersection_count);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; last_id_of_previous_level := last_id_of_previous_level+1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; total_count := total_count +1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; id := total_count;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RAISE NOTICE 'Inserting polygon number: % at level: %',total_count,1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RETURN NEXT;<br>&nbsp;&nbsp;&nbsp; END LOOP;<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; -- handle all higher
 levels<br>&nbsp;&nbsp;&nbsp; FOR level IN 2..100 LOOP<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RAISE NOTICE 'level: %',level;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; FOR i IN first_id_of_previous_level..last_id_of_previous_level LOOP<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RAISE NOTICE 'i: %',i;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; FOR j IN (i+1) .. last_id_of_previous_level LOOP<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RAISE NOTICE 'j: %&nbsp;&nbsp; last_id_of_previous_level: %',j,last_id_of_previous_level;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; IF Intersects(geometries[i],geometries[j]) THEN<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; the_geom := Intersection(geometries[i],geometries[j]);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 intersection_count := level;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; current_level_count := current_level_count+1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; geometries := array_append(geometries, temp_geom);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num_intersections := array_append(num_intersections, level);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; total_count := total_count +1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; id := total_count;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RAISE NOTICE 'Inserting polygon number %',total_count;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RETURN
 NEXT;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; END IF;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; END LOOP;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; END LOOP;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; IF current_level_count &gt; 0 THEN<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; first_id_of_previous_level := last_id_of_previous_level+1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; last_id_of_previous_level := first_id_of_previous_level+current_level_count;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; current_level_count := 0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ELSE <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; EXIT;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; END IF;<br>&nbsp;&nbsp;&nbsp; END LOOP;<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; RETURN;<br>END;<br>$BODY$<br>&nbsp; LANGUAGE 'plpgsql' IMMUTABLE;<br><br><div style="font-family: times new roman,new
 york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: Mark Cave-Ayland &lt;mark.cave-ayland@ilande.co.uk&gt;<br>To: PostGIS Users Discussion &lt;postgis-users@postgis.refractions.net&gt;<br>Sent: Tuesday, October 10, 2006 9:40:41 AM<br>Subject: Re: [postgis-users] Chained Intersections?<br><br><div>On Tue, 2006-10-10 at 06:22 -0700, Curtis W. Ruck wrote:<br><br>(cut)<br><br>&gt; DECLARE<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; total_count int := 0;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; current_level_count int := 0;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; first_id_of_previous_level int := 0;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; last_id_of_previous_level int:= 0;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; num_intersections int ARRAY[0];<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; geometries geometry ARRAY[0];<br><br><br>Hi Curtis,<br><br>The declarations for num_intersections and geometries look strange - I'm<br>not sure the PostgreSQL parser can correctly determine they are arrays<br>from your
 definitions. Can you try something like this:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;num_intersections int[];<br>&nbsp;&nbsp;&nbsp;&nbsp;geometries geometry[];<br><br><br>Kind regards,<br><br>Mark.<br><br><br><br>_______________________________________________<br>postgis-users mailing list<br>postgis-users@postgis.refractions.net<br><a target="_blank" href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br></div></div><br></div></div></body></html>