Browse Source

Pruefungsvorleistung

kai zhang 7 years ago
commit
0f48b9c6c6
1 changed files with 145 additions and 0 deletions
  1. 145 0
      map1.py

+ 145 - 0
map1.py

@@ -0,0 +1,145 @@
1
+#Aufgabe
2
+#Es soll die Distanz Luftlinie zweier Orte in Deutschland ( ) in km berechnet werden.
3
+#Dazu gibt es eine Datei de.dat (liegt /data/share/sstudent/py_pgm1/de.dat), welche alle deutsche
4
+#Orte in Deutschland aufgelistet hat. Diese Daten enthalten auch Angaben ueber die s.g.
5
+#Longitude und Latitude in dezimaler Form aus der sich die aktuelle Position eines
6
+#Ortes auf der Weltkugel ergibt.
7
+#Abfrage eines ersten Ortes (fehlertolerante Schreibweise erlauben,
8
+#inkl. eines Vorschlages moeglicher passenden Orte in Form einer Liste)
9
+#Abfrage eines zweiten Ortes (fehlertolerante Schreibweise
10
+#erlauben, inkl. eines Vorschlages  moeglicher passenden Orte in Form einer
11
+#Liste)
12
+# Berechnung der Distanz dieser beiden Orte unter Verwendung der
13
+#entsprechenden Angaben zur Longitude und zur Latitude der beiden Orte
14
+#aus der Datei De.dat
15
+# Ausgabe gewaehlten Orte und der berechneten Distanz (Luftlinie) in km
16
+#Es soll moeglich sein ein Logging der einzelnen Verarbeitungsschritte mit Verwendung
17
+#des Logging-Moduls einzustellen.
18
+# Auf Grund der Komplexitaet ist die intensive Verwendung von git und PAP anzuraten.
19
+#Autor :Zhang Kai  Milad shirvani filabadi, Yuan Wei
20
+#Datum : 20,05,2017
21
+#data-Erklaerung
22
+# 0   'loc_id', #OpenGeoDB Location ID
23
+# 1  'ags', # AGS - Amtlicher Gemeindeschluessel
24
+# 2   'ascii', # Normalized ASCII-only uppercase location name
25
+# 3  'name', # Actual (unicode) location name
26
+# 4   'lat', # Latitude in degrees (northern Latitude) weidu
27
+# 5   'lon', # Longitude in degrees(western Longitude) jingdu
28
+# 6  'amt', # Associated to
29
+# 7   'plz', # List of PLZ codes
30
+# 8  'vorwahl', # Telephone prefix
31
+# 9  'einwohner', # Population figure
32
+# 10   'flaeche', # Area
33
+# 11  'kz', # KFZ Kennzeichen
34
+# 12   'typ', # ?
35
+# 13   'level', # ?
36
+# 14   'of', # ?
37
+# 15   'invalid'])
38
+import  re #  stichworte suchen
39
+import os  #The OS module in Python provides a way of using operating system dependent
40
+                #functionality
41
+import sys     #system
42
+import logging
43
+import time as t
44
+from math import  cos, sin, asin, sqrt ,atan2
45
+from contextlib import contextmanager
46
+ort1 = []
47
+ort2 = []
48
+R = 6378.137#EARTH RADIUS
49
+def protokoll():
50
+    logging.info("You should see this info both in log file ")
51
+    logging.warning("You should see this warning both in log file ")
52
+    logging.error("You should see this error both in log file ")
53
+    logging.debug("You should ONLY see this debug in log file")
54
+    logging.basicConfig(level=logging.DEBUG,
55
+                format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
56
+                datefmt='%a, %d %b %Y %H:%M:%S',
57
+                filename='map.log',
58
+                filemode='w')
59
+protokoll ()
60
+def ort_name1 () :
61
+    i = 0
62
+    ort1=""
63
+    list1 = []#list entsthen
64
+    orts_info = open("DE.tab","r").readlines()
65
+    while True:
66
+        try :
67
+            ort1 = raw_input("Bitte  start_Stadt eingeben:").upper()#start-Stadt
68
+            break
69
+        except TypeError :
70
+            print("Tipps :ue,ae,oeund ss in ue,ae,oe und ss schreiben")
71
+        else :
72
+            break
73
+        break
74
+    print("Moechten Sie folgende Orte finden?")
75
+    for line1 in  orts_info :
76
+        if re.search(ort1,line1):
77
+            i = i + 1
78
+            line3 = re.split("\t",line1)# eine list entstehen
79
+            list1.append(line3)
80
+            print  "Ordnungszahl:{}, ort_name:{} PLZ:{}".format(i,line3[3],line3[7]) #Vorschlages
81
+    z=input("Bitte geben Sie die Ordnungszahl ein:")
82
+    l=len(list1)
83
+    for b in range(1,l) :
84
+        if z == b + 1 :
85
+            line3 = list1[b]
86
+    return line3
87
+def ort_name2 () :
88
+    i = 0
89
+    ort2 = ""
90
+    list1 = [] #list entsthen
91
+    orts_info = open("DE.tab","r").readlines()
92
+    while True:
93
+        try :
94
+            ort2 = raw_input("Bitte Ziel-Stadt eingeben:").upper()#ziel-Stadt
95
+            break
96
+        except TypeError :
97
+            print("Tipps :ue,ae,oeund ss in ue,ae,oe und ss schreiben")
98
+        else :
99
+            break
100
+        break
101
+    print("Moechten Sie folgende Orte finden?")
102
+    for line1 in  orts_info :
103
+        if re.search(ort2,line1):
104
+            i = i + 1
105
+            line3 = re.split("\t",line1)# eine list entstehen
106
+            list1.append(line3)
107
+            print  "Ordnungszahl:{}, ort_name:{} PLZ:{}".format(i,line3[3],line3[7]) #Vorschlages
108
+    z=input("Bitte geben sie die Ordnungszahl ein:")
109
+    l=len(list1)
110
+    line4 = 0
111
+    for b in range(1,l) :
112
+        if z == b + 1 :
113
+            line4 = list1[b]
114
+    return line4
115
+def Distanz():
116
+    ort1 = ort_name1()
117
+    ort2 = ort_name2()
118
+    #print "ort2:",ort2
119
+    #print "ort1:", ort1
120
+    lat1=float(ort1[5])#weidu
121
+    lon1=float(ort1[4])#jingdu
122
+    lat2=float(ort2[5])#
123
+    lon2=float(ort2[4])#
124
+    #lat1=ort1[5]#weidu
125
+    #lon1=ort1[4]#jingdu
126
+    #lat2=ort2[5]#
127
+    #lon2=ort2[4]
128
+
129
+    #haversine Gleichung
130
+    dlon = 71.5*(lon2 - lon1)
131
+    dlat = 111.3*(lat2 - lat1)
132
+
133
+    #a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
134
+    #c = 2 * atan2(sqrt(a),sqrt(1-a))
135
+    #c = 2 * asin(sqrt(a))
136
+
137
+    d =float(sqrt(dlon*dlon+dlat*dlat))
138
+    print ("Distanz von {} bis {}:{:0.2f}".format(ort1[3],ort2[3],d)+"km")
139
+
140
+Distanz()
141
+
142
+#a = ""
143
+#a = raw_input("moechten Sie nochmal finden ? a)nochmal b)ende:").upper
144
+#if a == "A" :
145
+    #Distanz()