25.1 SDO_GEOM.DTW_DISTANCE
Format
SDO_GEOM.DTW_DISTANCE( s IN SDO_GEOMETRY, t IN SDO_GEOMETRY, w_in IN NUMBER default NULL ) RETURN NUMBER;
Description
Compares two different spatial trajectories by measuring the distance between the two objects.
Parameters
- s
-
The first two-dimensional line geometry.
- t
-
The second two-dimensional line geometry.
- w_in
-
Specifies how many vertices on the second line geometry need to be compared with a given vertex on the first line geometry.
For example, if
w_in = 2
, then the third vertex on the first line is compared to vertices 1, 2, 3, 4, and 5 on the second line; that is, using the vertex as the index, it determines the range for comparison as two points before and two after the vertex. Similarly, ifw_in = 1
, then the second vertex on the first line is compared to vertices 1, 2, 3, and 4 on the second line since there is only one prior vertex for index 2.Also, note the following:- In case the computed range is greater than the maximum number of vertices available in the second line geometry, then the comparison will be limited to the maximum number of vertices available in the second line.
- If
w_in = 0
, then the first vertex on the first line is compared with vertex 1, 2, and 3 of the second line as there are no prior vertices for index 1. - If
w_in = NULL
(default), then each vertex (i) on the first line is only compared with vertex (i) on the second line.
Usage Notes
The SDO_GEOM.DTW_DISTANCE
function is based on the Dynamic
Time Warping Algorithm and measures the similarity between two spatial trajectories by
computing the distance between them.
A spatial trajectory is represented by a two-dimensional line geometry. If the two lines are exactly the same, then the function returns zero. As the lines diverge, the resulting distance value grows higher.
Examples
The following example compares two spatial line trajectories with w_in
distance as 2.
SQL> select sdo_geom.dtw_distance(
sdo_geometry(2002, NULL, NULL, sdo_elem_info_array(1,2,1),
sdo_ordinate_array(1,1, 2,2, 3,3, 4,4, 5,5)),
sdo_geometry(2002, NULL, NULL, sdo_elem_info_array(1,2,1),
sdo_ordinate_array(2,2, 3,3, 4,4)), 2)
from dual;
SDO_GEOM.DTW_DISTANCE(SDO_GEOMETRY(2002,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO
--------------------------------------------------------------------------------
2.82842712
Parent topic: SDO_GEOM Package (Geometry)