Exemplo n.º 1
0
//------------------------------------------------------------------------------
// 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);
}
Exemplo n.º 2
0
// Set min elevation
bool Display::setSlotMinElevation(const Basic::Distance* const msg)
{
   bool ok = false;
   if (msg != nullptr) {
      ok = setMinElevation( Basic::Meters::convertStatic(*msg) );
   }
   return ok;
}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
// Read elevation data from SRTM file
//------------------------------------------------------------------------------
bool SrtmHgtFile::readSrtmData(std::istream& in)
{
    if (nptlat < 1 || nptlong < 1)
    {
        if (isMessageEnabled(MSG_ERROR)) {
        std::cerr << "SrtmHgtFile::readSrtmData: SRTM headers indicate an empty file." << std::endl;
        }
        return false;
    }

    // Allocate the elevation array
    columns = new short*[nptlong];
    for(unsigned int i=0; i<nptlong; i++)
    {
        columns[i] = new short[nptlat];
    }
    
    // Read the elevation array.
    for(unsigned int lat=0; lat<nptlat; lat++)
    {
        //unsigned long checksum = 0;

        // Read elevation values for record
        LCreal minElev0 = 99999;
        LCreal maxElev0 = 0;
        for(unsigned int lon=0; lon<nptlong; lon++)
        {
            unsigned char values[2];
            in.read((char*)values, sizeof(values));
            if (in.fail() || in.gcount() < sizeof(values))
            {
                if (isMessageEnabled(MSG_ERROR)) {
                std::cerr << "SrtmHgtFile::readSrtmData: error reading data value." << std::endl;
                }
                return false;
            }

            short height  = readValue(values[0], values[1]);
            columns[lon][nptlat-lat-1] = height;

            // check if this is the new min or max elevation
            if (height != voidValue)
            {
                if (height < minElev0) minElev0 = height;
                if (height > maxElev0) maxElev0 = height;
            }
        }
        setMinElevation(minElev0);
        setMaxElevation(maxElev0);
    }
    return true;
}
Exemplo n.º 4
0
//------------------------------------------------------------------------------
// 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);
   }

}
Exemplo n.º 5
0
//------------------------------------------------------------------------------
// Read elevation data from DTED file
//------------------------------------------------------------------------------
bool DtedFile::readDtedData(std::istream& in)
{
    if (nptlat < 1 || nptlong < 1)
    {
        if (isMessageEnabled(MSG_ERROR)) {
            std::cerr << "DtedFile::readDtedData: DTED headers indicate an empty file." << std::endl;
        }
        return false;
    }

    // Allocate the elevation array
    columns = new short*[nptlong];
    for(unsigned int i=0; i<nptlong; i++)
    {
        columns[i] = new short[nptlat];
    }

    // Read the elevation array.
    for(unsigned int lon=0; lon<nptlong; lon++)
    {
        unsigned long checksum = 0;

        // read record header
        dtedColumnHeader head;
        in.read(reinterpret_cast<char*>(&head), sizeof(head));
        if (in.fail() || in.gcount() < sizeof(head))
        {
            if (isMessageEnabled(MSG_ERROR)) {
            std::cerr << "DtedFile::readDtedData: error reading column header." << std::endl;
            }
            return false;
        }
        for(unsigned int i=0; i<sizeof(head); i++)
            checksum += (reinterpret_cast<unsigned char*>(&head))[i];

        if (head.recognition_sentinel[0] != DATA_RECOGNITION_SENTINEL)
        {
            if (isMessageEnabled(MSG_ERROR)) {
            std::cerr << "DtedFile::readDtedData: record contains invalid recognition sentinel." << std::endl;
            }
            return false;
        }

        // Read elevation values for record
        double minElev0 = 99999.0;
        double maxElev0 = 0.0;
        for(unsigned int lat=0; lat<nptlat; lat++)
        {
            unsigned char values[2];
            in.read(reinterpret_cast<char*>(values), sizeof(values));
            if (in.fail() || in.gcount() < sizeof(values))
            {
                if (isMessageEnabled(MSG_ERROR)) {
                    std::cerr << "DtedFile::readDtedData: error reading data value." << std::endl;
                }
                return false;
            }
            checksum += values[0] + values[1];

            short height = readValue(values[0], values[1]);
            columns[lon][lat] = height;

            // check if this is the new min or max elevation
            if (height < minElev0) minElev0 = height;
            if (height > maxElev0) maxElev0 = height;
        }
        setMinElevation(minElev0);
        setMaxElevation(maxElev0);

        // Read data record footer and verify checksum
        dtedColumnFooter foot;
        in.read(reinterpret_cast<char*>(&foot), sizeof(foot));
        if (in.fail() || in.gcount() < sizeof(foot))
        {
            if (isMessageEnabled(MSG_ERROR)) {
                std::cerr << "DtedFile::readDtedData: error reading column footer." << std::endl;
            }
            return false;
        }

        if (isVerifyChecksum()) {
           unsigned long file_cksum = readValue(foot.checksum[0], foot.checksum[1], foot.checksum[2], foot.checksum[3]);
           if (file_cksum != checksum)
           {
               if (isMessageEnabled(MSG_ERROR)) {
                   std::cerr << "DtedFile::readDtedData: bad checksum in data record." << std::endl;
               }
               return false;
           }
        }
    }
    return true;
}