文档

ST_JaccardSimilarity

更新时间:

计算轨迹或子轨迹的Jaccard相似系数(Jaccard index)。

语法

record ST_JaccardSimilarity(trajectory tr1, trajectory tr2, double tol_dist, 
                            text unit default '{}', interval tol_time default NULL, 
                            timestamp ts default '-infinity', timestamp te default 'infinity') ; 

参数

参数名称

描述

tr1

轨迹对象1。

tr2

轨迹对象2。

tol_dist

空间容差,单位为米。

unit

描述距离计算方式的JSON字符串。

tol_time

时间容差。默认为NULL,当值为NULL或负值时表示只进行空间匹配不考虑时间。

ts

开始时间。默认为-infinity,只关注在起止时间之间的子轨迹。

te

结束时间。默认为infinity,只关注在起止时间之间的子轨迹。

unit参数说明如下。

参数名称

类型

默认值

说明

Projection

string

重新投影的目标坐标系。取值:

  • auto:根据经纬度坐标动态选择最合适的坐标系(Lambert Azimuthal、UTM等),并投影到此坐标系进行计算。不需要额外指定Unit,单位为米。

  • srid:需要重投影到的空间参考系ID。

说明

不传本参数时,依照原有坐标系计算。

Unit

string

null

度量单位。取值:

  • null:即无单位,直接按照轨迹点坐标的欧式距离进行计算。

  • M:按照所在空间参考系基于的单位进行距离计算,通常为米。

useSpheroid

bool

true

是否使用椭球体计算。当Unit设置为M时,可以指定此项。取值:

  • true:使用椭球体并计算更精确的距离。

  • false:使用球体表示地球并计算近似的距离。

返回参数说明如下。

参数名称

类型

说明

nleaf1

int

轨迹1与轨迹2相交的点数量。

nleaf2

int

轨迹2与轨迹1相交的点数量。

说明

nleaf1不一定相同,例如可能轨迹1两次经过轨迹2的同一个点,则nleaf1为1,nleaf2为2。

inter1

int

轨迹1到轨迹2的距离同时满足时间容差和空间容差的点数量。

inter2

int

轨迹2到轨迹1的距离同时满足时间容差和空间容差的点数量。

jaccard_lower

double

Jaccard距离下限。计算公式:inter/(nleaf1+nleaf2-inter)

说明

inter为inter1inter2中较小的值。

jaccard_upper

double

Jaccard距离上限。计算公式:inter/(nleaf1+nleaf2-inter)

说明

inter为inter1inter2中较大的值。

描述

两个集合的Jaccard index指两个集合交集的元素数量除以两个集合并集的元素数量。对于两条轨迹,我们扩展了Jaccard index的定义,分别计算在轨迹1与轨迹2相交的点数量,以及在轨迹2上与轨迹1相交的点数量,并通过上文jaccard_lowerjaccard_upper的公式计算距离。

示例

With traj as(
SELECT ST_makeTrajectory('STPOINT'::leaftype, 'SRID=4326;LINESTRING(114.49211 37.97921,114.49211 37.97921,114.49211 37.97921,114.49211 37.97921)'::geometry,
    ARRAY[to_timestamp(1590287775) AT TIME ZONE 'UTC', to_timestamp(1590287778) AT TIME ZONE 'UTC', to_timestamp(1590302169) AT TIME ZONE 'UTC',to_timestamp(1590302171) AT TIME ZONE 'UTC'], '{}') a,
    ST_makeTrajectory('STPOINT'::leaftype, 'SRID=4326;LINESTRING(114.49211 37.97921,114.49211 37.97921,114.49211 37.97921,114.49211 37.97921,114.49145 37.97781,114.49145 37.97781,114.49145 37.97781,114.49145 37.97781,114.49145 37.97781,114.49145 37.97781,114.49145 37.97781,114.49145 37.97781,114.49145 37.97781,114.49145 37.97781,114.49211 37.97921,114.49211 37.97921,114.49211 37.97921,114.49211 37.97921,114.49211 37.97921,114.49211 37.97921)'::geometry,
    ARRAY[ to_timestamp(1590287765) AT TIME ZONE 'UTC', to_timestamp(1590287771) AT TIME ZONE 'UTC', to_timestamp(1590287778) AT TIME ZONE 'UTC', to_timestamp(1590287780) AT TIME ZONE 'UTC', to_timestamp(1590295992) AT TIME ZONE 'UTC', to_timestamp(1590295997) AT TIME ZONE 'UTC', to_timestamp(1590296013) AT TIME ZONE 'UTC', to_timestamp(1590296018) AT TIME ZONE 'UTC',  to_timestamp(1590296025) AT TIME ZONE 'UTC', to_timestamp(1590296032) AT TIME ZONE 'UTC', to_timestamp(1590296055) AT TIME ZONE 'UTC', to_timestamp(1590296073) AT TIME ZONE 'UTC', to_timestamp(1590296081) AT TIME ZONE 'UTC', to_timestamp(1590296081) AT TIME ZONE 'UTC', to_timestamp(1590302169) AT TIME ZONE 'UTC', to_timestamp(1590302174) AT TIME ZONE 'UTC',  to_timestamp(1590302176) AT TIME ZONE 'UTC', to_timestamp(1590302176) AT TIME ZONE 'UTC', to_timestamp(1590302172) AT TIME ZONE 'UTC', to_timestamp(1590302176) AT TIME ZONE 'UTC'],'{}') b
)
select ST_JaccardSimilarity(a,b, 100,'{"unit":"M"}','20 second', '2020-05-23'::timestamptz AT TIME ZONE 'UTC', '2020-05-26'::timestamptz AT TIME ZONE 'UTC') from traj;
       st_jaccardsimilarity        
-----------------------------------
 (4,20,4,10,0.2,0.7142857142857143)
(1 row)

  • 本页导读 (1)
文档反馈