Skip to content

Instantly share code, notes, and snippets.

@mlewis-everley
Last active March 21, 2019 16:22
Show Gist options
  • Save mlewis-everley/9b7ec36aad8bc5ec44628ce741942119 to your computer and use it in GitHub Desktop.
Save mlewis-everley/9b7ec36aad8bc5ec44628ce741942119 to your computer and use it in GitHub Desktop.
Example function creation
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