| 56 | } |
| 57 | |
| 58 | void SrtmTile::Init(std::string const & dir, ms::LatLon const & coord) |
| 59 | { |
| 60 | Invalidate(); |
| 61 | |
| 62 | std::string const base = GetBase(coord); |
| 63 | std::string const cont = GetSrtmContFileName(dir, base); |
| 64 | std::string file = base + ".hgt"; |
| 65 | |
| 66 | // Original files are stored in zip archives. Alternatively, they can be loaded |
| 67 | // from uncompressed files like "N34E012.hgt". |
| 68 | static bool const loadFromZip = static_cast<bool>(std::ifstream(cont)); |
| 69 | if (loadFromZip) |
| 70 | { |
| 71 | UnzipMemDelegate delegate(m_data); |
| 72 | try |
| 73 | { |
| 74 | ZipFileReader::UnzipFile(cont, file, delegate); |
| 75 | } |
| 76 | catch (ZipFileReader::LocateZipException const &) |
| 77 | { |
| 78 | // Sometimes packed file has different name. See N39E051 measure. |
| 79 | file = base + ".SRTMGL1.hgt"; |
| 80 | |
| 81 | ZipFileReader::UnzipFile(cont, file, delegate); |
| 82 | } |
| 83 | |
| 84 | if (!delegate.m_completed) |
| 85 | { |
| 86 | LOG(LWARNING, ("Can't decompress SRTM file:", cont)); |
| 87 | Invalidate(); |
| 88 | return; |
| 89 | } |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | m_data = base::ReadFile(base::JoinPath(dir, file)); |
| 94 | } |
| 95 | |
| 96 | if (m_data.size() != kSrtmTileSize) |
| 97 | { |
| 98 | LOG(LWARNING, ("Bad decompressed SRTM file size:", cont, m_data.size())); |
| 99 | Invalidate(); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | m_valid = true; |
| 104 | } |
| 105 | |
| 106 | // static |
| 107 | ms::LatLon SrtmTile::GetCoordInSeconds(ms::LatLon const & coord) |
no test coverage detected