[postgis-users] Chained Intersections?

Curtis W. Ruck ruckc at yahoo.com
Tue Oct 10 15:31:53 PDT 2006


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

CREATE OR REPLACE FUNCTION intersection_all(in_polys geometry, OUT id int, OUT intersection_count int, 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[];
    geometries geometry[];
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 := array_append(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;
        RETURN NEXT;
    END LOOP;
 
    -- handle all higher levels
    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]) THEN
                    the_geom := Intersection(geometries[i],geometries[j]);
                    intersection_count := level;
                    current_level_count := current_level_count+1;
                    geometries := array_append(geometries, temp_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;
        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;
 
    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: Tuesday, October 10, 2006 9:40:41 AM
Subject: Re: [postgis-users] Chained Intersections?

On Tue, 2006-10-10 at 06:22 -0700, Curtis W. Ruck wrote:

(cut)

> 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[0];


Hi Curtis,

The declarations for num_intersections and geometries look strange - I'm
not sure the PostgreSQL parser can correctly determine they are arrays
from your definitions. Can you try something like this:

    num_intersections int[];
    geometries geometry[];


Kind regards,

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/20061010/9bd3fd39/attachment.html>


More information about the postgis-users mailing list