[postgis-users] Chained Intersections?
Curtis W. Ruck
ruckc at yahoo.com
Wed Oct 11 06:31:09 PDT 2006
Alright, I still have some tweaking todo (it is returning way too many identical polygons). But the issue i was having was that I was not inserting anything into the array at initialization. In the Postgresql documentation it says this: "A limitation of the present array implementation is that individual
elements of an array cannot be SQL null values. The entire array can be
set to null, but you can't have an array with some elements null and
some not. (This is likely to change in the future.)" Not it doesn't say explicitly that you can't but i think what was happening is when i was appending my geometry & integer to their arrays, it was tryign to join a <NULL> and a real item and only returning the <NULL>.
So i am just creating them with a default geometry and integer that are removed after the first loop. Below is my function so far:
BTW, thanks for the help.
CREATE OR REPLACE FUNCTION intersection_all(IN in_polys geometry, OUT id int4, OUT intersection_count int4, OUT the_geom geometry) RETURNS SETOF record AS
$BODY$
DECLARE
total_count int := 0;
current_level_count int := 0;
first_id_of_previous_level int := 0;
last_id_of_previous_level int:= 0;
num_intersections int[] = ARRAY[0];
geometries geometry[] = ARRAY[GeomFromText('POINT(0 0)',-1)];
BEGIN
-- handle level one by adding all input polygons
FOR i IN 1..NumGeometries(in_polys) LOOP
the_geom := GeometryN(in_polys,i);
intersection_count := 1;
geometries := geometries || the_geom;
num_intersections := array_append(num_intersections, intersection_count);
last_id_of_previous_level := last_id_of_previous_level+1;
total_count := total_count +1;
id := total_count;
--RAISE NOTICE 'Inserting polygon number: % at level: %',total_count,1;
--RAISE NOTICE 'Size of geometries array: %',array_upper(geometries, 1);
RETURN NEXT;
END LOOP;
geometries := geometries[2:array_upper(geometries, 1)];
num_intersections := num_intersections[2:array_upper(num_intersections, 1)];
-- handle all higher levels
<<LEVELLOOP>>
FOR level IN 2..100 LOOP
RAISE NOTICE 'level: %',level;
FOR i IN first_id_of_previous_level..last_id_of_previous_level LOOP
--RAISE NOTICE 'i: %',i;
FOR j IN (i+1) .. last_id_of_previous_level LOOP
--RAISE NOTICE 'j: % last_id_of_previous_level: %',j,last_id_of_previous_level;
IF Intersects(geometries[i],geometries[j]) AND NOT Equals(geometries[i],geometries[j]) THEN
the_geom := Intersection(geometries[i],geometries[j]);
intersection_count := level;
current_level_count := current_level_count+1;
geometries := array_append(geometries, the_geom);
num_intersections := array_append(num_intersections, level);
total_count := total_count +1;
id := total_count;
RAISE NOTICE 'Inserting polygon number %',total_count;
RETURN NEXT;
END IF;
END LOOP;
IF total_count > 2000 THEN
EXIT LEVELLOOP;
END IF;
END LOOP;
IF current_level_count > 0 THEN
first_id_of_previous_level := last_id_of_previous_level+1;
last_id_of_previous_level := first_id_of_previous_level+current_level_count;
current_level_count := 0;
ELSE
EXIT;
END IF;
END LOOP LEVELLOOP;
RETURN;
END;
$BODY$
LANGUAGE 'plpgsql' IMMUTABLE;
----- Original Message ----
From: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
To: PostGIS Users Discussion <postgis-users at postgis.refractions.net>
Sent: Wednesday, October 11, 2006 5:48:23 AM
Subject: Re: [postgis-users] Chained Intersections?
On Tue, 2006-10-10 at 15:31 -0700, Curtis W. Ruck wrote:
> Negative, i tried that with the below as the function declaration to
> no avail. The handle all higher levels section isn't finding anything
> in the arrays. Anyone else have a suggestion on how to store data
> within a function without creating a temporary table?
>
> Curtis
Hi Curtis,
Looking at the code you just posted, you have this line here:
geometries := array_append(geometries, temp_geom);
but I can't see where temp_geom is being set within your PLPGSQL
function? Should it be the_geom? Another trick would be to add something
like:
RAISE NOTICE 'geometries count: %', array_upper(geometries, 1);
which should show the size of your arrays increasing as the function
runs.
HTH,
Mark.
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20061011/f5efd4dd/attachment.html>
More information about the postgis-users
mailing list