-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
Code executes when inputting lat/long, does not pull from LADI imagery.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Wed Oct 14 18:08:46 2020 | ||
@author: zachr | ||
""" | ||
|
||
|
||
## Inputs either a N X 1 imagery UUID or an image itself | ||
|
||
|
||
import pandas as pd | ||
import csv | ||
import numpy as np | ||
from math import sqrt | ||
|
||
## Calculate the distance, in units meters, between the latitude, longitude metadata of the image and all nearby airports | ||
|
||
# Assign value to lat/long of image | ||
#latimage = 0 | ||
#longimage = 0 | ||
|
||
# making data frame | ||
df = pd.read_csv("Airports.csv") | ||
longairport = df['X'].values | ||
This comment has been minimized.
Sorry, something went wrong. |
||
latairport = df['Y'].values | ||
nameairport = df['NAME'].values | ||
idairport = df['GLOBAL_ID'].values | ||
|
||
#print(type(longairport[0])) | ||
#airportloc = np.array([longairport, latairport]) | ||
|
||
# make new column for distance to airports | ||
def findclosestairport(latimage,longimage): | ||
|
||
closest_index = 0 | ||
closest_distance = np.inf | ||
|
||
#for latimage, longimage in somelist: | ||
#latimage_list = [] | ||
for idx in range(len(longairport)): | ||
curr_long = float(longairport[idx]) | ||
curr_lat = float(latairport[idx]) | ||
|
||
curr_distance = get_distance_degrees(curr_long, curr_lat, latimage, longimage) | ||
|
||
if curr_distance < closest_distance: | ||
closest_distance = curr_distance | ||
closest_index = idx | ||
|
||
distance_meters = closest_distance * 111194.926644559 | ||
|
||
return [distance_meters, longairport[closest_index], latairport[closest_index], nameairport[closest_index], idairport[closest_index]] | ||
|
||
|
||
|
||
|
||
def get_distance_degrees(long, lat, latimage, longimage): | ||
return sqrt((abs(latimage - lat))**2 + (abs(longimage - long))**2) | ||
|
||
# input long,lat, output closest airport info | ||
print(findclosestairport(42.373615, -71.109734)) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
% location of cambridge,ma | ||
latimage = 42.373615; | ||
longimage = -71.109734; | ||
|
||
% make into array | ||
longairport = table2array(Airports(:,1)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
zroberts45
Author
|
||
latairport = table2array(Airports(:,2)); | ||
uuidairport = table2array(Airports(:,4)); | ||
nameairport = table2array(Airports(:,6)); | ||
|
||
% zero variables | ||
distance_degrees = zeros(height(Airports),1); | ||
distance_meters = zeros(height(Airports),1); | ||
|
||
% iterate over all airports | ||
for i = 1: height(Airports) | ||
distance_degrees(i) = sqrt((abs(latimage - latairport(i)))^2 + (abs(longimage - longairport(i)))^2); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
distance_meters(i) = distance_degrees(i) * 111194.926644559; | ||
end | ||
|
||
airport_id = table2array(Airports(:,3)); | ||
% airport_uuid = table2array(Airports(:,4)); | ||
% airport_name = table2array(Airports(:,6)); | ||
|
||
% organize information | ||
airportinfo = zeros(height(Airports),2); | ||
for i = 1:height(Airports) | ||
airportinfo(i,1) = distance_meters(i); | ||
airportinfo(i,2) = airport_id(i); | ||
end | ||
|
||
% airportinfo(i,2) = airport_uuid(i); | ||
% airportinfo(i,3) = airport_name(i); | ||
|
||
% sort distances | ||
airportsort = sortrows(airportinfo,1); | ||
|
||
% Output a N X 4 column of UUID, image latitude, image longitude, | ||
% distance to nearest airport, UUID of nearest airport | ||
|
||
closestairportlong = longairport(airportsort(1,2)); | ||
x1 = 'The longitude of the closest airport is '; | ||
disp(x1) | ||
This comment has been minimized.
Sorry, something went wrong.
aweinert-MIT
Member
|
||
closestairportlong | ||
x2 = 'The latitude of the closest airport is '; | ||
disp(x2) | ||
latairport(airportsort(1,2)) | ||
x3 = 'The distance in meters from the closest airport is '; | ||
disp(x3) | ||
airportsort(1,1) | ||
x4 = ['The UUID of the closest airport is ', uuidairport(airportsort(1,2))]; | ||
disp(x4) | ||
x5 = ['The name of the closest airport is ', nameairport(airportsort(1,2))]; | ||
disp(x5) | ||
|
||
|
||
|
||
|
1 comment
on commit ad5b78e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zroberts45 , I have a few commits with the Python units / naming convention as the most important comment. Thanks
Please add units to variable names and update variables to align with PEP 8 naming conventions (PEP 8 reference). So
longairport
could beairport_lon_deg
andlatairport
can beairport_lat_deg
, etc.