postGIS非常慢的st_buffer查询 - 如何提高性能

时间:2015-01-07 14:01:41

标签: sql performance postgresql postgis spatial

我在postgreSQL空间数据库中使用postGIS。我想从每个48只动物(与线连接的GPS位置)的运动路径周围的缓冲区创建homerange多边形。我有48个不同动物的264和39个数据点的位置数据。 我通过3个步骤来提高性能。问题是第二步(st_buffer在路径周围创建缓冲区)。如果我针对单个动物(6000个位置)运行下面的步骤2,则大约需要3分钟。如果我为所有动物的数据子集(三分之一)运行第二步,则需要30分钟。 既然我已经运行了查询所有数据,那么它已经运行了超过5个小时,而且我不确定它是否会成功返回。是否有任何理由说明运行时间不会以线性方式增长或减少?任何人都可以告诉我我的代码是否有问题,或者是否可以提高我的代码性能。任何建议都会非常感激!!

步骤1:首先创建一个带有移动路径的临时表 - 使用st_simplify来简化浮点参数为10m的路径

create table ws_zurich.polygon_homerange_104m_mirco_all_step1 as
select gps.animals_original_id, st_simplify(st_makeline(gps.geom_21781),10) as geom
from (select animals_original_id,acquisition_time, geom_21781
from ws_zurich.mirco
order by animals_original_id, acquisition_time) as gps
group by gps.animals_original_id;

Alter table ws_zurich.polygon_homerange_104m_mirco_all_step1
ADD CONSTRAINT polygon_homerange_104m_mirco_step1_pkey PRIMARY KEY(animals_original_id);

步骤2:使用移动路径周围的缓冲区创建一个表 - 这是最慢的查询,整个数据集需要几个小时

create table ws_zurich.polygon_homerange_104m_mirco_all_step2 as
select animals_original_id, (st_buffer(geom, 104)) as geom
from ws_zurich.polygon_homerange_104m_mirco_all_step1;

- 步骤3:使用st_union创建单个多边形作为主范围

create table ws_zurich.polygon_homerange_104m_mirco_post_hunting as
select row_number() over (order by animals_original_id) as id,animals_original_id,(st_union(geom)) as geom
from ws_zurich.polygon_homerange_104m_mirco_post_hunting_step2 group by animals_original_id;

Alter table ws_zurich.polygon_homerange_104m_mirco_post_hunting
ADD CONSTRAINT polygon_homerange_104m_mirco_post_hunting_pkey PRIMARY KEY (id);

0 个答案:

没有答案
相关问题