def parseNearbyStationsNoKey(self, jsonData): stations = jsonData["stations"] s = self.settings llat = s.location.latitude llon = s.location.longitude arrStations = [] for stationDict in stations: stationId = stationDict["id"] stationType = stationDict["type"] if stationType == "PWS": lat1 = stationDict["latitude"] lon1 = stationDict["longitude"] distance = distanceBetweenGeographicCoordinatesAsKm( lat1, lon1, llat, llon) arrStations.append({ 'id': stationId, 'lat': lat1, 'lon': lon1, 'distance': distance }) arrStations = sorted(arrStations, key=lambda k: k['distance']) for stationDict in arrStations: self.params["_nearbyStationsIDList"].append( stationDict['id'] + " (" + str(round(stationDict['distance'], 1)) + "km" + "; lat=" + str(round(stationDict['lat'], 2)) + ", lon=" + str(round(stationDict['lon'], 2)) + ")")
def getNearbyStations(self, jsonData): try: nearbyStations = jsonData["location"]["nearby_weather_stations"] except: log.warning("No nearby stations found!") self.lastKnownError = "Warning: No nearby stations found!" return airportStations = None pwsStations = None try: airportStations = nearbyStations["airport"] except: log.warning("No airport stations found!") self.lastKnownError = "Warning: No airport stations found!" try: pwsStations = nearbyStations["pws"] except: log.warning("No pws stations found!") self.lastKnownError = "Warning: No pws stations found!" if pwsStations is not None: arrStations = pwsStations["station"] for st in arrStations: self.params["_nearbyStationsIDList"].append( str(st["id"]) + "(" + str(st["distance_km"]) + "km" + "; lat=" + str(round(st["lat"], 2)) + ", lon=" + str(round(st["lon"], 2)) + ")") if airportStations is not None: arrStations = airportStations["station"] for st in arrStations: distance = None if not st["icao"]: continue lat = self.__toFloat(st["lat"]) lon = self.__toFloat(st["lon"]) llat = self.settings.location.latitude llon = self.settings.location.longitude if lat is not None and lon is not None: # some airports don't report lat/lon distance = distanceBetweenGeographicCoordinatesAsKm( lat, lon, llat, llon) if distance is not None: distance = self.__toInt(round(distance)) infoStr = "(" + str(distance) + "km" + "; lat=" + str( round(lat, 2)) + ", lon=" + str(round(lon, 2)) + ")" else: distance = -1 infoStr = "(unknown distance)" self.params["_airportStationsIDList"].append( str(st["icao"]) + infoStr)
def distanceToStation(self, lat, lon): if RMOSPlatform().AUTODETECTED == RMOSPlatform.SIMULATED: llat = 47.1550897 llon = 27.5815751 else: s = self.settings llat = s.location.latitude llon = s.location.longitude return distanceBetweenGeographicCoordinatesAsKm(lat, lon, llat, llon)
def distanceToStation(self, lat, lon): if RMOSPlatform().AUTODETECTED == RMOSPlatform.SIMULATED: llat = 47.1550897 llon = 27.5815751 else: s = self.settings llat = s.location.latidude llon = s.location.longitude return distanceBetweenGeographicCoordinatesAsKm(lat, lon, llat, llon)
def getNearbyStations(self, jsonData): try: nearbyStations = jsonData["location"][ "nearby_weather_stations"] except: log.warning("No nearby stations found!") self.lastKnownError = "Warning: No nearby stations found!" return airportStations = None pwsStations = None try: airportStations = nearbyStations["airport"] except: log.warning("No airport stations found!") self.lastKnownError = "Warning: No airport stations found!" try: pwsStations = nearbyStations["pws"] except: log.warning("No pws stations found!") self.lastKnownError = "Warning: No pws stations found!" if pwsStations is not None: arrStations = pwsStations["station"] for st in arrStations: self.params["_nearbyStationsIDList"].append(str(st["id"]) + "(" + str(st["distance_km"]) + "km" + "; lat=" + str(round(st["lat"],2)) + ", lon=" + str(round(st["lon"],2)) + ")") if airportStations is not None: arrStations = airportStations["station"] for st in arrStations: distance = None if not st["icao"]: continue lat = self.__toFloat(st["lat"]) lon = self.__toFloat(st["lon"]) llat = self.settings.location.latitude llon = self.settings.location.longitude if lat is not None and lon is not None: # some airports don't report lat/lon distance = distanceBetweenGeographicCoordinatesAsKm(lat, lon, llat, llon) if distance is not None: distance = self.__toInt(round(distance)) else: distance = -1 self.params["_airportStationsIDList"].append(str(st["icao"]) + "(" + str(distance) + "km" + "; lat=" + str(round(lat,2)) + ", lon=" + str(round(lon,2)) + ")" )
def _discover_station(self): lat = self.settings.location.latitude lon = self.settings.location.longitude stations = self.openURL(IPMA_LOCATIONS_URL) if stations is None: self._log_error("Error: Unable to fetch the station list from " + IPMA_LOCATIONS_URL) return None else: stations = json.loads(stations.read()) for s in stations: s_lat = float(s['latitude']) s_lon = float(s['longitude']) d = distanceBetweenGeographicCoordinatesAsKm( s_lat, s_lon, lat, lon) if d < self.params[self.STATION_DISTANCE]: self.params[self.STATION] = s['local'] self.params[self.STATION_ID] = s['globalIdLocal'] self.params[self.STATION_DISTANCE] = d if self.params[self.STATION_DISTANCE] == MAX_STATION_DISTANCE: self._log_error("Error: Unable to discover a nearby station") return None return self.params[self.STATION_ID]
def distanceToStation(self, lat, lon): s = self.settings llat = s.location.latidude llon = s.location.longitude return distanceBetweenGeographicCoordinatesAsKm(lat, lon, llat, llon)
def getNearbyStations(self, jsonData): airportStations = {} pwsStations = {} llat = self.settings.location.latitude llon = self.settings.location.longitude try: for key in jsonData['response']: if len(key['id']) == 4: airportStations.update({str(key['id']): key['loc']}) log.debug("airportStations: {}".format(airportStations)) except: log.warning("No airport stations found!") self.lastKnownError = "Warning: No airport stations found!" try: for key in jsonData['response']: if ("MID" in key['id']) or ("PWS" in key['id']): pwsStations.update({str(key['id']): key['loc']}) log.debug("pwsStations: {}".format(pwsStations)) except: log.warning("No pws stations found!") self.lastKnownError = "Warning: No pws stations found!" if pwsStations: # arrStations = pwsStations["station"] for key in pwsStations: # print key # print pwsStations.get(key)['lat'] distance = None lat = pwsStations.get(key)['lat'] lon = pwsStations.get(key)['long'] log.debug("lat: {}, lon: {}, llat: {}, llon: {}".format( lat, lon, llat, llon)) if lat is not None and lon is not None: # some airports don't report lat/lon distance = distanceBetweenGeographicCoordinatesAsKm( lat, lon, llat, llon) print(distance) if distance is not None: distance = int(round(distance)) infoStr = "(" + str(distance) + "km" + "; lat=" + str( round(lat, 2)) + ", lon=" + str(round(lon, 2)) + ")" else: distance = -1 infoStr = "(unknown distance)" self.params["_nearbyStationsIDList"].append(key + infoStr) log.debug(self.params["_nearbyStationsIDList"]) if airportStations: for key in airportStations: distance = None lat = airportStations.get(key)['lat'] lon = airportStations.get(key)['long'] log.debug("lat: {}, lon: {}, llat: {}, llon: {}".format( lat, lon, llat, llon)) if lat is not None and lon is not None: # some airports don't report lat/lon distance = distanceBetweenGeographicCoordinatesAsKm( lat, lon, llat, llon) print(distance) if distance is not None: distance = int(round(distance)) infoStr = "(" + str(distance) + "km" + "; lat=" + str( round(lat, 2)) + ", lon=" + str(round(lon, 2)) + ")" else: distance = -1 infoStr = "(unknown distance)" self.params["_airportStationsIDList"].append(key + infoStr) log.debug(self.params["_airportStationsIDList"])
def distanceToStation(self, lat, lon): s = self.settings llat = s.location.latidude llon = s.location.longitude return distanceBetweenGeographicCoordinatesAsKm(lat, lon, llat, llon)