#Aufgabe #Es soll die Distanz Luftlinie zweier Orte in Deutschland ( ) in km berechnet werden. #Dazu gibt es eine Datei de.dat (liegt /data/share/sstudent/py_pgm1/de.dat), welche alle deutsche #Orte in Deutschland aufgelistet hat. Diese Daten enthalten auch Angaben ueber die s.g. #Longitude und Latitude in dezimaler Form aus der sich die aktuelle Position eines #Ortes auf der Weltkugel ergibt. #Abfrage eines ersten Ortes (fehlertolerante Schreibweise erlauben, #inkl. eines Vorschlages moeglicher passenden Orte in Form einer Liste) #Abfrage eines zweiten Ortes (fehlertolerante Schreibweise #erlauben, inkl. eines Vorschlages moeglicher passenden Orte in Form einer #Liste) # Berechnung der Distanz dieser beiden Orte unter Verwendung der #entsprechenden Angaben zur Longitude und zur Latitude der beiden Orte #aus der Datei De.dat # Ausgabe gewaehlten Orte und der berechneten Distanz (Luftlinie) in km #Es soll moeglich sein ein Logging der einzelnen Verarbeitungsschritte mit Verwendung #des Logging-Moduls einzustellen. # Auf Grund der Komplexitaet ist die intensive Verwendung von git und PAP anzuraten. #Autor :Zhang Kai Milad shirvani filabadi, Yuan Wei #Datum : 20,05,2017 #data-Erklaerung # 0 'loc_id', #OpenGeoDB Location ID # 1 'ags', # AGS - Amtlicher Gemeindeschluessel # 2 'ascii', # Normalized ASCII-only uppercase location name # 3 'name', # Actual (unicode) location name # 4 'lat', # Latitude in degrees (northern Latitude) weidu # 5 'lon', # Longitude in degrees(western Longitude) jingdu # 6 'amt', # Associated to # 7 'plz', # List of PLZ codes # 8 'vorwahl', # Telephone prefix # 9 'einwohner', # Population figure # 10 'flaeche', # Area # 11 'kz', # KFZ Kennzeichen # 12 'typ', # ? # 13 'level', # ? # 14 'of', # ? # 15 'invalid']) import re # stichworte suchen import os #The OS module in Python provides a way of using operating system dependent #functionality import sys #system import logging import time as t from math import cos, sin, asin, sqrt ,atan2 from contextlib import contextmanager ort1 = [] ort2 = [] R = 6378.137#EARTH RADIUS def protokoll(): logging.info("You should see this info both in log file ") logging.warning("You should see this warning both in log file ") logging.error("You should see this error both in log file ") logging.debug("You should ONLY see this debug in log file") logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='map.log', filemode='w') protokoll () def ort_name1 () : i = 0 ort1="" list1 = []#list entsthen orts_info = open("DE.tab","r").readlines() while True: try : ort1 = raw_input("Bitte start_Stadt eingeben:").upper()#start-Stadt break except TypeError : print("Tipps :ue,ae,oeund ss in ue,ae,oe und ss schreiben") else : break break print("Moechten Sie folgende Orte finden?") for line1 in orts_info : if re.search(ort1,line1): i = i + 1 line3 = re.split("\t",line1)# eine list entstehen list1.append(line3) print "Ordnungszahl:{}, ort_name:{} PLZ:{}".format(i,line3[3],line3[7]) #Vorschlages z=input("Bitte geben Sie die Ordnungszahl ein:") l=len(list1) for b in range(1,l) : if z == b + 1 : line3 = list1[b] return line3 def ort_name2 () : i = 0 ort2 = "" list1 = [] #list entsthen orts_info = open("DE.tab","r").readlines() while True: try : ort2 = raw_input("Bitte Ziel-Stadt eingeben:").upper()#ziel-Stadt break except TypeError : print("Tipps :ue,ae,oeund ss in ue,ae,oe und ss schreiben") else : break break print("Moechten Sie folgende Orte finden?") for line1 in orts_info : if re.search(ort2,line1): i = i + 1 line3 = re.split("\t",line1)# eine list entstehen list1.append(line3) print "Ordnungszahl:{}, ort_name:{} PLZ:{}".format(i,line3[3],line3[7]) #Vorschlages z=input("Bitte geben sie die Ordnungszahl ein:") l=len(list1) line4 = 0 for b in range(1,l) : if z == b + 1 : line4 = list1[b] return line4 def Distanz(): ort1 = ort_name1() ort2 = ort_name2() #print "ort2:",ort2 #print "ort1:", ort1 lat1=float(ort1[5])#weidu lon1=float(ort1[4])#jingdu lat2=float(ort2[5])# lon2=float(ort2[4])# #lat1=ort1[5]#weidu #lon1=ort1[4]#jingdu #lat2=ort2[5]# #lon2=ort2[4] #haversine Gleichung dlon = 71.5*(lon2 - lon1) dlat = 111.3*(lat2 - lat1) #a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2 #c = 2 * atan2(sqrt(a),sqrt(1-a)) #c = 2 * asin(sqrt(a)) d =float(sqrt(dlon*dlon+dlat*dlat)) print ("Distanz von {} bis {}:{:0.2f}".format(ort1[3],ort2[3],d)+"km") Distanz() #a = "" #a = raw_input("moechten Sie nochmal finden ? a)nochmal b)ende:").upper #if a == "A" : #Distanz()