TransWikia.com

Compare linestrings in postgis

Geographic Information Systems Asked by Dino C on August 11, 2021

Let us assume the following two lines

enter image description here

The two geometries are extracted by two different tables: table_1 and table_2 with respective column geometries geometry_1 and geometry_2. I want to check if the two lines are identical. Condition for this is if the max distance between the two lines is not longer than x meters. I am running the following:

create index geom_1_idx ON table1 USING GIST (geometry_1);
select table1_id, table2_id  from table1 t1, table2 t2
              where (select st_DWithin(t1.geometry_2 , t2.geometry_2, units_of_srid) = true)

With spatial indexing, I understand that the comparison refers to the bounding boxes of the lines.

How correct is it?

Is a case like the one of the image covered?

One Answer

It sounds like you need to know the maximum distance between the two lines, but ST_DWithin is computing the minimum distance between the two lines.

I think what you're after is the Hausdorff Distance metric, implemented in PostGIS as ST_HausdorffDistance.

Because the Hausdorff distance is computed between sets of points, not lines, you might want to specify a densification parameter to interpolate additional points from the lines for use in the computation.

The densification parameter f, which must be between 0 and 1, causes each segment to be divided into approximately 1/f smaller segments. With a densification fraction of 1.0, no segments will be divided. As the densifcation parameter approaches (but does not reach) zero, the approximated value generated by this function will approach the true Hausdorff distance.

Correct answer by dbaston on August 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP