PostGIS中的多层相交


9

我需要编写PL / pgSQL存储过程来计算多层的相交。例如,对于三层A,B,C,此函数应返回ABC几何: 在此处输入图片说明

函数将需要相交的图层的id作为输入。谁能给我建议以构建此功能?我对此的想法是,我需要先相交,然后相交,然后相交的结果与第三层相交,等等。


1
这个问题是否与您要寻找的问题相同?gis.stackexchange.com/q/83/97
Nathan W

不,这是另一个问题。
drnextgis 2011年

Answers:


3

请给我有关我建议的解决方案的任何评论:

CREATE OR REPLACE FUNCTION fp_intersect(lids varchar)
    RETURNS integer AS
$$
DECLARE
    lid_new  integer;
    lndx     integer := 1;
    lids_arr integer[];
BEGIN

IF regexp_replace(lids, E'\\s+', '', 'g') ~ E'^-?\\d+$' THEN
    RETURN -1;
END IF;

SELECT nextval ('g_layer_lid_seq') INTO lid_new; 

lids_arr := string_to_array(regexp_replace(lids, E'\\s+', '', 'g'), ',');
DROP TABLE IF EXISTS tmp_intersect;
CREATE TEMPORARY TABLE tmp_intersect AS SELECT geom FROM g_lgeom WHERE lid = lids_arr[1];

WHILE lndx < array_length(lids_arr, 1) LOOP
    DROP TABLE IF EXISTS tmp;
    CREATE TEMPORARY TABLE tmp AS SELECT ST_Intersection(geom, g_next) AS geom
    FROM tmp_intersect
    JOIN (
        SELECT geom AS g_next
        FROM g_lgeom
        WHERE lid = lids_arr[lndx+1]
    ) AS _
    ON ST_Intersects(geom, g_next);
    lndx := lndx+1;
    DROP TABLE IF EXISTS tmp_intersect;
    CREATE TEMPORARY TABLE tmp_intersect AS SELECT geom FROM tmp;
END LOOP;

INSERT INTO g_lgeom(lid, geom) SELECT lid_new, (_.p_geom).geom FROM (SELECT ST_Dump(geom) AS p_geom FROM tmp_intersect) AS _;

RETURN lid_new;
END
$$
LANGUAGE plpgsql;
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.