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