Skip to content

Commit

Permalink
Opencharts : adding cache files for opencharts Projections , wind and…
Browse files Browse the repository at this point in the history
… symbol
  • Loading branch information
sylvielamythepaut committed Oct 10, 2023
1 parent be6bc5b commit c6e7bc8
Showing 1 changed file with 68 additions and 28 deletions.
96 changes: 68 additions & 28 deletions src/decoders/TileDecoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ string TileDecoder::weights() {
}
if (mode_ == "opencharts" )
out << parent << "/opencharts-cache-" << grid_ << ".nc";

else
out << parent << "/weight-" << grid_ << "-" << projection() << "-z" + tostring(z_) << ".nc";
return out.str();
Expand All @@ -67,7 +66,10 @@ string TileDecoder::positions() {
if (parent.empty()) {
parent = buildSharePath("tiles");
}
out << parent << "/wind-" << grid_ << "-" << projection() << "-z" + tostring(z_) << ".nc";
if (mode_ == "opencharts" )
out << parent << "/opencharts-wind-" << grid_ << ".nc";
else
out << parent << "/wind-" << grid_ << "-" << projection() << "-z" + tostring(z_) << ".nc";

return out.str();
}
Expand All @@ -78,7 +80,12 @@ string TileDecoder::positions_symbols() {
if (parent.empty()) {
parent = buildSharePath("tiles");
}
out << parent << "/symbol-" << grid_ << "-" << projection() << "-z" + tostring(z_) << ".nc";
if (mode_ == "opencharts" ) {
out << parent << "/opencharts-symbol-" << grid_ << ".nc";
}

else
out << parent << "/symbol-" << grid_ << "-" << projection() << "-z" + tostring(z_) << ".nc";
file_ = ifstream(out.str());
if (file_.good()) {
file_.close();
Expand Down Expand Up @@ -110,6 +117,20 @@ bool TileDecoder::ok() {
grid_ = string(val);

string path = weights();
if (mode_ == "opencharts" ) {
try {
Netcdf netcdf(path, "index");
map<string, string> first, last;
static vector<double> latitudes;
netcdf.get(projection_ + "_lat", latitudes, first, last);
return true;
}
catch(...) {
return false;
}
}


file_ = ifstream(path);
if (!file_.good()) {
file_.close();
Expand Down Expand Up @@ -158,17 +179,29 @@ void TileDecoder::customisedPoints(const Transformation& transformation, const s
#ifdef HAVE_NETCDF
Netcdf netcdf(path, "index");

map<string, string> first, last;
first["x"] = tostring(x_);
first["y"] = tostring(y_);
last["x"] = tostring(x_);
last["y"] = tostring(y_);
vector<double> bbox;
vector<double> latitudes;
vector<double> longitudes;
vector<double> values;
vector<int> index;

map<string, string> first, last;

if ( mode_ == "opencharts") {

// netcdf.get(projection_ + "_lat", latitudes, first, last);
// netcdf.get(projection_ + "_lon", longitudes, first, last);
netcdf.get(projection_ + "_index", values, first, last);

}
else {
first["x"] = tostring(x_);
first["y"] = tostring(y_);
last["x"] = tostring(x_);
last["y"] = tostring(y_);
netcdf.get("index", values, first, last);
}


int error;

FILE* in = fopen(file_name_.c_str(), "rb");
Expand All @@ -193,9 +226,6 @@ void TileDecoder::customisedPoints(const Transformation& transformation, const s
return;
}

int nbpoints = netcdf.getDimension("points");
// netcdf.get("bounding-box", bbox, first, last);
netcdf.get("index", values, first, last);

for (auto b = values.begin(); b != values.end(); ++b) {
double lat = *b;
Expand Down Expand Up @@ -249,21 +279,36 @@ void TileDecoder::customisedPoints(const Transformation& transformation, const s
PointsHandler& TileDecoder::points(const Transformation& t, bool) {
string path = positions_symbols();
Timer timer("Tile", path);


#ifdef HAVE_NETCDF
Netcdf netcdf(path, "index");

map<string, string> first, last;
first["x"] = tostring(x_);
first["y"] = tostring(y_);
last["x"] = tostring(x_);
last["y"] = tostring(y_);
// vector<double> bbox;
static vector<double> latitudes;
static vector<double> longitudes;
static vector<double> values;
vector<double> latitudes;
vector<double> longitudes;
vector<double> values;
vector<int> index;

map<string, string> first, last;

if ( mode_ == "opencharts") {

// netcdf.get(projection_ + "_lat", latitudes, first, last);
// netcdf.get(projection_ + "_lon", longitudes, first, last);
netcdf.get(projection_ + "_index", values, first, last);



}
else {
first["x"] = tostring(x_);
first["y"] = tostring(y_);
last["x"] = tostring(x_);
last["y"] = tostring(y_);
netcdf.get("index", values, first, last);
}


int error;

FILE* in = fopen(file_name_.c_str(), "rb");
Expand All @@ -285,12 +330,8 @@ PointsHandler& TileDecoder::points(const Transformation& t, bool) {
return *(pointsHandlers_.back());
}


if (latitudes.size() == 0) {
int nbpoints = netcdf.getDimension("points");
// netcdf.get("bounding-box", bbox, first, last);
netcdf.get("index", values, first, last);


for (auto b = values.begin(); b != values.end(); ++b) {
double lat = *b;
Expand All @@ -302,11 +343,10 @@ PointsHandler& TileDecoder::points(const Transformation& t, bool) {
if (i != 0) {
if (lon > 180)
lon -= 360;
// transformation.fast_reproject(lon, lat);

latitudes.push_back(lat);
longitudes.push_back(lon);
index.push_back(i);

}
}
}
Expand Down

0 comments on commit c6e7bc8

Please sign in to comment.