Created
January 30, 2025 17:18
-
-
Save SamyBencherif/744d33abf05fd80c4156d4432b1d7dbd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 csv | |
def distanceSq(A, B): | |
return (A[0]-B[0])**2 + (A[1]-B[1])**2 | |
dupont_circ = (38.90968521377803, -77.04349286990991) | |
""" | |
An array of tuples with (sn, dist) | |
""" | |
distances = [] | |
with open("sensors_latlon.csv") as csv_file: | |
Reader = csv.reader(csv_file) | |
c = 0 | |
for line in Reader: | |
if c >= 1: | |
sn, lat, lon = line | |
lat = float(lat) | |
lon = float(lon) | |
distances.append( | |
(sn, distanceSq(dupont_circ, (lat, lon))) | |
) | |
c += 1 | |
shortest_distance_elem = min(distances, key=lambda K: K[1]) | |
sn, dist = shortest_distance_elem | |
print(sn, dist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment