Last active
March 21, 2019 16:22
-
-
Save mlewis-everley/9b7ec36aad8bc5ec44628ce741942119 to your computer and use it in GitHub Desktop.
Example function creation
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 math | |
def CalculateDistance(Lat1, Lon1, Lat2, Lon2): | |
Lat1 = float(Lat1) | |
Lon1 = float(Lon1) | |
Lat2 = float(Lat2) | |
Lon2 = float(Lon2) | |
nDLat = (Lat1 - Lat2) * 0.017453293 | |
nDLon = (Lon1 - Lon2) * 0.017453293 | |
Lat1 = Lat1 * 0.017453293 | |
Lat2 = Lat2 * 0.017453293 | |
nA = (math.sin(nDLat/2) ** 2) + math.cos(Lat1) * math.cos(Lat2) * (math.sin(nDLon/2) ** 2 ) | |
nC = 2 * math.atan2(math.sqrt(nA),math.sqrt( 1 - nA )) | |
nD = 6372.797 * nC | |
return nD | |
def LocationCount(FileName, Dist, Lat, Long): | |
FileIn =open(FileName,"r") | |
FileList = [] | |
# Loop through the lines in the file and generated a nested list | |
for Seperate in FileIn: | |
Seperate = Seperate.rstrip().split("\t") | |
FileList.append(Seperate) | |
FileIn.close() | |
# Loop through nested list and create variables for name, lat and long | |
for Seperate in FileList: | |
A= Seperate[0] | |
B= Seperate[1] | |
C= Seperate[2] | |
# Ensure these lines are "inside" the "for loop" | |
Counter = 0 | |
Distance = CalculateDistance(Lat, Long, B,C) | |
print(Distance) | |
if Dist > Distance: | |
Counter +=1 | |
print(Counter) | |
LocationCount("Mammal.txt", 20.0, 50.261667, -5.043333) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment