I have around 100 list of gps coordinates and I want to draw the line that each of those lists make.
One of the lists plotted using scatter, look somewhat like this:
Clearly there's a line there;
I tried several methods to sort the gps positions and plot them:
lats = []
lngs = []
with open(filename) as f:
for line in f:
lat, lng = line.split("\t")
lats.append(float(lat))
lngs.append(float(lng))
def sort_positions(position):
return position[0]+position[1]
positions= zip(lngs, lats)
positions = sorted(poss, key=sort_positions)
for i, positionin enumerate(positions):
lng, lat = position
#plt.scatter(lng, lat)
try:
n_lng, n_lat = positions[i+1]
plt.plot((lng, n_lng),(lat, n_lat), "b")
except IndexError:
pass
plt.show()
Sorting by Longitude
def sort_positions(position):
return position[0]
Sorting by Latitude
def sort_positions(position):
return position[1]
Sorting by Summing Both
def sort_positions(position):
return position[0]+position[1]
If the line are mostly straight in one of the axis(latitude/longitude), it plots fine (some minor bumps are still showing)
Here's one of the lists that do plot fine, sorting by latitude.
I to only plot if the distance between the two points was lesser than 200~500 meters, but I endup with holes in the lines, since there's some missing data.
Probably I'm doing this wrong. Does anyone know how to plot this lines properly?
EDIT:
In response to rth
answer:
The blue line is using his approach in this questions, the red one is using the method in his other answer.
Ignoring the fact that the red is closing the loop.
There are some limitations in both, first, the red one can't handle too many points, I had to to use 1/90 of the points for both, the blue one generates some weird sharp turns when the points are too clustered (the dark spots in the image), while the red one some weird curves in those places.