def getProperAlt(origin, destination, course): start = str(origin.latlon) end = str(destination.latlon) path = start + "|" + end elevations = getElevation(path, chartSize="700x200") # get the maximum altitude maxAlt = max(elevations) # for hemispheric rule for cruising altitudes start_lat = start.split(", ")[0] start_lon = start.split(", ")[1] mag_hdg = mag_heading(float(course[1]), float(start_lat), float(start_lon)) # Get the magnetic heading cruise_alt = roundthousand(maxAlt * meters_to_feet) thousands = int(cruise_alt / 1000) if mag_hdg >= 0 and mag_hdg <= 179: if (thousands % 2 == 0): cruise_alt += 1000 else: if not thousands % 2 == 0: cruise_alt += 1000 # for all VFR flights cruise_alt += 500 if (cruise_alt < 1500): cruise_alt += 2000 pathMap = getChart(elevations) return (cruise_alt, pathMap)
def get_bearing(lat1, lon1, lat2, lon2): """ Calculate the bearing between two coordinates :param a pair of lat,lon coordinates: :return: bearing in degrees """ waypoint_1 = xyz(lat1, lon1) waypoint_2 = xyz(lat2, lon2) true_north = great_circle_angle(waypoint_2, waypoint_1, geographic_northpole) bearing = geomag.mag_heading(true_north, dlat=lat1, dlon=lon1) return bearing
def update_data(self): if self.start_pos==None or self.dest_pos==None: return self.data_dist.set_text("Distance: %f km" % (geo.distance(self.start_pos,self.dest_pos)/1000.)) if not self.start_pos==self.dest_pos: if HAVE_GEOMAG: true_north = geo.great_circle_angle(self.dest_pos,self.start_pos,geo.geographic_northpole) angle = geomag.mag_heading(true_north,dlat=self.start_lat,dlon=self.start_lon) else: angle = geo.great_circle_angle(self.dest_pos,self.start_pos,geo.magnetic_northpole) self.data_dir.set_text("Direction: %f\xc2\xb0 from north (%s)" % (angle, geo.direction_name(angle))) else: self.data_dir.set_text("Start point and destination is the same!")
def magCorrect(self): self.mag_hdg = mag_heading( float(self.true_hdg), float(self.from_poi.lat), float(self.from_poi.lon)) # Get the magnetic heading self.mag_var = float("{0:.2f}".format( getHeadingDiff(self.true_hdg, self.mag_hdg)))
def radial_dme(lat, lon, elev=12., test_date=datetime.date.today(), maxdist=250.): # Read the list of NAVAIDs # PATH needs to be replaced by generic navaid_file = os.path.join(MSUI_CONFIG_PATH, 'plugins', 'NAVAID_System.csv') navaid = open(navaid_file, encoding='utf-8-sig') csvreader = csv.reader(navaid) header = next(csvreader) ix = header.index('X') iy = header.index('Y') itype = header.index('TYPE_CODE') iident = header.index('IDENT') locations = [] navidents = [] for row in csvreader: # Find the ones that are useful to the pilots (types 6, 7, or 8) type_code = int(row[itype]) if type_code == 6 or type_code == 7 or type_code == 8: navlon = float(row[ix]) navlat = float(row[iy]) locations.append((navlat, navlon)) navidents.append(row[iident]) # Determine nearest NAVAID to the lat/lon point in nautical miles. position = (lat, lon) dist = [geodesic(position, i).nm for i in locations] minpos = dist.index(min(dist)) navident = navidents[minpos] navlat = locations[minpos][0] navlon = locations[minpos][1] # Calculate the true heading to the nearest NAVAID # Uses WGS84 ellipsoid for the earth true_bear = Geodesic.WGS84.Inverse(navlat, navlon, lat, lon)['azi1'] # Convert to magnetic heading (note: elevation converted to feet) mag_bear = geomag.mag_heading(true_bear, dlat=lat, dlon=lon, h=elev * 3280.8399, time=test_date) # Round to whole numbers az = round(mag_bear) rng = round(dist[minpos]) # Print and return values lonx = np.mod((lon + 180), 360) - 180 hemx = 'E' if lonx < 0: hemx = 'W' hemy = 'N' if lat < 0: hemy = 'S' lonx = np.abs(lonx) latx = np.abs(lat) latdeg = int(np.floor(latx)) londeg = int(np.floor(lonx)) latmin = int(round((latx - np.floor(latx)) * 60.)) lonmin = int(round((lonx - np.floor(lonx)) * 60.)) if rng > maxdist: wpt_str = '{:02d}{:02d}{}{:03d}{:02d}{}'.format( latdeg, latmin, hemy, londeg, lonmin, hemx) else: wpt_str = '{}{:03d}{:03d}'.format(navident, az, rng) if rng <= 1: wpt_str = navident return wpt_str