How to calculate the similarity(0%-99%) of two polylines in Python

66 Views Asked by At

Both two polylines contains a set of geo positions(like 38.663610000000006,-121.29237), the total number of position for each polylines are different.

How to calculate the similarity(0%-99%) of two polylines in Python?

1

There are 1 best solutions below

0
blunova On

To calculate the similiary between two lines you can try to use the Fréchet distance.

The shapely library provides the frechet_distance function and its documentation reports the following example:

from shapely import LineString
line1 = LineString([(0, 0), (100, 0)])
line2 = LineString([(0, 0), (50, 50), (100, 0)])
distance = frechet_distance(line1, line2)

As you can see the lines are defined by a different number of points. Then, if you need a percentage you can simply normalize the distance value using a reference distance relevant for this problem.