mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:50:05 +00:00
Get coordinates from radar site configuration
This commit is contained in:
parent
29ce4b1eb8
commit
3620bfd13a
8 changed files with 93 additions and 36 deletions
|
|
@ -14,6 +14,9 @@ namespace config
|
||||||
|
|
||||||
static const std::string logPrefix_ = "[scwx::qt::settings::radar_site] ";
|
static const std::string logPrefix_ = "[scwx::qt::settings::radar_site] ";
|
||||||
|
|
||||||
|
static const std::string defaultRadarSiteFile_ =
|
||||||
|
":/res/config/radar_sites.json";
|
||||||
|
|
||||||
static std::unordered_map<std::string, std::shared_ptr<RadarSite>>
|
static std::unordered_map<std::string, std::shared_ptr<RadarSite>>
|
||||||
radarSiteMap_;
|
radarSiteMap_;
|
||||||
|
|
||||||
|
|
@ -97,8 +100,16 @@ std::shared_ptr<RadarSite> RadarSite::Get(const std::string& id)
|
||||||
return radarSite;
|
return radarSite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RadarSite::Initialize()
|
||||||
|
{
|
||||||
|
ReadConfig(defaultRadarSiteFile_);
|
||||||
|
}
|
||||||
|
|
||||||
size_t RadarSite::ReadConfig(const std::string& path)
|
size_t RadarSite::ReadConfig(const std::string& path)
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(info) << logPrefix_ << "Loading radar sites from \""
|
||||||
|
<< path << "\"...";
|
||||||
|
|
||||||
bool dataValid = true;
|
bool dataValid = true;
|
||||||
size_t sitesAdded = 0;
|
size_t sitesAdded = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ public:
|
||||||
|
|
||||||
static std::shared_ptr<RadarSite> Get(const std::string& id);
|
static std::shared_ptr<RadarSite> Get(const std::string& id);
|
||||||
|
|
||||||
|
static void Initialize();
|
||||||
static size_t ReadConfig(const std::string& path);
|
static size_t ReadConfig(const std::string& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <scwx/qt/config/radar_site.hpp>
|
||||||
#include <scwx/qt/main/main_window.hpp>
|
#include <scwx/qt/main/main_window.hpp>
|
||||||
#include <scwx/qt/manager/resource_manager.hpp>
|
#include <scwx/qt/manager/resource_manager.hpp>
|
||||||
#include <scwx/qt/manager/settings_manager.hpp>
|
#include <scwx/qt/manager/settings_manager.hpp>
|
||||||
|
|
@ -13,6 +14,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
QCoreApplication::setApplicationName("Supercell Wx");
|
QCoreApplication::setApplicationName("Supercell Wx");
|
||||||
|
|
||||||
|
scwx::qt::config::RadarSite::Initialize();
|
||||||
scwx::qt::manager::SettingsManager::Initialize();
|
scwx::qt::manager::SettingsManager::Initialize();
|
||||||
scwx::qt::manager::ResourceManager::PreLoad();
|
scwx::qt::manager::ResourceManager::PreLoad();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include <scwx/qt/manager/radar_product_manager.hpp>
|
#include <scwx/qt/manager/radar_product_manager.hpp>
|
||||||
#include <scwx/common/constants.hpp>
|
#include <scwx/common/constants.hpp>
|
||||||
|
#include <scwx/qt/config/radar_site.hpp>
|
||||||
#include <scwx/util/threads.hpp>
|
#include <scwx/util/threads.hpp>
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
@ -38,15 +39,25 @@ static std::unordered_map<std::string, std::shared_ptr<RadarProductManager>>
|
||||||
class RadarProductManagerImpl
|
class RadarProductManagerImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit RadarProductManagerImpl(const std::string& radarSite) :
|
explicit RadarProductManagerImpl(const std::string& radarId) :
|
||||||
radarSite_ {radarSite}, initialized_ {false}
|
radarId_ {radarId},
|
||||||
|
initialized_ {false},
|
||||||
|
radarSite_ {config::RadarSite::Get(radarId)}
|
||||||
{
|
{
|
||||||
|
if (radarSite_ == nullptr)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(warning)
|
||||||
|
<< logPrefix_ << "Radar site not found: \"" << radarId_ << "\"";
|
||||||
|
radarSite_ = std::make_shared<config::RadarSite>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
~RadarProductManagerImpl() = default;
|
~RadarProductManagerImpl() = default;
|
||||||
|
|
||||||
std::string radarSite_;
|
std::string radarId_;
|
||||||
bool initialized_;
|
bool initialized_;
|
||||||
|
|
||||||
|
std::shared_ptr<config::RadarSite> radarSite_;
|
||||||
|
|
||||||
std::vector<float> coordinates0_5Degree_;
|
std::vector<float> coordinates0_5Degree_;
|
||||||
std::vector<float> coordinates1Degree_;
|
std::vector<float> coordinates1Degree_;
|
||||||
|
|
||||||
|
|
@ -57,8 +68,8 @@ public:
|
||||||
std::mutex fileLoadMutex_;
|
std::mutex fileLoadMutex_;
|
||||||
};
|
};
|
||||||
|
|
||||||
RadarProductManager::RadarProductManager(const std::string& radarSite) :
|
RadarProductManager::RadarProductManager(const std::string& radarId) :
|
||||||
p(std::make_unique<RadarProductManagerImpl>(radarSite))
|
p(std::make_unique<RadarProductManagerImpl>(radarId))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
RadarProductManager::~RadarProductManager() = default;
|
RadarProductManager::~RadarProductManager() = default;
|
||||||
|
|
@ -75,6 +86,11 @@ RadarProductManager::coordinates(common::RadialSize radialSize) const
|
||||||
throw std::exception("Invalid radial size");
|
throw std::exception("Invalid radial size");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<config::RadarSite> RadarProductManager::radar_site() const
|
||||||
|
{
|
||||||
|
return p->radarSite_;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<const wsr88d::Ar2vFile> RadarProductManager::level2_data() const
|
std::shared_ptr<const wsr88d::Ar2vFile> RadarProductManager::level2_data() const
|
||||||
{
|
{
|
||||||
std::shared_ptr<const wsr88d::Ar2vFile> level2Data = nullptr;
|
std::shared_ptr<const wsr88d::Ar2vFile> level2Data = nullptr;
|
||||||
|
|
@ -101,8 +117,8 @@ void RadarProductManager::Initialize()
|
||||||
GeographicLib::Geodesic geodesic(GeographicLib::Constants::WGS84_a(),
|
GeographicLib::Geodesic geodesic(GeographicLib::Constants::WGS84_a(),
|
||||||
GeographicLib::Constants::WGS84_f());
|
GeographicLib::Constants::WGS84_f());
|
||||||
|
|
||||||
// TODO: This should be retrieved from configuration
|
const QMapbox::Coordinate radar(p->radarSite_->latitude(),
|
||||||
const QMapbox::Coordinate radar(38.6986, -90.6828);
|
p->radarSite_->longitude());
|
||||||
|
|
||||||
// Calculate half degree azimuth coordinates
|
// Calculate half degree azimuth coordinates
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
@ -117,7 +133,8 @@ void RadarProductManager::Initialize()
|
||||||
std::execution::par_unseq,
|
std::execution::par_unseq,
|
||||||
radialGates0_5Degree.begin(),
|
radialGates0_5Degree.begin(),
|
||||||
radialGates0_5Degree.end(),
|
radialGates0_5Degree.end(),
|
||||||
[&](uint32_t radialGate) {
|
[&](uint32_t radialGate)
|
||||||
|
{
|
||||||
const uint16_t gate =
|
const uint16_t gate =
|
||||||
static_cast<uint16_t>(radialGate % common::MAX_DATA_MOMENT_GATES);
|
static_cast<uint16_t>(radialGate % common::MAX_DATA_MOMENT_GATES);
|
||||||
const uint16_t radial =
|
const uint16_t radial =
|
||||||
|
|
@ -154,7 +171,8 @@ void RadarProductManager::Initialize()
|
||||||
std::execution::par_unseq,
|
std::execution::par_unseq,
|
||||||
radialGates1Degree.begin(),
|
radialGates1Degree.begin(),
|
||||||
radialGates1Degree.end(),
|
radialGates1Degree.end(),
|
||||||
[&](uint32_t radialGate) {
|
[&](uint32_t radialGate)
|
||||||
|
{
|
||||||
const uint16_t gate =
|
const uint16_t gate =
|
||||||
static_cast<uint16_t>(radialGate % common::MAX_DATA_MOMENT_GATES);
|
static_cast<uint16_t>(radialGate % common::MAX_DATA_MOMENT_GATES);
|
||||||
const uint16_t radial =
|
const uint16_t radial =
|
||||||
|
|
@ -221,19 +239,21 @@ RadarProductManager::GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
scwx::util::async([&]() {
|
scwx::util::async(
|
||||||
std::lock_guard<std::mutex> guard(p->fileLoadMutex_);
|
[&]()
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Start load";
|
|
||||||
|
|
||||||
QString filename = qgetenv("AR2V_FILE");
|
|
||||||
if (!filename.isEmpty() && p->level2VolumeScans_.size() == 0)
|
|
||||||
{
|
{
|
||||||
LoadLevel2Data(filename.toUtf8().constData());
|
std::lock_guard<std::mutex> guard(p->fileLoadMutex_);
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "End load";
|
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Start load";
|
||||||
});
|
|
||||||
|
QString filename = qgetenv("AR2V_FILE");
|
||||||
|
if (!filename.isEmpty() && p->level2VolumeScans_.size() == 0)
|
||||||
|
{
|
||||||
|
LoadLevel2Data(filename.toUtf8().constData());
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "End load";
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::tie(radarData, elevationCut, elevationCuts);
|
return std::tie(radarData, elevationCut, elevationCuts);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <scwx/common/types.hpp>
|
#include <scwx/common/types.hpp>
|
||||||
|
#include <scwx/qt/config/radar_site.hpp>
|
||||||
#include <scwx/wsr88d/ar2v_file.hpp>
|
#include <scwx/wsr88d/ar2v_file.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -22,10 +23,11 @@ class RadarProductManager : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RadarProductManager(const std::string& radarSite);
|
explicit RadarProductManager(const std::string& radarId);
|
||||||
~RadarProductManager();
|
~RadarProductManager();
|
||||||
|
|
||||||
const std::vector<float>& coordinates(common::RadialSize radialSize) const;
|
const std::vector<float>& coordinates(common::RadialSize radialSize) const;
|
||||||
|
std::shared_ptr<config::RadarSite> radar_site() const;
|
||||||
|
|
||||||
// TODO: Improve this interface
|
// TODO: Improve this interface
|
||||||
std::shared_ptr<const wsr88d::Ar2vFile> level2_data() const;
|
std::shared_ptr<const wsr88d::Ar2vFile> level2_data() const;
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,13 @@ void MapWidget::SelectRadarProduct(common::Level2Product product)
|
||||||
this,
|
this,
|
||||||
[&]()
|
[&]()
|
||||||
{
|
{
|
||||||
RadarRangeLayer::Update(p->map_, radarProductView->range());
|
std::shared_ptr<config::RadarSite> radarSite =
|
||||||
|
p->radarProductManager_->radar_site();
|
||||||
|
|
||||||
|
RadarRangeLayer::Update(
|
||||||
|
p->map_,
|
||||||
|
radarProductView->range(),
|
||||||
|
{radarSite->latitude(), radarSite->longitude()});
|
||||||
update();
|
update();
|
||||||
emit RadarSweepUpdated();
|
emit RadarSweepUpdated();
|
||||||
},
|
},
|
||||||
|
|
@ -301,6 +307,9 @@ void MapWidget::AddLayers()
|
||||||
std::unique_ptr<QMapbox::CustomLayerHostInterface> pColorTableHost =
|
std::unique_ptr<QMapbox::CustomLayerHostInterface> pColorTableHost =
|
||||||
std::make_unique<LayerWrapper>(p->colorTableLayer_);
|
std::make_unique<LayerWrapper>(p->colorTableLayer_);
|
||||||
|
|
||||||
|
std::shared_ptr<config::RadarSite> radarSite =
|
||||||
|
p->radarProductManager_->radar_site();
|
||||||
|
|
||||||
QString before = "ferry";
|
QString before = "ferry";
|
||||||
|
|
||||||
for (const QString& layer : p->map_->layerIds())
|
for (const QString& layer : p->map_->layerIds())
|
||||||
|
|
@ -315,8 +324,9 @@ void MapWidget::AddLayers()
|
||||||
}
|
}
|
||||||
|
|
||||||
p->map_->addCustomLayer("radar", std::move(pHost), before);
|
p->map_->addCustomLayer("radar", std::move(pHost), before);
|
||||||
RadarRangeLayer::Add(
|
RadarRangeLayer::Add(p->map_,
|
||||||
p->map_, p->context_->radarProductView_->range(), before);
|
p->context_->radarProductView_->range(),
|
||||||
|
{radarSite->latitude(), radarSite->longitude()});
|
||||||
p->map_->addCustomLayer("colorTable", std::move(pColorTableHost));
|
p->map_->addCustomLayer("colorTable", std::move(pColorTableHost));
|
||||||
p->map_->addCustomLayer("overlay", std::move(pOverlayHost));
|
p->map_->addCustomLayer("overlay", std::move(pOverlayHost));
|
||||||
}
|
}
|
||||||
|
|
@ -421,8 +431,11 @@ void MapWidget::initializeGL()
|
||||||
p.get(),
|
p.get(),
|
||||||
&MapWidgetImpl::Update);
|
&MapWidgetImpl::Update);
|
||||||
|
|
||||||
// Set default location to KLSX.
|
// Set default location to radar site
|
||||||
p->map_->setCoordinateZoom(QMapbox::Coordinate(38.6986, -90.6828), 9);
|
std::shared_ptr<config::RadarSite> radarSite =
|
||||||
|
p->radarProductManager_->radar_site();
|
||||||
|
p->map_->setCoordinateZoom({radarSite->latitude(), radarSite->longitude()},
|
||||||
|
9);
|
||||||
p->UpdateStoredMapParameters();
|
p->UpdateStoredMapParameters();
|
||||||
|
|
||||||
QString styleUrl = qgetenv("MAPBOX_STYLE_URL");
|
QString styleUrl = qgetenv("MAPBOX_STYLE_URL");
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,12 @@ namespace map
|
||||||
|
|
||||||
static const std::string logPrefix_ = "[scwx::qt::map::radar_range_layer] ";
|
static const std::string logPrefix_ = "[scwx::qt::map::radar_range_layer] ";
|
||||||
|
|
||||||
static std::shared_ptr<QMapbox::Feature> GetRangeCircle(float range);
|
static std::shared_ptr<QMapbox::Feature>
|
||||||
|
GetRangeCircle(float range, QMapbox::Coordinate center);
|
||||||
|
|
||||||
void RadarRangeLayer::Add(std::shared_ptr<QMapboxGL> map,
|
void RadarRangeLayer::Add(std::shared_ptr<QMapboxGL> map,
|
||||||
float range,
|
float range,
|
||||||
|
QMapbox::Coordinate center,
|
||||||
const QString& before)
|
const QString& before)
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Add()";
|
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Add()";
|
||||||
|
|
@ -30,7 +32,8 @@ void RadarRangeLayer::Add(std::shared_ptr<QMapboxGL> map,
|
||||||
map->removeSource("rangeCircleSource");
|
map->removeSource("rangeCircleSource");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<QMapbox::Feature> rangeCircle = GetRangeCircle(range);
|
std::shared_ptr<QMapbox::Feature> rangeCircle =
|
||||||
|
GetRangeCircle(range, center);
|
||||||
|
|
||||||
map->addSource(
|
map->addSource(
|
||||||
"rangeCircleSource",
|
"rangeCircleSource",
|
||||||
|
|
@ -43,15 +46,19 @@ void RadarRangeLayer::Add(std::shared_ptr<QMapboxGL> map,
|
||||||
"rangeCircleLayer", "line-color", "rgba(128, 128, 128, 128)");
|
"rangeCircleLayer", "line-color", "rgba(128, 128, 128, 128)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadarRangeLayer::Update(std::shared_ptr<QMapboxGL> map, float range)
|
void RadarRangeLayer::Update(std::shared_ptr<QMapboxGL> map,
|
||||||
|
float range,
|
||||||
|
QMapbox::Coordinate center)
|
||||||
{
|
{
|
||||||
std::shared_ptr<QMapbox::Feature> rangeCircle = GetRangeCircle(range);
|
std::shared_ptr<QMapbox::Feature> rangeCircle =
|
||||||
|
GetRangeCircle(range, center);
|
||||||
|
|
||||||
map->updateSource("rangeCircleSource",
|
map->updateSource("rangeCircleSource",
|
||||||
{{"data", QVariant::fromValue(*rangeCircle)}});
|
{{"data", QVariant::fromValue(*rangeCircle)}});
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<QMapbox::Feature> GetRangeCircle(float range)
|
static std::shared_ptr<QMapbox::Feature>
|
||||||
|
GetRangeCircle(float range, QMapbox::Coordinate center)
|
||||||
{
|
{
|
||||||
GeographicLib::Geodesic geodesic(GeographicLib::Constants::WGS84_a(),
|
GeographicLib::Geodesic geodesic(GeographicLib::Constants::WGS84_a(),
|
||||||
GeographicLib::Constants::WGS84_f());
|
GeographicLib::Constants::WGS84_f());
|
||||||
|
|
@ -59,8 +66,6 @@ static std::shared_ptr<QMapbox::Feature> GetRangeCircle(float range)
|
||||||
constexpr float angleDelta = 0.5f;
|
constexpr float angleDelta = 0.5f;
|
||||||
constexpr float angleDeltaH = angleDelta / 2.0f;
|
constexpr float angleDeltaH = angleDelta / 2.0f;
|
||||||
|
|
||||||
const QMapbox::Coordinate radar {38.6986, -90.6828};
|
|
||||||
|
|
||||||
float angle = -angleDeltaH;
|
float angle = -angleDeltaH;
|
||||||
|
|
||||||
QMapbox::Coordinates geometry;
|
QMapbox::Coordinates geometry;
|
||||||
|
|
@ -70,8 +75,8 @@ static std::shared_ptr<QMapbox::Feature> GetRangeCircle(float range)
|
||||||
double latitude;
|
double latitude;
|
||||||
double longitude;
|
double longitude;
|
||||||
|
|
||||||
geodesic.Direct(radar.first,
|
geodesic.Direct(center.first,
|
||||||
radar.second,
|
center.second,
|
||||||
angle,
|
angle,
|
||||||
range * 1000.0f,
|
range * 1000.0f,
|
||||||
latitude,
|
latitude,
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,11 @@ namespace RadarRangeLayer
|
||||||
|
|
||||||
void Add(std::shared_ptr<QMapboxGL> map,
|
void Add(std::shared_ptr<QMapboxGL> map,
|
||||||
float range,
|
float range,
|
||||||
|
QMapbox::Coordinate center,
|
||||||
const QString& before = QString());
|
const QString& before = QString());
|
||||||
void Update(std::shared_ptr<QMapboxGL> map, float range);
|
void Update(std::shared_ptr<QMapboxGL> map,
|
||||||
|
float range,
|
||||||
|
QMapbox::Coordinate center);
|
||||||
|
|
||||||
} // namespace RadarRangeLayer
|
} // namespace RadarRangeLayer
|
||||||
} // namespace map
|
} // namespace map
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue