diff --git a/src/decoders/TileDecoder.cc b/src/decoders/TileDecoder.cc index 2d8d1e78..4731b58c 100644 --- a/src/decoders/TileDecoder.cc +++ b/src/decoders/TileDecoder.cc @@ -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(); @@ -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(); } @@ -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(); @@ -110,6 +117,20 @@ bool TileDecoder::ok() { grid_ = string(val); string path = weights(); + if (mode_ == "opencharts" ) { + try { + Netcdf netcdf(path, "index"); + map first, last; + static vector latitudes; + netcdf.get(projection_ + "_lat", latitudes, first, last); + return true; + } + catch(...) { + return false; + } + } + + file_ = ifstream(path); if (!file_.good()) { file_.close(); @@ -158,17 +179,29 @@ void TileDecoder::customisedPoints(const Transformation& transformation, const s #ifdef HAVE_NETCDF Netcdf netcdf(path, "index"); - map first, last; - first["x"] = tostring(x_); - first["y"] = tostring(y_); - last["x"] = tostring(x_); - last["y"] = tostring(y_); - vector bbox; vector latitudes; vector longitudes; vector values; vector index; + map 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"); @@ -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; @@ -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 first, last; - first["x"] = tostring(x_); - first["y"] = tostring(y_); - last["x"] = tostring(x_); - last["y"] = tostring(y_); - // vector bbox; - static vector latitudes; - static vector longitudes; - static vector values; + vector latitudes; + vector longitudes; + vector values; vector index; + map 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"); @@ -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; @@ -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); + } } }