Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compute distance in meters of sequence of GPS coordinates in Python.

I have a list of GPS coordinates belonging to the same street. I would like to use this list to estimate the length of the street in meters.

I know I can use Haversine formula to compute the distance in meters between two coordinates, but I still have two problems:

  1. The sequence is not sorted in any way, so consecutive points in the list can be basically anywhere along the street.
  2. GPS coordinates are not aligned at the center of the street, but can be anywhere along the width of the street.

To solve the problem I need to sort the sequence of coordinates using some criterion and to align them along the center of the street. But I cannot find an accurate solution to neither of these issues.

How can I go about solving this problem?

like image 766
Blackecho Avatar asked Dec 07 '25 18:12

Blackecho


1 Answers

GPS coordinates means that you have two pieces of information: the location at some length down the street, and the location at some point in the width of the street.

Since you're only interested in computing the length of the street, find the coordinate that corresponds to the length (that would be the coordinate with the largest "spread", assuming the length is longer than the width), sort them, and then just find the difference between the minimum and maximum values.

Here's a simplified example. Suppose the points on the grid are the coordinates you have.

enter image description here

You are only interested in the distance in one direction. Assume that is the X axis in this case. Then you only care about the distance between the X-coordinates of C and F, regardless of the Y-coordinates of any of the points.

Update: My previous answer wrongly assumed that the street is aligned along a particular coordinate. For more general street orientations, you can sort the points along any one coordinate, and find the distance between the first and last point. This is just a heuristic and the points could likely lie along a diagonal of the street.

For a better estimate, Mikael N's approach of fitting a least squares line to estimate the mid point would work well.

like image 165
Antimony Avatar answered Dec 11 '25 03:12

Antimony