From: | Néstor Ramires <nramire1(at)rosario(dot)gov(dot)ar> |
---|---|
To: | "pgsql-es-ayuda(at)postgresql(dot)org" <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Construcción de multipunto a partir de puntos en polígono |
Date: | 2018-04-18 14:15:31 |
Message-ID: | op.zhn675zfocut9v@car-800 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Hola a todos
Tengo los siguientes datos:
CREATE TABLE arboles (
id SERIAL,
raiz geometry(Point, 22185)
);
INSERT INTO arboles (raiz) VALUES (ST_GeomFromText('POINT(1 1)',22185));
INSERT INTO arboles (raiz) VALUES (ST_GeomFromText('POINT(1 2)',22185));
INSERT INTO arboles (raiz) VALUES (ST_GeomFromText('POINT(5 2)',22185));
INSERT INTO arboles (raiz) VALUES (ST_GeomFromText('POINT(6 2)',22185));
INSERT INTO arboles (raiz) VALUES (ST_GeomFromText('POINT(5 3)',22185));
INSERT INTO arboles (raiz) VALUES (ST_GeomFromText('POINT(1 6)',22185));
INSERT INTO arboles (raiz) VALUES (ST_GeomFromText('POINT(3 6)',22185));
CREATE TABLE patrulla (
id SERIAL,
guardia int,
arboles geometry(MultiPoint, 22185),
region geometry(Polygon, 22185)
);
INSERT INTO patrulla (guardia, region) VALUES (1, ST_GeomFromText('POLYGON((0 0, 0 3, 3 3, 3 0, 0 0))',22185));
INSERT INTO patrulla (guardia, region) VALUES (2, ST_GeomFromText('POLYGON((4 1, 4 4, 8 4, 8 1, 4 1))',22185));
INSERT INTO patrulla (guardia, region) VALUES (3, ST_GeomFromText('POLYGON((2 8, 0 6, 2 4, 2 8))',22185));
INSERT INTO patrulla (guardia, region) VALUES (4, ST_GeomFromText('POLYGON((2 8, 5 6, 2 4, 2 8))',22185));
El objetivo es actualizar el campo arboles de la tabla patrulla, con una geometría multipunto que contenga todos los árboles de la región. Para ello utilizo la siguiente sentencia:
UPDATE patrulla mp
SET arboles = ST_Multi(r.raiz)
FROM arboles r
WHERE ST_Contains(mp.region, r.raiz);
Que no estaría funcionando como yo esperaba, ya que en las regiones que tienen más de un árbol en su interior, sólo toma en cuenta el primero de ellos.
¿Alguno puede darme una idea de por dónde apuntar para buscar la solución?
From | Date | Subject | |
---|---|---|---|
Next Message | jvenegasperu | 2018-04-19 20:18:34 | Explaining the Unexplainable |
Previous Message | Jaime Casanova | 2018-04-17 21:25:44 | Re: modificar tipo de dato postgres |