//------------------------------------------------------------------------------ // clear our data //------------------------------------------------------------------------------ void DataFile::clearData() { // Delete the columns of data if (columns != 0) { // Delete the columns of data for (unsigned int i = 0; i < nptlong; i++) { if (columns[i] != 0) { delete[] columns[i]; columns[i] = 0; } } // Delete the array of pointers to the columns of data delete[] columns; columns = 0; } nptlat = 0; nptlong = 0; setLatitudeSW(0); setLongitudeSW(0); setLatitudeNE(0); setLongitudeNE(0); setMinElevation(0); setMaxElevation(0); }
bool SrtmHgtFile::determineSrtmInfo(const std::string& srtmFilename, std::streamoff size) { // Extract the number of latitude and longitude lines unsigned int num_lat; unsigned int num_lon; // Extract the data intervals for latitude and longitude switch (size) { case 2884802: latSpacing = 3.0 / 3600.0; lonSpacing = 3.0 / 3600.0; num_lat = 1201; num_lon = 1201; break; case 25934402: latSpacing = 1.0 / 3600.0; lonSpacing = 1.0 / 3600.0; num_lat = 3601; num_lon = 3601; break; default: return false; } // valid SRTM file extensions std::string ext1(".hgt"); std::string ext2(".HGT"); if (srtmFilename.substr(7, 4) != ".hgt" && srtmFilename.substr(7, 4) != ".HGT") { return false; } // nXXwXXX.hgt srtm1 srtm3 int swcLatitude = std::atoi(srtmFilename.substr(1, 2).c_str()); int swcLongitude = std::atoi(srtmFilename.substr(4, 3).c_str()); char ns = (char)tolower(srtmFilename[0]); char ew = (char)tolower(srtmFilename[3]); if ((ns != 'n' && ns != 's') || (ew != 'e' && ew != 'w')) { return false; } if (ns == 's') { swcLatitude = -swcLatitude; } if (ew == 'w') { swcLongitude = -swcLongitude; } setLatitudeSW( swcLatitude ); setLongitudeSW( swcLongitude ); setLatitudeNE( swcLatitude + 1 ); setLongitudeNE( swcLongitude + 1 ); nptlat = num_lat; nptlong = num_lon; return true; }
//------------------------------------------------------------------------------ // Initializes the channel array //------------------------------------------------------------------------------ void QuadMap::findDataFiles() { // Clear out the old ones clearData(); // Find the DataFile objects { Basic::PairStream* subcomponents = getComponents(); if (subcomponents != nullptr) { unsigned int count = 0; Basic::List::Item* item = subcomponents->getFirstItem(); while (item != nullptr && count < MAX_DATA_FILES) { Basic::Pair* pair = static_cast<Basic::Pair*>( item->getValue() ); Basic::Terrain* dataFile = dynamic_cast<Basic::Terrain*>( pair->object() ); if (dataFile != nullptr && dataFile->isDataLoaded()) { dataFile->ref(); dataFiles[count] = dataFile; count++; } item = item->getNext(); } numDataFiles = count; subcomponents->unref(); subcomponents = nullptr; } } // Find the max/min elevations and the corner points if (numDataFiles > 0) { LCreal elevMin = 999999.0; LCreal elevMax = -999999.0; double lowerLat = 90.0; double lowerLon = 180.0; double upperLat = -90.0; double upperLon = -180.0; for (unsigned int i = 0; i < numDataFiles; i++) { if (dataFiles[i]->getMinElevation() < elevMin) elevMin = dataFiles[i]->getMinElevation(); if (dataFiles[i]->getMaxElevation() > elevMax) elevMax = dataFiles[i]->getMaxElevation(); if (dataFiles[i]->getLatitudeSW() < lowerLat) lowerLat = dataFiles[i]->getLatitudeSW(); if (dataFiles[i]->getLongitudeSW() < lowerLon) lowerLon = dataFiles[i]->getLongitudeSW(); if (dataFiles[i]->getLatitudeNE() > upperLat) upperLat = dataFiles[i]->getLatitudeNE(); if (dataFiles[i]->getLongitudeNE() > upperLon) upperLon = dataFiles[i]->getLongitudeNE(); } setMinElevation(elevMin); setMaxElevation(elevMax); setLatitudeSW(lowerLat); setLongitudeSW(lowerLon); setLatitudeNE(upperLat); setLongitudeNE(upperLon); } else { setMinElevation(0); setMaxElevation(0); setLatitudeSW(0); setLongitudeSW(0); setLatitudeNE(0); setLongitudeNE(0); } }
//------------------------------------------------------------------------------ // Read basic information about this cell from the file headers //------------------------------------------------------------------------------ bool DtedFile::readDtedHeaders(std::istream& in) { // Read in the User Header Label (UHL) record dtedUhlRecord uhl; in.read(reinterpret_cast<char*>(&uhl), sizeof(uhl)); if (in.fail() || in.gcount() < sizeof(uhl)) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "DtedFile::readDtedHeaders: error reading UHL record." << std::endl; } return false; } if (std::strncmp(uhl.recognition_sentinel, UHL_RECOGNITION_SENTINEL, sizeof(uhl.recognition_sentinel)) != 0) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "DtedFile::readDtedHeaders: invalid recognition sentinel in UHL record." << std::endl; } return false; } if (uhl.fixed_by_standard[0] != UHL_FIXED_BY_STANDARD_BYTE) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "DtedFile::readDtedHeaders: invalid fixed_by_standard byte in UHL record." << std::endl; } return false; } // Read in the Data Set Identification (DSI) record dtedDsiRecord dsi; in.read(reinterpret_cast<char*>(&dsi), sizeof(dsi)); if (in.fail() || in.gcount() < sizeof(dsi)) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "DtedFile::readDtedHeaders: error reading DSI record." << std::endl; } return false; } // Read in the Accuracy Description (ACC) record dtedAccRecord acc; in.read(reinterpret_cast<char*>(&acc), sizeof(acc)); if (in.fail() || in.gcount() < sizeof(acc)) { if (isMessageEnabled(MSG_ERROR)) { std::cerr << "DtedFile::readDtedHeaders: error reading ACC record." << std::endl; } return false; } // Extract the latitude and longitude of cell's SW corner. // DTED cells are always 1 degree by 1 degree, // and always start on an integer degree. int swcLatitude(0); int swcLongitude(0); std::sscanf(uhl.origin_latitude, "%3d", &swcLatitude); std::sscanf(uhl.origin_longitude, "%3d", &swcLongitude); if (uhl.origin_latitude[7] == 'S') swcLatitude = -1*swcLatitude; if (uhl.origin_longitude[7] == 'W') swcLongitude = -1*swcLongitude; setLatitudeSW( swcLatitude ); setLongitudeSW( swcLongitude ); setLatitudeNE( swcLatitude + 1 ); setLongitudeNE( swcLongitude + 1 ); // Extract the data intervals for latitude and longitude static const double TENTHS_OF_SECONDS_PER_DEGREE = 36000.0; int latIncr(0); int lonIncr(0); std::sscanf(uhl.data_interval_latitude, "%4d", &latIncr); std::sscanf(uhl.data_interval_longitude, "%4d", &lonIncr); latSpacing = latIncr / TENTHS_OF_SECONDS_PER_DEGREE; lonSpacing = lonIncr / TENTHS_OF_SECONDS_PER_DEGREE; // Extract the number of latitude and longitude lines unsigned int num_lat(0); unsigned int num_lon(0); std::sscanf(uhl.number_latitude_lines, "%4u", &num_lat); std::sscanf(uhl.number_longitude_lines, "%4u", &num_lon); nptlat = num_lat; nptlong = num_lon; return true; }