多个表之间的距离直方图
histogram of distances between multiple tables
下面这里是sequel
背景 我有 2 个数据库:事件(全年 40 万行)和汽车(每个月 600 万行)。较小的样本是 here looking like this
事件有位置 x y。汽车有 car_id、time_now、time_prev、time_next 以及位置 x y.
期望的结果 将是每个事件到事件发生时所有汽车的距离直方图±增量时间。
或者,对于每个事件,在事件发生时与每辆车的距离为 table ±delta 会很好。如果没有任何效果,也许可以添加到 table 事件列 closest_car_0min , closest_car_5min, closest_car_15min,closest_car_30min.
我想使用 ST_Distance
来计算距离(PostGIS 扩展)。
我还创建了 time_prev 和 time_next 因为我想检查事件的时间 events.date_ ±1 小时是否在 time_prev 到 time_now 或从 time_now 到 time_next.
问题:好吧,我到底该怎么做?
更新 澄清一下,我将想要的结果添加到 here looking like this
我想我找到了答案。以下有效:
--create empty table for results and fix key
create table results
(
resultID serial NOT NULL,
vehicle_id numeric(10,0),
eventid numeric(10,0),
deltaMIN interval MINUTE,
distance_m32138 double precision,
eventtime timestamp without time zone,
time_now timestamp without time zone,
time_prev timestamp without time zone,
time_next timestamp without time zone
)
;
alter table results add CONSTRAINT results_pkey PRIMARY KEY (resultID);
INSERT INTO results
( vehicle_id, eventid, deltaMIN, distance_m32138, eventtime, time_now, time_prev,time_next)
select
vehicle_id,
eventid,
deltaMIN,
ST_Distance (
ST_Transform(toy_events.geom ,32138),
ST_Transform(toy_cars.geom ,32138)
) AS distance_m32138,
eventtime, time_now, time_prev, time_next
from
toy_events,
toy_cars,
deltas
where
eventtime between time_prev and time_next
or
(
eventtime - deltamin between time_prev and time_now
or
eventtime + deltamin between time_now and time_next
)
;
select * from results;
下面
背景 我有 2 个数据库:事件(全年 40 万行)和汽车(每个月 600 万行)。较小的样本是 here looking like this
期望的结果 将是每个事件到事件发生时所有汽车的距离直方图±增量时间。 或者,对于每个事件,在事件发生时与每辆车的距离为 table ±delta 会很好。如果没有任何效果,也许可以添加到 table 事件列 closest_car_0min , closest_car_5min, closest_car_15min,closest_car_30min.
我想使用 ST_Distance
来计算距离(PostGIS 扩展)。
我还创建了 time_prev 和 time_next 因为我想检查事件的时间 events.date_ ±1 小时是否在 time_prev 到 time_now 或从 time_now 到 time_next.
问题:好吧,我到底该怎么做?
更新 澄清一下,我将想要的结果添加到 here looking like this
我想我找到了答案。以下有效:
--create empty table for results and fix key
create table results
(
resultID serial NOT NULL,
vehicle_id numeric(10,0),
eventid numeric(10,0),
deltaMIN interval MINUTE,
distance_m32138 double precision,
eventtime timestamp without time zone,
time_now timestamp without time zone,
time_prev timestamp without time zone,
time_next timestamp without time zone
)
;
alter table results add CONSTRAINT results_pkey PRIMARY KEY (resultID);
INSERT INTO results
( vehicle_id, eventid, deltaMIN, distance_m32138, eventtime, time_now, time_prev,time_next)
select
vehicle_id,
eventid,
deltaMIN,
ST_Distance (
ST_Transform(toy_events.geom ,32138),
ST_Transform(toy_cars.geom ,32138)
) AS distance_m32138,
eventtime, time_now, time_prev, time_next
from
toy_events,
toy_cars,
deltas
where
eventtime between time_prev and time_next
or
(
eventtime - deltamin between time_prev and time_now
or
eventtime + deltamin between time_now and time_next
)
;
select * from results;