boat
C++23 geospatial library
Loading...
Searching...
No Matches
catalogs.hpp
Go to the documentation of this file.
1// Andrew Naplavkov
2
3#ifndef BOAT_CATALOGS_HPP
4#define BOAT_CATALOGS_HPP
5
6#include <boat/detail/uri.hpp>
7#if __has_include(<gdal.h>)
9#endif
10#if __has_include(<curl/curl.h>)
11#include <boat/slippy.hpp>
12#endif
13#include <boat/sql/catalog.hpp>
14#include <boat/sql/commands.hpp>
15
16namespace boat {
17
18inline std::unique_ptr<db::catalog> make_catalog(std::string_view address)
19{
20 if (is_http_url(address))
21#if __has_include(<curl/curl.h>)
22 {
23 auto ret = std::make_unique<slippy::catalog>();
24 auto u = uri::parse(address);
25 auto os = std::ostringstream{};
26 os << u.scheme << "://" << u.host_spec << '/' << u.path;
27 for (auto sep{"?"}; !u.query.empty();) {
28 auto next = u.query.find('&');
29 auto len = (next == u.query.npos) ? u.query.size() : next;
30 auto pair = u.query.substr(0, len);
31 u.query.remove_prefix(len + (next != u.query.npos));
32 if (auto eq = pair.find('='); eq != pair.npos) {
33 auto key = pair.substr(0, eq);
34 auto val = pair.substr(eq + 1);
35 if (key == "agent") {
36 ret->agent = val;
37 continue;
38 }
39 if (key == "epsg") {
40 ret->epsg = from_chars<int>(val.data(), val.size());
41 continue;
42 }
43 if (key == "zmax") {
44 ret->zmax = from_chars<int>(val.data(), val.size());
45 continue;
46 }
47 if (key == "ssl") {
48 ret->ssl = from_chars<int>(val.data(), val.size());
49 continue;
50 }
51 }
52 os << std::exchange(sep, "&") << pair;
53 }
54 ret->url = std::move(os).str();
55 return ret;
56 }
57#else
58 throw std::runtime_error("compiled without curl");
59#endif
60 if (sql::supported_url(address)) {
61 auto ret = std::make_unique<sql::catalog>();
62 ret->command = sql::make_command(address);
63 return ret;
64 }
65#if __has_include(<gdal.h>)
66 auto ret = std::make_unique<gdal::catalog>();
67 ret->dataset = gdal::open(std::string{address}.data());
68 return ret;
69#else
70 throw std::runtime_error("compiled without gdal");
71#endif
72}
73
74} // namespace boat
75
76#endif // BOAT_CATALOGS_HPP
dataset_ptr open(char const *file)
Definition dataset.hpp:11
std::unique_ptr< db::command > make_command(std::string_view url)
Throws if the URL scheme is unknown or its client library is unavailable.
Definition commands.hpp:39
bool supported_url(std::string_view url)
Recognizes SQL URL schemes even without the corresponding client library.
Definition commands.hpp:32
Definition blob.hpp:12
std::unique_ptr< db::catalog > make_catalog(std::string_view address)
Definition catalogs.hpp:18