Cogs.Core
WCSRasterSource.cpp
1#include "WCSRasterSource.h"
2
3#include "Foundation/Logging/Logger.h"
4
5namespace {
6 using namespace Cogs::Core;
7 Cogs::Logging::Log logger = Cogs::Logging::getLogger("WMSRasterSource");
8
9}
10
11Cogs::Core::TerrainProvider::WCSRasterSource::WCSRasterSource(Context* context)
12 : HTTPRasterSource(context)
13{
14}
15
16Cogs::Core::TerrainProvider::WCSRasterSource::~WCSRasterSource()
17{
18}
19
20bool Cogs::Core::TerrainProvider::WCSRasterSource::init(const WCSConfig& conf, std::unique_ptr<ICache>&& icache)
21{
22 layer = conf.layer;
23 if (layer == NoString) {
24 LOG_ERROR(logger, "No layer specified");
25 return false;
26 }
27
28 format = conf.format;
29 if (format == NoString) {
30 LOG_ERROR(logger, "No format specified");
31 return false;
32 }
33 switch (Strings::get(format).hash()) { // FIXME: case-insensitive?
34 case Cogs::hash("GeoTIFF"): // http ://www.remotesensing.org/geotiff/geotiff.html
35 case Cogs::hash("GEOTIFF"):
36 //case Cogs::hash("HDF-EOS"): //
37 //case Cogs::hash("DTED"): // http://www.nima.mil/publications/specs/printed/89020A/89020A_DTED.pdf
38 //case Cogs::hash("NITF"): // http://www.ismc.nima.mil/ntb/baseline/1999.html
39 //case Cogs::hash("GML"): // http://www.opengis.org/techno/documents/02-023r4.pdf
40 //case Cogs::hash("image/png"):
41 break;
42 default:
43 LOG_ERROR(logger, "Unrecognized format '%s'", Strings::getC(format));
44 return false;
45 }
46
47 interpolation = conf.interpolation;
48 interpolationFieldName = conf.interpolationFieldName;
49 return HTTPRasterSource::init(conf, std::move(icache));
50}
51
52void Cogs::Core::TerrainProvider::WCSRasterSource::getConfig(WCSConfig& conf) const
53{
54 HTTPRasterSource::getConfig(conf);
55 conf.layer = layer;
56 conf.format = format;
57 conf.interpolation = interpolation;
58 conf.interpolationFieldName = interpolationFieldName;
59}
60
61
62bool Cogs::Core::TerrainProvider::WCSRasterSource::createFetchTileUrl(std::string& url, TileId id)
63{
64 double divisor = std::exp2(static_cast<double>(id.level));
65 double xres = tiling.size.x / divisor;
66 double yres = tiling.size.y / divisor;
67 double west = extent.min.x + (xres * id.i);
68 double east = extent.min.x + (xres * (id.i + 1));
69 double south = extent.min.y + (yres * id.j);
70 double north = extent.min.y + (yres * (id.j + 1));
71
72 url.assign(Strings::getC(baseUrl));
73 //url.append("SERVICE=WCS&VERSION=1.0.0&REQUEST=GetCoverage");
74 url.append("&COVERAGE=");
75 url.append(Strings::getC(layer));
76 url.append("&FORMAT=");
77 url.append(Strings::getC(format));
78 url.append("&CRS=");
79 switch (coordsys.kind) {
80 case CoordSys::Kind::EPSG:
81 url.append("EPSG:");
82 break;
83 default:
84 assert(false && "Garbage in conf.coordSys.kind");
85 return false;
86 }
87 url.append(std::to_string(coordsys.id));
88 url.append("&WIDTH=");
89 url.append(std::to_string(tiling.width));
90 url.append("&HEIGHT=");
91 url.append(std::to_string(tiling.height));
92 url.append("&BBOX=");
93 url.append(std::to_string(west)); url.append(",");
94 url.append(std::to_string(south)); url.append(",");
95 url.append(std::to_string(east)); url.append(",");
96 url.append(std::to_string(north));
97 if (interpolation != NoString && interpolationFieldName != NoString) {
98 url.append("&");
99 url.append(Strings::getC(interpolationFieldName));
100 url.append("=");
101 url.append(Strings::getC(interpolation));
102 }
103 LOG_DEBUG(logger, "%s", url.c_str());
104 return true;
105}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Log implementation class.
Definition: LogManager.h:139
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62