Guest User

Untitled

a guest
Apr 28th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import csv
  4. from tkinter import Tk, Canvas, mainloop, SW
  5.  
  6. #Klasse Bahnhof
  7. class Bahnhof(object):
  8.     def __init__(self, name, breite, laenge):
  9.         self.name = name
  10.         self.breite = float(breite)
  11.         self.laenge = float(laenge)
  12.  
  13.     def isHbf(self):
  14.         return "Hbf" in self.name
  15.  
  16.  
  17. #Parsen der csv-Datei und Erzeugen der Bahnhöfe
  18. alleBahnhoefe = []
  19. with open("D_Bahnhof_2016_01_alle.csv") as csv_file:
  20.     reader = csv.reader(csv_file,delimiter=';')
  21.     for row in reader:
  22.         alleBahnhoefe.append(Bahnhof(row[2],row[4],row[5]))
  23.  
  24. #Bestimmen der max/min Breiten und Längen
  25. maxLaenge = max(bahnhof.laenge for bahnhof in alleBahnhoefe)
  26. minLaenge = min(bahnhof.laenge for bahnhof in alleBahnhoefe)
  27. maxBreite = max(bahnhof.breite for bahnhof in alleBahnhoefe)
  28. minBreite = min(bahnhof.breite for bahnhof in alleBahnhoefe)
  29.  
  30. #Zeichnen der Punkte
  31. master = Tk()
  32. canvas_width = 600
  33. canvas_height = 600
  34. w = Canvas(master, width=canvas_width, height=canvas_height)
  35. w.pack()
  36.  
  37. #Normale Bahnhöfe in Blau
  38. for curBahnhof in alleBahnhoefe:
  39.     actLaenge = (canvas_width) / (maxLaenge-minLaenge) * (curBahnhof.laenge-minLaenge);
  40.     actBreite = (canvas_height) / (maxBreite-minBreite) * (curBahnhof.breite-minBreite);
  41.     actX = int(actBreite);
  42.     actY = int(canvas_height-actLaenge);
  43.     if curBahnhof.isHbf():
  44.         w.create_oval(actX,actY, actX+5,actY+5, fill="#ff0000")
  45.         w.create_text(actX+5,actY+5,text=curBahnhof.name[:2], fill="#ff0000",
  46.                        anchor=SW, activefill="yellow")
  47.     else:
  48.         w.lower(w.create_oval(actX,actY, actX+5,actY+5, fill="#000000"))
  49.  
  50. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment