[postgis-users] Construcción de multipunto a partir de puntos en polígono

Néstor Ramires nramire1 at rosario.gov.ar
Wed Apr 18 07:18:32 PDT 2018


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?


--------------------------------------------------

Hello everyone
I have the following data:

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));

The objective is to update the Trees field of the patrol table, with a multipoint geometry that contains all the trees in the region. To do this I use the following sentence:

UPDATE patrulla mp
SET arboles = ST_Multi(r.raiz)
 FROM arboles r
WHERE ST_Contains(mp.region, r.raiz);

That would not be working as I expected, as in regions that have more than one tree inside, just take into account the first of them.
Can anyone give me an idea of where to aim to find the solution?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20180418/afe1e373/attachment.html>


More information about the postgis-users mailing list