2017-05-11 06:13:52 -04:00
|
|
|
#ifndef OSRM_TIMEZONES_HPP
|
|
|
|
#define OSRM_TIMEZONES_HPP
|
|
|
|
|
|
|
|
#include "util/log.hpp"
|
|
|
|
|
|
|
|
#include <boost/geometry.hpp>
|
|
|
|
#include <boost/geometry/index/rtree.hpp>
|
|
|
|
|
2017-05-25 11:56:42 -04:00
|
|
|
#include <rapidjson/document.h>
|
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
#include <chrono>
|
2024-06-20 15:44:28 -04:00
|
|
|
#include <filesystem>
|
2024-05-22 08:58:07 -04:00
|
|
|
#include <optional>
|
2017-05-11 06:13:52 -04:00
|
|
|
|
2022-12-11 04:10:26 -05:00
|
|
|
namespace osrm::updater
|
2017-05-11 06:13:52 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
// Time zone shape polygons loaded in R-tree
|
|
|
|
// local_time_t is a pair of a time zone shape polygon and the corresponding local time
|
|
|
|
// rtree_t is a lookup R-tree that maps a geographic point to an index in a local_time_t vector
|
|
|
|
using point_t = boost::geometry::model::
|
|
|
|
point<double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>>;
|
|
|
|
using polygon_t = boost::geometry::model::polygon<point_t>;
|
|
|
|
using box_t = boost::geometry::model::box<point_t>;
|
|
|
|
using rtree_t =
|
|
|
|
boost::geometry::index::rtree<std::pair<box_t, size_t>, boost::geometry::index::rstar<8>>;
|
|
|
|
using local_time_t = std::pair<polygon_t, struct tm>;
|
|
|
|
|
|
|
|
class Timezoner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Timezoner() = default;
|
|
|
|
|
2017-05-29 17:07:03 -04:00
|
|
|
Timezoner(const char geojson[], std::time_t utc_time_now);
|
2024-06-20 15:44:28 -04:00
|
|
|
Timezoner(const std::filesystem::path &tz_shapes_filename, std::time_t utc_time_now);
|
2017-05-11 06:13:52 -04:00
|
|
|
|
2024-05-22 08:58:07 -04:00
|
|
|
std::optional<struct tm> operator()(const point_t &point) const;
|
2017-06-01 12:41:25 -04:00
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
private:
|
2017-05-29 17:07:03 -04:00
|
|
|
void LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t utc_time);
|
2017-05-11 06:13:52 -04:00
|
|
|
|
|
|
|
rtree_t rtree;
|
|
|
|
std::vector<local_time_t> local_times;
|
|
|
|
};
|
2022-12-20 12:00:11 -05:00
|
|
|
} // namespace osrm::updater
|
2017-05-11 06:13:52 -04:00
|
|
|
|
|
|
|
#endif
|