From 82fc267b22b43f763a3622c250d46be06a2615ce Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Mon, 28 Mar 2016 17:04:37 +0200 Subject: [PATCH] Fetch weather data by grid and range instead of geo location refs #612 --- src/blackcore/weatherdata.h | 5 ++-- .../weatherdata/gfs/weatherdatagfs.cpp | 23 ++++++++++++++----- src/plugins/weatherdata/gfs/weatherdatagfs.h | 10 ++++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/blackcore/weatherdata.h b/src/blackcore/weatherdata.h index a7a92e4f0..6da504de3 100644 --- a/src/blackcore/weatherdata.h +++ b/src/blackcore/weatherdata.h @@ -32,8 +32,9 @@ namespace BlackCore //! Destructor virtual ~IWeatherData() {} - //! Fetch new weather data - virtual void fetchWeatherData(const BlackMisc::Geo::CLatitude &latitude, const BlackMisc::Geo::CLongitude &longitude, double maxDistance = -1) = 0; + //! Fetch new weather data around grid + virtual void fetchWeatherData(const BlackMisc::Weather::CWeatherGrid &grid, + const BlackMisc::PhysicalQuantities::CLength &range) = 0; //! Get fetched weather data virtual BlackMisc::Weather::CWeatherGrid getWeatherData() const = 0; diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp index a0c5530ca..a428d2514 100644 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.cpp +++ b/src/plugins/weatherdata/gfs/weatherdatagfs.cpp @@ -52,11 +52,10 @@ namespace BlackWxPlugin connect(&m_networkAccessManager, &QNetworkAccessManager::finished, this, &CWeatherDataGfs::ps_parseGfsFile); } - void CWeatherDataGfs::fetchWeatherData(const CLatitude &latitude, const CLongitude &longitude, double maxDistance) + void CWeatherDataGfs::fetchWeatherData(const CWeatherGrid &grid, const CLength &range) { - m_latitude = latitude; - m_longitude = longitude; - m_maxDistance = maxDistance; + m_grid = grid; + m_maxRange = range; if (m_gribData.isEmpty()) { CLogMessage(this).debug() << "Started to download GFS data..."; @@ -422,11 +421,23 @@ namespace BlackWxPlugin if(gridPoint.longitude < 0.0) { gridPoint.longitude += 360.0; } gridPoint.fieldPosition = ix + i; CCoordinateGeodetic gridPointPosition(gridPoint.latitude, gridPoint.longitude, 0); - CCoordinateGeodetic centralPosition(m_latitude, m_longitude, {0}); - if ((m_maxDistance == -1) || calculateEuclideanDistance(gridPointPosition, centralPosition) < m_maxDistance ) + if (m_maxRange == CLength()) { m_gfsWeatherGrid.append(gridPoint); } + else + { + for (const CGridPoint &fixedGridPoint : as_const(m_grid)) + { + auto distance = calculateGreatCircleDistance(gridPointPosition, fixedGridPoint.getPosition()).value(CLengthUnit::m()); + auto maxRange = m_maxRange.value(CLengthUnit::m()); + if (distance < maxRange) + { + m_gfsWeatherGrid.append(gridPoint); + break; + } + } + } } } } diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.h b/src/plugins/weatherdata/gfs/weatherdatagfs.h index ebe1618e5..844b0d27b 100644 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.h +++ b/src/plugins/weatherdata/gfs/weatherdatagfs.h @@ -40,8 +40,9 @@ namespace BlackWxPlugin //! Constructor CWeatherDataGfs(QObject *parent = nullptr); - //! \copydoc BlackCore::IWeatherData::fetchWeatherData() - virtual void fetchWeatherData(const BlackMisc::Geo::CLatitude &latitude, const BlackMisc::Geo::CLongitude &longitude, double maxDistance = -1) override; + //! \copydoc BlackCore::IWeatherData::fetchWeatherData + virtual void fetchWeatherData(const BlackMisc::Weather::CWeatherGrid &grid, + const BlackMisc::PhysicalQuantities::CLength &range) override; //! \copydoc BlackCore::IWeatherData::getWeatherData() virtual BlackMisc::Weather::CWeatherGrid getWeatherData() const override; @@ -134,9 +135,8 @@ namespace BlackWxPlugin void setCloudCoverage(const g2float *fld, int level); void setCloudLevel(const g2float *fld, int surfaceType, int level); - BlackMisc::Geo::CLatitude m_latitude; - BlackMisc::Geo::CLongitude m_longitude; - double m_maxDistance = -1; + BlackMisc::Weather::CWeatherGrid m_grid; + BlackMisc::PhysicalQuantities::CLength m_maxRange; mutable QReadWriteLock m_lockData; QByteArray m_gribData;