void ossimImageElevationDatabase::getBoundingRect(ossimGrect& rect) const
{
   // The bounding rect is the North up rectangle.  So if the underlying image projection is not
   // a geographic projection and there is a rotation this will include null coverage area.
   rect.makeNan();
   std::map<ossim_uint64, ossimImageElevationFileEntry>::const_iterator i = m_entryMap.begin();
   ossimGrect subRect;
   while ( i != m_entryMap.end() )
   {
      subRect = i->second.m_rect;
      if (subRect.isLonLatNan())
      {
         // The DEM source was not yet initialized:
         ossimRefPtr<ossimImageElevationHandler> h = new ossimImageElevationHandler();
         if ( h->open( i->second.m_file ) )
            subRect = h->getBoundingGndRect();
         else
         {
            ++i;
            continue;
         }
      }
      if (rect.isLonLatNan())
         rect = subRect;
      else
         rect = rect.combine(subRect);
      ++i;
   }
}
void ossimDtedElevationImageSource::getPostSpacing(const ossimGrect& rect,
                                                   ossim_uint32 lines,
                                                   ossim_uint32 samples,
                                                   ossimDpt& result) const
{
   result.lat = (rect.ul().lat - rect.ll().lat) / (lines   - 1);
   result.lon = (rect.lr().lon - rect.ll().lon) / (samples - 1);
}
Exemplo n.º 3
0
void oms::SingleImageChain::setViewCut(const ossimGrect& grect)
{
   std::vector<ossimGpt> pointList(4);
   pointList[0] = grect.ul();
   pointList[1] = grect.ur();
   pointList[2] = grect.lr();
   pointList[3] = grect.ll();
   setViewCut(pointList);
};
void ossimTiledElevationDatabase::getBoundingRect(
   ossimRefPtr<ossimImageGeometry> geom, ossimGrect& boundingRect) const
{
   if ( geom.valid() )
   {
      std::vector<ossimGpt> corner(4);
      if ( geom->getCornerGpts(corner[0], corner[1], corner[2], corner[3]) )
      {
         ossimGpt ulGpt(corner[0]);
         ossimGpt lrGpt(corner[0]);
         for ( ossim_uint32 i = 1; i < 4; ++i )
         {
            if ( corner[i].lon < ulGpt.lon ) ulGpt.lon = corner[i].lon;
            if ( corner[i].lat > ulGpt.lat ) ulGpt.lat = corner[i].lat;
            if ( corner[i].lon > lrGpt.lon ) lrGpt.lon = corner[i].lon;
            if ( corner[i].lat < lrGpt.lat ) lrGpt.lat = corner[i].lat;
         }
         boundingRect = ossimGrect(ulGpt, lrGpt);
      }
      else
      {
         boundingRect.makeNan();
      }
   }
}
void ossimDtedElevationImageSource::computeImageRect(
   const ossimMapProjection* view,
   const ossimGrect& grect,
   ossimIrect& irect) const
{
   if (!view)
   {
      return;
   }
   
   ossimDpt dpt;
   view->worldToLineSample(grect.ul(), dpt);
   irect.set_ul(dpt);
   view->worldToLineSample(grect.lr(), dpt);
   irect.set_lr(dpt);
}
ossim_uint32 ossimDtedElevationImageSource::computeIndex(
   const ossimImageData& id,
   const ossimGrect& idRect,
   const ossimGpt& gpt,
   const ossimDpt& postSpacing) const
{
   if ( ! idRect.pointWithin(gpt) )
   {
      return OSSIM_INT_NAN;
   }

   ossim_uint32 line = static_cast<ossim_uint32>( (idRect.ul().lat - gpt.lat)
                                                  / postSpacing.y );
   ossim_uint32 samp = static_cast<ossim_uint32>( (gpt.lon - idRect.ul().lon)
                                                  / postSpacing.x );
   return ( (line * id.getWidth()) + samp );
}
Exemplo n.º 7
0
void ossimUsgsQuad::getQuadList(vector<ossimUsgsQuad>& result,
                                const ossimGrect& rect)
{
   result.clear();
//   QUAD_SIZE_IN_DEGREES;

   ossimGpt point = rect.ul();

   while(rect.pointWithin(point))
   {
      while(rect.pointWithin(point))
      {
         result.push_back(ossimUsgsQuad(point));

         point.lond(point.lond()+QUAD_SIZE_IN_DEGREES);
      }
      point.lond(rect.ul().lond());
      point.latd(point.latd()-QUAD_SIZE_IN_DEGREES);
   }
}
Exemplo n.º 8
0
void ossimElevManager::getCellsForBounds( const ossimGrect& bbox,
                                          std::vector<std::string>& cells,
                                          ossim_uint32 maxCells)
{
   getCellsForBounds(bbox.lr().lat, bbox.ul().lon, bbox.ul().lat, bbox.lr().lon, cells, maxCells);
}
ossimRefPtr<ossimImageData> ossimDtedElevationImageSource::getBlock(
   const ossimGrect& rect,
   ossim_uint32 lines,
   ossim_uint32 samples) const
{

   ossimDpt postSpacing;
   getPostSpacing(rect, lines, samples, postSpacing);
   
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::getBlock DEBUG:"
         << "\nrect:          " << rect
         << "\nlines:         " << lines
         << "\nsamples:       " << samples
         << "\npost spacing:  " << postSpacing
         << "\ntheDirectory:  " << theDirectory
         << endl;
   }

   // Get a list of needed cells.
   vector<ossimFilename> vf;
   findCells(rect, vf);

   // Create a mosaic of them.
   ossimRefPtr<ossimImageChain> mosaic = createMosaic(vf);
   if (!mosaic)
   {
      return 0;
   }

   // Get the view.
   ossimMapProjection* view = getView(mosaic.get());
   if (!view)
   {
      mosaic = 0;
      return 0;
   }
   
   // Set the output resolution.
   view->setDecimalDegreesPerPixel(postSpacing);

   // Set the tie point to be the upper left of the requested rect.
   view->setUlTiePoints(rect.ul());

   // Convert the ground rectangle to the view's image space.
   ossimIrect tileRect;
   computeImageRect(view, rect, tileRect);

   cout << "tileRect:  " << tileRect << endl;
   
   ossimRefPtr<ossimImageData> result = mosaic->getTile(tileRect);

   mosaic = 0;
   
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::getBlock DEBUG:"
         << *result
         << "\nReturning..."
         << endl;
   }

   return result;
}
void ossimDtedElevationImageSource::snap(const ossimGrect& rect,
                                         const ossimDpt& postSpacing,
                                         ossimGrect& clipRect) const
{
   ossim_float64 d;

   // upper left latitude
   d = (rect.ul().lat - clipRect.ul().lat) / postSpacing.y;
   if (d != 0.0)
   {
      clipRect.ul().lat = floor(d) * postSpacing.y;
   }

   // upper left longitude
   d = (rect.ul().lon - clipRect.ul().lon) / postSpacing.x;
   if (d != 0.0)
   {
      clipRect.ul().lon = ceil(d) * postSpacing.x;
   }

   // upper right latitude
   d = (rect.ul().lat - clipRect.ur().lat) / postSpacing.y;
   if (d != 0.0)
   {
      clipRect.ur().lat = floor(d) * postSpacing.y;
   }

   // upper right longitude
   d = (rect.ul().lon - clipRect.ur().lon) / postSpacing.x;
   if (d != 0.0)
   {
      clipRect.ul().lon = floor(d) * postSpacing.x;
   }

   // lower right latitude
   d = (rect.ul().lat - clipRect.lr().lat) / postSpacing.y;
   if (d != 0.0)
   {
      clipRect.lr().lat = ceil(d) * postSpacing.y;
   }

   // lower right longitude
   d = (rect.ul().lon - clipRect.lr().lon) / postSpacing.x;
   if (d != 0.0)
   {
      clipRect.ul().lon = floor(d) * postSpacing.x;
   }

   // lower left latitude
   d = (rect.ul().lat - clipRect.ll().lat) / postSpacing.y;
   if (d != 0.0)
   {
      clipRect.ll().lat = ceil(d) * postSpacing.y;
   }

   // lower left longitude
   d = (rect.ul().lon - clipRect.ll().lon) / postSpacing.x;
   if (d != 0.0)
   {
      clipRect.ul().lon = ceil(d) * postSpacing.x;
   }
}
void ossimDtedElevationImageSource::resampleCellBilinear(
   const ossimGrect& rect,
   const ossimFilename& dtedFile,
   ossimImageData& id,
   const ossimDpt& postSpacing) const
{
   cout << dtedFile << endl;
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::resampleCellBilinear DEBUG:"
         << " Entered..."
         << endl;
   }

   ossimRefPtr<ossimDtedHandler> dh = new ossimDtedHandler(dtedFile);
   if (!dh)
   {
      return;
   }
   if (dh->getErrorStatus() != ossimErrorCodes::OSSIM_OK)
   {
      dh = 0;
      return;
   }

   ossim_float32* buf = id.getFloatBuf();
   if (!buf)
   {
      dh = 0;
      return;
   }
   
   // Get the clip rectangle.
   const ossimGrect clipRect = rect.clipToRect(dh->getBoundingGndRect());
   const ossimGpt STOP_GPT = clipRect.lr();
   ossimGpt gpt = clipRect.ul();

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "clipRect:  " << clipRect
         << "\nSTOP_GPT:  " << STOP_GPT
         << "\nStarting gpt:       " << gpt
         << endl;
   }

   // Walk in the latitude (line) direction.
   while (gpt.lat >= STOP_GPT.lat)
   {
      // Walk in longitude (sample) direction.
      gpt.lon = clipRect.ul().lon;
      while (gpt.lon <= STOP_GPT.lon)
      {
         ossim_int32 index = computeIndex(id, rect, gpt, postSpacing);
//         cout << "index:  " << index << endl;
         if (index != OSSIM_INT_NAN)
         {
            ossim_float32 hgt =
               static_cast<ossim_float32>(dh->getHeightAboveMSL(gpt));
//             cout << "index: " << index
//                  << "\ngpt: " << gpt
//                  << "\nhgt: " << hgt
//                  << endl;
            buf[index] = hgt;
            if (hgt == -32767.0)
            {
               cout << gpt << endl;
            }
            // static_cast<ossim_float32>(dh->getHeightAboveMSL(gpt));
         }
         else
         {
            cout << "nan index for gpt:\n" << gpt << endl;
         }
         
         gpt.lon = gpt.lon + postSpacing.x;
      }
      gpt.lat = gpt.lat - postSpacing.y;
   }
