import xml.etree.ElementTree as ET import coord_to_xy import math from PIL import Image from PIL.ImageDraw import Draw zoom = 10 import item from getLineData import lineInfo plaatjes = {} def drawMap(lat,long,screenDim,Img): (x_tile,y_tile) = coord_to_xy.degree_to_coord(math.radians(lat),math.radians(long),zoom) (x_real,y_real)= coord_to_xy.degree_to_real_coord(math.radians(lat),math.radians(long),zoom) (x_tile_offset, y_tile_offset) = (x_real%256,y_real%256) (w,h) = screenDim tiles_width = math.ceil(w/256) tiles_height = math.ceil(h/256) for x in range(0,tiles_width): for y in range(0,tiles_height): tile_x = x+x_tile-tiles_width//2 tile_y = y+y_tile-tiles_height//2 if not ((tile_x,tile_y) in plaatjes): coord_to_xy.coord_to_download(tile_x,tile_y,zoom,"hey.png") plaatjes[(tile_x,tile_y)]=Image.open("hey.png") #afbeeldingen.append(Label(scherm)) upper_x = int(x*256-x_tile_offset-64) upper_y = int(y*256-y_tile_offset+24) Img.paste(plaatjes[(tile_x,tile_y)],box=(upper_x,upper_y)) #afbeeldingen[i].place(x=x*256-x_tile_offset,y=y*256-y_tile_offset) #omgezetPlaatjes.append(PhotoImage(plaatjes[i])) def degree_to_pix(lat_point,long_point,x_camera,y_camera,screenDim): (w,h) = screenDim (x_point,y_point)= coord_to_xy.degree_to_real_coord(math.radians(lat_point),math.radians(long_point),zoom) return(x_point-x_camera+w//2,y_point-y_camera+h//2) #Source https://www.omnicalculator.com/other/latitude-longitude-distance def dist_coords(latd1,longd1,latd2,longd2): R = 6378.137 lat1 = math.radians(latd1) long1 = math.radians(longd1) lat2 = math.radians(latd2) long2 = math.radians(longd2) #d = 2R × sin⁻¹(√[sin²((θ₂ - θ₁)/2) + cosθ₁ × cosθ₂ × sin²((φ₂ - φ₁)/2)]) d = 2*R*math.asin(math.sqrt(math.sin((lat1-lat2)/2)**2+math.cos(lat1)*math.cos(lat2)*math.sin((long2-long1)/2)**2)) return(d) #def dist_coords(latd1,longd1,latd2,longd2): # lat1 = math.radians(latd1) # long1 = math.radians(longd1) # lat2 = math.radians(latd2) # long2 = math.radians(longd2) # x1 = math.cos(lat1)*math.cos(long1) # y1 = math.sin(lat1)*math.cos(long1) # z1 = math.sin(long1) # # x2 = math.cos(lat2)*math.cos(long2) # y2 = math.sin(lat2)*math.cos(long2) # z2 = math.sin(long2) # # print((x1*x2+y1*y2+z1*z2,x1**2+y1**2+z1**2,x2**2+y2**2+z2**2)) # angle = math.acos(x1*x2+y1*y2+z1*z2) # return(40075.017*angle/(2*math.pi)) def drawLine(name,lat,long,screenDim,lineNum): Img = Image.new(mode="RGBA", size=screenDim) draw = Draw(Img) (x_real,y_real)= coord_to_xy.degree_to_real_coord(math.radians(lat),math.radians(long),zoom) tree = ET.parse(name) trkseg = tree.getroot()[1][1] points = [] station_points = [] dist =0 prev_lat_point =0 prev_lon_point =0 first = True stations = lineInfo(lineNum) si = 0 for trkpt in trkseg: lat_point = trkpt.items()[0][1] lon_point = trkpt.items()[1][1] points.append((float(lat_point),float(lon_point))) if(not first): dist+=dist_coords(float(prev_lat_point),float(prev_lon_point),float(lat_point),float(lon_point)) print(dist) if(si=stations[si][0]): si+=1 station_points.append((float(lat_point),float(lon_point))) (prev_lat_point,prev_lon_point)=(lat_point,lon_point) first = False print(station_points) first = True (prev_x,prev_y) = (0,0) drawMap(lat,long,screenDim,Img) for (lat_point,lon_point) in points: (x,y) = degree_to_pix(lat_point,lon_point,x_real,y_real,screenDim) if(not first): draw.line(((x,y),(prev_x,prev_y)), fill='black', width=4, joint=None) #print(((x,y),(prev_x,prev_y))) (prev_x,prev_y)=(x,y) first = False for (lat,lon) in station_points: (x,y) = degree_to_pix(lat,lon,x_real,y_real,screenDim) draw.ellipse(((x-8,y-8),(x+8,y+8)),"black") draw.ellipse(((x-4,y-4),(x+4,y+4)),"white") Img.show() def drawLineChronological(name,screenDim,lineNum): items = getItemList(name,lineNum) item.animate(items,screenDim) #events = [] #events.append(item.line(name,"black","1 jan 1900")) #for station in stations: # for opening in station.openings: # events.append(Station(station.name, #print(dist_coords(63.98470, -22.61021,52.30887, 4.76240)) drawLine("39.gpx",52.2349, 6.0796,(1920,1080),39)#Apeldoorn-Deventer #drawLine("69.gpx",51.952377, 5.218356,(1920,1080),69)#Apeldoorn-Deventer #print(dist_coords(0, 0,180, 0))