Created
May 27, 2021 10:28
-
-
Save gruvw/7a0a5b378ad452c0b6d5c09576c4b1b4 to your computer and use it in GitHub Desktop.
Meeting point from GPS coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from tqdm import tqdm | |
import matplotlib.pyplot as plt | |
multi = 1e3 # Precision | |
# GPS coords: (°N, °E) | |
pers = [ | |
(, ), | |
(, ), | |
(, ) | |
] | |
# Same order as coords | |
names = [ | |
"", | |
"", | |
"", | |
] | |
pers = np.array([np.array([int(per[1]*multi)+1, int(per[0]*multi)+1], dtype='int32') for per in pers]) # °E, °N | |
for i in range(len(pers)): | |
plt.plot(pers[i][0]/multi, pers[i][1]/multi, marker="o", label=names[i]) | |
mini = np.array([90*multi, 90*multi], dtype='int32') | |
maxi = np.array([0, 0], dtype='int32') | |
for per in pers: | |
if per[0] < mini[0]: | |
mini[0] = per[0] | |
if per[0] > maxi[0]: | |
maxi[0] = per[0] | |
if per[1] < mini[1]: | |
mini[1] = per[1] | |
if per[1] > maxi[1]: | |
maxi[1] = per[1] | |
mini[0] = mini[0] - 3*multi/1e2 | |
mini[1] = mini[1] - 3*multi/1e2 | |
maxi[0] = maxi[0] + 3*multi/1e2 | |
maxi[1] = maxi[1] + 3*multi/1e2 | |
# Main calculations | |
pts = [] | |
for i in tqdm(range(maxi[0]-mini[0]+1)): | |
for j in range(maxi[1]-mini[1]+1): | |
x = mini[0] + i # °E | |
y = mini[1] + j # °N | |
pt = np.array([x, y], dtype='int32') | |
dist = 0 | |
for per in pers: | |
vec = pt - per | |
dist += np.linalg.norm(vec) | |
pts.append([x, y, dist]) | |
pts = np.array(pts) # (°E, °N, dist) | |
best = pts[pts[:, 2].argmin()] # Best meeting point: (°E, °N, dist) | |
plt.figtext(0.5, 0.02, f"Meeting Point: {best[1]/multi}°N, {best[0]/multi}°E", ha="center", fontsize=10) | |
plt.scatter(best[0]/multi, best[1]/multi, marker="x", label="Meeting Point", color="red") # single point | |
print(f"Meeting Point: {best[1]/multi}°N, {best[0]/multi}°E") | |
print(f"URL: https://www.google.ch/maps/place/{best[1]/multi}+{best[0]/multi}") | |
dists = pts[:, 2] - best[2] | |
dists = dists**(1/2) # accentuate diff | |
heat = [] | |
for i in range(maxi[0]-mini[0]): | |
heat.append(dists[(maxi[1]-mini[1]+1)*i:(maxi[1]-mini[1]+1)*(i+1)]) | |
heat = list(zip(*heat))[::-1] | |
plt.imshow(heat, cmap='viridis', extent=[mini[0]/multi, maxi[0]/multi, mini[1]/multi, maxi[1]/multi]) | |
plt.colorbar(label="Distance") | |
plt.legend(prop={'size': 7}) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment