Skip to content
Snippets Groups Projects
Commit d40b834f authored by Hannah Freudenberger's avatar Hannah Freudenberger
Browse files

Distanz-Methode in Lib verschoben

parent 455bdb7c
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
import math
def getDistance(lat1,lon1,lat2,lon2):
lat = (lat1+lat2)/2*0.01745
dx = 111.3*math.cos(lat)*(lon1-lon2)
dy = 111.3*(lat1-lat2)
return math.sqrt(dx*dx+dy*dy)
......@@ -2,15 +2,22 @@
import Distanz_Rechner_Geokoordinaten as drg
import pandas as pd
import numpy as np
import math
df = pd.read_excel("koordinaten.xlsx")
def getSample(df,n):
return df.sample(n)
def getDistance(lat1,lon1,lat2,lon2):
lat = (lat1+lat2)/2*0.01745
dx = 111.3*math.cos(lat)*(lon1-lon2)
dy = 111.3*(lat1-lat2)
return math.sqrt(dx*dx+dy*dy)
def costFunction(sample,permutation):
cost = 0
for i in range(0, len(permutation)-1):
......@@ -18,6 +25,6 @@ def costFunction(sample,permutation):
lon1 = sample['Laengengrad_DEC'][sample.index[permutation[i]]]
lat2 = sample['Breitengrad_DEC'][sample.index[permutation[i+1]]]
lon2 = sample['Laengengrad_DEC'][sample.index[permutation[i+1]]]
cost += drg.getDistance(lat1,lon1,lat2,lon2)
cost += getDistance(lat1,lon1,lat2,lon2)
return cost
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment