Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. import csv
  2. import math
  3.  
  4. csv2 = open('Merge.csv','w')
  5.  
  6. with open("stationLongLatVind.csv") as f:
  7.        read1 = csv.reader(f, delimiter=';')
  8.        weather= filter(None,read1)
  9.        print "klar"
  10.  
  11. with open("GPSCoord.csv") as f:
  12.        read2 = csv.reader(f, delimiter=';')
  13.        train= filter(None,read2)
  14.        print "klar"
  15.  
  16. def distance(p0, p1):
  17.     return math.sqrt((float(p0[0]) - float(p1[0]))**2 + (float(p0[1]) - float(p1[1]))**2)
  18.  
  19.  
  20. csv2.write("Train station;")
  21. csv2.write("Weather station id;")
  22. csv2.write("Distance;")
  23. csv2.write("tlong;")
  24. csv2.write("tlat;")
  25. csv2.write("wlong;")
  26. csv2.write("wlat")
  27. csv2.write("\n")
  28.  
  29.  
  30. for index1 in range(len(train)-1):
  31.  
  32.     shortest = 999
  33.     row=[]
  34.  
  35.     for index2 in range(len(weather)-1):        
  36.         if distance(train[index1+1][0:2], weather[index2+1][2:4]) < shortest and weather[index2+1][1].startswith("2014"):
  37.  
  38.             shortest = distance(train[index1+1][0:2], weather[index2+1][1:3])
  39.             a = train[index1+1][0]
  40.             b = train[index1+1][1]
  41.             c = train[index1+1][2]
  42.             d = weather[index2+1][0]
  43.             e = weather[index2+1][2]
  44.             f = weather[index2+1][3]
  45.            
  46.     csv2.write(c+";")
  47.     csv2.write(d+";")
  48.     csv2.write(str(shortest)+";")
  49.     csv2.write(a+";")
  50.     csv2.write(b+";")
  51.     csv2.write(e+";")
  52.     csv2.write(f)
  53.     csv2.write("\n")
  54.    
  55.  
  56.     print index1
  57.            
  58.  
  59. csv2.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement