3#ifndef BOAT_GUI_FETCH_HPP
4#define BOAT_GUI_FETCH_HPP
8#include <boat/gui/detail/geometry.hpp>
9#include <boat/gui/detail/tile.hpp>
17 std::shared_ptr<caches::cache>
cache;
26using caches::detail::get_or_invoke;
28std::generator<variant> vectors(
layer_query const& q)
30 namespace bgi = boost::geometry::index;
31 auto cells = std::max<>(1,
int(std::sqrt(2 * q.
limit)));
33 return q.catalog().get_table(q.layer.schema_name, q.layer.table_name);
37 check(it != tbl.columns.end(), col);
41 auto done = bgi::rtree<geometry::cartesian::box, bgi::rstar<4>>{};
43 if (q.
stop.stop_requested())
45 if (done.qbegin(bgi::contains(box)) != done.qend())
47 auto a = box.min_corner(), b = box.max_corner();
48 auto vec = get_or_invoke(
50 std::tuple{q.cache_key, a.x(), a.y(), b.x(), b.y(), q.limit},
52 auto rs = q.catalog().select(tbl, {{col}, col, box, q.limit});
55 blob_view{wkb} >> ret.geoms.emplace_back();
56 ret.partial = ret.geoms.size() >= q.
limit;
58 ret.geoms = sample(std::move(ret.geoms), box, cells);
60 inv(std::move(ret.geoms)).value_or(
decltype(ret.geoms){});
65 if (!vec.geoms.empty())
66 co_yield std::move(vec);
70std::generator<variant> rasters(layer_query
const& q)
72 auto& footprint = q.footprint;
73 if (footprint.empty())
75 auto r = get_or_invoke(q.cache.get(), q.cache_key, [&] {
76 return q.catalog().get_raster(q.layer);
78 auto meters = std::next(footprint.begin(), footprint.size() > 1)->first;
81 auto uncached = std::vector<tile>{};
83 tiles(footprint.begin()->second, meters, r.extent, mat, crs)) {
85 q.cache ? q.cache->get(std::pair{q.cache_key, t}) : std::any{};
86 if (!any.has_value()) {
87 uncached.push_back(t);
91 std::any_cast<decltype(raster::rgba)>(std::move(any)),
92 mat * t.affine(r.extent),
95 if (uncached.empty() || q.stop.stop_requested())
97 for (
auto [t, img] : q.catalog().read(r, std::move(uncached))) {
100 q.cache->put(std::pair{q.cache_key, t}, rgba);
101 co_yield raster{std::move(rgba), mat * t.affine(r.extent), crs};
102 if (q.stop.stop_requested())
113 return q.
layer.
raster ? detail::rasters(q) : detail::vectors(q);
constexpr auto view
Columns must match the field count and order; scalars need one column.
Definition rowset.hpp:27
bool transform(T1 const &geom1, T2 &geom2, Strategy const &strategy)
Collections succeed if any element succeeds; failed elements are omitted.
Definition transform.hpp:89
auto make_boxes(geographic::grid const &footprint, srs_spec auto const &crs)
Definition raster.hpp:79
srs_variant make_srs_variant(int epsg, std::string const &proj4)
Prefers positive EPSG to PROJ.4; throws if neither is available.
Definition transform.hpp:122
auto backward(matrix const &v)
Definition transform.hpp:76
auto transformation(srs_spec auto const &a, srs_spec auto const &b)
Definition transform.hpp:48
T to(any_image_view img)
Definition gil.hpp:55
std::generator< variant > fetch(layer_query const &q)
Definition fetch.hpp:111
Definition catalog.hpp:14
std::string column_name
Definition meta.hpp:29
std::string column_name
Definition meta.hpp:21
bool raster
Definition meta.hpp:22
std::map< double, multi_point > grid
Definition vocabulary.hpp:73
db::layer layer
Definition fetch.hpp:16
geometry::geographic::grid footprint
Definition fetch.hpp:19
std::move_only_function< db::catalog &() const > catalog
Definition fetch.hpp:15
int limit
Definition fetch.hpp:20
std::shared_ptr< caches::cache > cache
Definition fetch.hpp:17
std::stop_token stop
Definition fetch.hpp:21
size_t cache_key
Unique within the cache.
Definition fetch.hpp:18
Definition variant.hpp:21
Definition variant.hpp:11