//   cout << "Ending gpt:  " << gpt << endl;

//    // Walk in the latitude direction
//    while (gpt.lat <= STOP_GPT.lat)
//    {
//       while (gpt.lon <= STOP_GPT.lon)
//       {
//          gpt.lon += postSpacing.x;
//       }
//       gpt.lat += postSpacing.y;
//    }

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::resampleCellBilinear DEBUG:"
         << " Exited..."
         << endl;
   }

   dh = 0;
}
void ossimDtedElevationImageSource::findCells(
   const ossimGrect& rect,
   vector<ossimFilename>& vf) const
{
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::findCells entered..." << endl;
   }

   // Clear the vector of filenames passed to us.
   vf.clear();

   if (!theDirectory.isDir())
   {
      return;
   }   

   //---
   // Expand out the rectangle to even degree boundaries.
   // Handle wrapping???
   //---
   
   ossimGrect expandedRect = rect.stretchToEvenBoundary(1.0, 1.0);


   ossim_int32 startLat = static_cast<ossim_int32>(expandedRect.ll().latd());
   ossim_int32 startLon = static_cast<ossim_int32>(expandedRect.ll().lond());
   ossim_int32 stopLat  =
      static_cast<ossim_int32>(expandedRect.ur().latd()-1);
   ossim_int32 stopLon  =
      static_cast<ossim_int32>(expandedRect.ur().lond()-1);

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG:"
         << "\nepandedRect:  " << expandedRect
         << "\nstartLat:  " << startLat
         << "\nstartLon:  " << startLon
         << "\nstopLat:   " << stopLat
         << "\nstopLon:   " << stopLon
         
         << endl;
   }

   
   for (ossim_int32 lon = startLon; lon <= stopLon; ++lon)
   {
      // Build up a dted file name.
      ossimString lonBase;
      if (lon < 0)
      {
         lonBase = "w";
      }
      else
      {
         lonBase = "e";
      }

      ossim_int32 tmpLon = abs(lon);
      ostringstream  s1;
      s1<< setfill('0')<<setw(3)<< tmpLon;

      lonBase += s1.str().c_str();
      lonBase += "/";

      for (ossim_int32 lat = startLat; lat <= stopLat; ++lat)
      {
         ossimFilename dtedFile = theDirectory.dirCat(lonBase);
         if (lat >= 0)
         {
            dtedFile += "n";
         }
         else
         {
            dtedFile += "s";
         }
         
         ossim_int32 tmpLat = abs(lat);
         ostringstream  s2;
         s2<< setfill('0')<<setw(2)<<tmpLat;
         dtedFile += s2.str().c_str();
         
         dtedFile.setExtension(theCellExtension);

         if (traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG)
               << "\nSearching for:  " << dtedFile
               << endl;
         }

         if (dtedFile.exists())
         {
            vf.push_back(dtedFile);
         }
      }
   }

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "Cell list:\n";
      
      vector<ossimFilename>::const_iterator i = vf.begin();
      while (i != vf.end())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << (*i) << "\n";
         ++i;
      }
      ossimNotify(ossimNotifyLevel_DEBUG) << endl;
   }

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimDtedElevationImageSource::findCells exited..." << endl;
   }
}