将缓冲区添加到现有 table 和空间连接
Add the buffer to the existing table and spatial join
我有一个包含多个 table 的空间数据库,我已经为带点的 table 创建了一个缓冲区,并希望将缓冲区添加到现有的 table。并且想要进行空间连接,例如使用此缓冲区和另一个 table 点来计算每个缓冲区内的点数,并将其作为新列添加到现有缓冲区 table 中。我想不通。
SELECT ST_Buffer(geom::geography,100) FROM public.operation;
UPDATE operations SET buffer = ST_Buffer(geom::geography,100)::geometry;
FROM "Supermarket" AS pts, "geom" as ST_Buffer
WHERE ST_Contains( the_geom, pts.location)
首先添加一个新的几何列 AddGeometryColumn
..
SELECT AddGeometryColumn ('public','operations','buffer',4326,'POLYGON',2);
.. 然后使用更新
在新列中插入缓冲区
UPDATE operations SET buffer = ST_Buffer(geom::geography,100)::geometry;
编辑 1:向 table“操作”添加一个新列,并用另一个 table 在空间上重叠的点数填充它新缓冲区:
ALTER TABLE operations ADD COLUMN pts int;
UPDATE operations o
SET pts = (SELECT count(*) FROM supermarket s
WHERE ST_Contains(o.buffer,s.geom));
编辑 2(见评论):
CREATE INDEX idx_operation_geom ON operations USING gist (geom);
CREATE INDEX idx_supermarket_geom ON supermarket USING gist (geom);
我有一个包含多个 table 的空间数据库,我已经为带点的 table 创建了一个缓冲区,并希望将缓冲区添加到现有的 table。并且想要进行空间连接,例如使用此缓冲区和另一个 table 点来计算每个缓冲区内的点数,并将其作为新列添加到现有缓冲区 table 中。我想不通。
SELECT ST_Buffer(geom::geography,100) FROM public.operation;
UPDATE operations SET buffer = ST_Buffer(geom::geography,100)::geometry;
FROM "Supermarket" AS pts, "geom" as ST_Buffer
WHERE ST_Contains( the_geom, pts.location)
首先添加一个新的几何列 AddGeometryColumn
..
SELECT AddGeometryColumn ('public','operations','buffer',4326,'POLYGON',2);
.. 然后使用更新
在新列中插入缓冲区UPDATE operations SET buffer = ST_Buffer(geom::geography,100)::geometry;
编辑 1:向 table“操作”添加一个新列,并用另一个 table 在空间上重叠的点数填充它新缓冲区:
ALTER TABLE operations ADD COLUMN pts int;
UPDATE operations o
SET pts = (SELECT count(*) FROM supermarket s
WHERE ST_Contains(o.buffer,s.geom));
编辑 2(见评论):
CREATE INDEX idx_operation_geom ON operations USING gist (geom);
CREATE INDEX idx_supermarket_geom ON supermarket USING gist (geom);