Beispiel #1
0
ossimRefPtr<ossimImageGeometry> ossimPngReader::getImageGeometry()
{
   if ( !theGeometry )
   {
      //---
      // Check factory for external geom:
      //---
      theGeometry = getExternalImageGeometry();

      if ( !theGeometry )
      {
         // Fist time through:
         theGeometry = new ossimImageGeometry();

         //---
         // This code does not call ossimImageGeometryRegistry::extendGeometry
         // by design to avoid wasted factory calls.
         //---
      }

      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
   }
   return theGeometry;
}
Beispiel #2
0
ossimRefPtr<ossimImageGeometry> ossimLasReader::getImageGeometry()
{
   if ( !theGeometry )
   {
      // Check for external geom:
      theGeometry = getExternalImageGeometry();
      
      if ( !theGeometry )
      {
         theGeometry = new ossimImageGeometry();
         if ( m_proj.valid() )
         {
            theGeometry->setProjection( m_proj.get() );
         }
         else
         {
            //---
            // WARNING:
            // Must create/set theGeometry at this point or the next call to 
            // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
            // as it does a recursive call back to ossimImageHandler::getImageGeometry().
            //---         

            // Try factories for projection.
            ossimImageGeometryRegistry::instance()->extendGeometry(this);
         }
      }
      
      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
   }
   
   return theGeometry;
}
//************************************************************************************************
//! Returns the image geometry object associated with this tile source or NULL if non defined.
//! The geometry contains full-to-local image transform as well as projection (image-to-world)
//************************************************************************************************
rspfRefPtr<rspfImageGeometry> rspfEnviTileSource::getImageGeometry()
{
   if ( !theGeometry )
   {
      // Check for external geom:
      theGeometry = getExternalImageGeometry();
      
      if ( !theGeometry )
      {
         // Check the internal geometry first to avoid a factory call.
         theGeometry = getInternalImageGeometry();

         // At this point it is assured theGeometry is set.

         //---
         // WARNING:
         // Must create/set theGeometry at this point or the next call to
         // rspfImageGeometryRegistry::extendGeometry will put us in an infinite loop
         // as it does a recursive call back to rspfImageHandler::getImageGeometry().
         //---         

         // Check for set projection.
         if ( theGeometry.valid()&&!theGeometry->getProjection() )
         {
            // Try factories for projection.
            rspfImageGeometryRegistry::instance()->extendGeometry(this);
         }
      }
      
      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
   }
   
   return theGeometry;
}
ossimRefPtr<ossimImageGeometry> ossimMrSidReader::getImageGeometry()
{
   if ( !theGeometry )
   {
      //---
      // Check for external geom:
      //---
      theGeometry = getExternalImageGeometry();
      
      if ( !theGeometry )
      {
         //---
         // Check the internal geometry first to avoid a factory call.
         //---
         theGeometry = getInternalImageGeometry();

         // At this point it is assured theGeometry is set.

         // Check for set projection.
         if ( !theGeometry->getProjection() )
         {
            // Try factories for projection.
            ossimImageGeometryRegistry::instance()->extendGeometry(this);
         }
      }

      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
   }

   return theGeometry;
}
ossimRefPtr<ossimImageGeometry> ossimNdfTileSource::getImageGeometry()
{
   if ( !theGeometry )
   {
      // Check for external geom:
      theGeometry = getExternalImageGeometry();
      
      if ( !theGeometry )
      {
         theGeometry = new ossimImageGeometry();
         
         // Validate Header to ensure we support this data type
         ossimNdfHeader lnh(theHeaderFile);
         if(lnh.getErrorStatus() == ossimErrorCodes::OSSIM_OK)
         {
            // Get the projection info.
            ossimKeywordlist kwl;
            kwl.add(lnh.getGeom());
            
            // Create the projection.
            ossimRefPtr<ossimProjection> proj = ossimProjectionFactoryRegistry::instance()->
               createProjection(kwl);
            
            if ( proj.valid() )
            {
               // Assign projection to our ossimImageGeometry object.
               theGeometry->setProjection( proj.get() );
            }
         }
         
         // At this point it is assured theGeometry is set.

         //---
         // WARNING:
         // Must create/set theGeometry at this point or the next call to
         // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
         // as it does a recursive call back to ossimImageHandler::getImageGeometry().
         //---         
         
         // Check for set projection.
         if ( !theGeometry->getProjection() )
         {
            // Try factories for projection.
            ossimImageGeometryRegistry::instance()->extendGeometry(this);
         }
      }
      
      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
   }
   
   return theGeometry;
}
ossimRefPtr<ossimImageGeometry> ossimPointCloudImageHandler::getImageGeometry()
{
   if (!isOpen())
      return 0;

   if (theGeometry.valid())
      return theGeometry;

   // Check for external geom (i.e., a *.geom file)
   theGeometry = getExternalImageGeometry();
   if (theGeometry.valid())
      return theGeometry;

   theGeometry = new ossimImageGeometry();
   ossimString epsgCode ("EPSG:4326");
   ossimMapProjection* proj = dynamic_cast<ossimMapProjection*>(
         ossimEpsgProjectionFactory::instance()->createProjection(epsgCode));
   if (!proj)
      return 0;
   theGeometry->setProjection(proj);

   // Need to establish image bounds and optimal GSD given ground rect. Use this switch to also
   // initialize the UL tiepoint of image projection:
   ossimGrect bounds;
   m_pch->getBounds(bounds);
   proj->setOrigin(bounds.ul());
   proj->setUlTiePoints(bounds.ul());

   // The GSD depends on the point density on the ground. count all final returns and
   // assume they are evenly distributed over the bounding ground rect. Note that this can have
   // up to a sqrt(2)X error if the collection was taken in a cardinal-diagonal direction.
   // Also use this point loop to latch the ground quad vertices vertices.
   ossim_uint32 numPulses = m_pch->getNumPoints(); // count of final returns
   if (numPulses == 0)
   {
      // Not yet determined. Set GSD to NAN and expect it will be set later:
      m_gsd.makeNan();
   }
   else if (m_gsd.hasNans())
   {
      ossimDpt delta (bounds.widthMeters(), bounds.heightMeters());
      ossim_float64 gsd = sqrt(delta.x * delta.y / numPulses) * m_gsdFactor;
      setGSD(gsd); // also recomputes the image size
   }

   return theGeometry;
}
ossimRefPtr<ossimImageGeometry>  ossimLandsatTileSource::getImageGeometry()
{
   if ( !theGeometry )
   {
      // Check for external geom:
      theGeometry = getExternalImageGeometry();
      
      if ( !theGeometry )
      {
         theGeometry = new ossimImageGeometry();

         if ( theFfHdr.valid() )
         {
            // Make a model
            ossimLandSatModel* model = new ossimLandSatModel (*theFfHdr);
            if (model->getErrorStatus() == ossimErrorCodes::OSSIM_OK)
            {
               //initialize the image geometry object with the model
               theGeometry->setProjection(model);
            }
         }

         //---
         // WARNING:
         // Must create/set the geometry at this point or the next call to
         // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
         // as it does a recursive call back to ossimImageHandler::getImageGeometry().
         //---         
         
         // Check for set projection.
         if ( !theGeometry->getProjection() )
         {
            // Try factories for projection.
            ossimImageGeometryRegistry::instance()->extendGeometry(this);
         }
      }

      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
   }
   
   return theGeometry;
}
Beispiel #8
0
ossimRefPtr<ossimImageGeometry> ossimH5Reader::getImageGeometry()
{
   if ( !theGeometry )
   {
      //---
      // Check for external geom:
      //---
      theGeometry = getExternalImageGeometry();
      
      if ( !theGeometry )
      {
         //---
         // WARNING:
         // Must create/set the geometry at this point or the next call to
         // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
         // as it does a recursive call back to ossimImageHandler::getImageGeometry().
         //---

         // Check the internal geometry first to avoid a factory call.
         m_mutex.lock();
         theGeometry = getInternalImageGeometry();
         m_mutex.unlock();

         // At this point it is assured theGeometry is set.

         // Check for set projection.
         if ( !theGeometry->getProjection() )
         {
            // Try factories for projection.
            ossimImageGeometryRegistry::instance()->extendGeometry(this);
         }
      }

      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
   }

   return theGeometry;
}
Beispiel #9
0
//*******************************************************************
// Public method:
//*******************************************************************
ossimRefPtr<ossimImageGeometry> ossimAdrgTileSource::getImageGeometry()
{
   if ( !theGeometry )
   {
      // Check for external geom:
      theGeometry = getExternalImageGeometry();
      
      if ( !theGeometry )
      {
         // origin of latitude
         ossim_float64 originLatitude = (m_AdrgHeader->maxLatitude() +
                                         m_AdrgHeader->minLatitude()) / 2.0;
         
         // central meridian.
         ossim_float64 centralMeridian = (m_AdrgHeader->maxLongitude() +
                                          m_AdrgHeader->minLongitude()) / 2.0;
         
         //---
         // Compute the pixel size in latitude and longitude direction.  This will
         // be full image extents divided by full image lines and samples.
         //---
         
         // Samples in full image (used to compute degPerPixelX).
         ossim_float64 samples = m_AdrgHeader->samples();
         
         // Lines in full image (used to compute degPerPixelX).
         ossim_float64 lines = m_AdrgHeader->lines();
         
         // Degrees in latitude direction of the full image.
         ossim_float64 degrees_in_lat_dir = m_AdrgHeader->maxLatitude() -
            m_AdrgHeader->minLatitude();
         
         // Degrees in longitude direction of the full image.
         ossim_float64 degrees_in_lon_dir = m_AdrgHeader->maxLongitude() -
            m_AdrgHeader->minLongitude();
         
         ossim_float64 degPerPixelY = degrees_in_lat_dir / lines;
         ossim_float64 degPerPixelX = degrees_in_lon_dir / samples;
         
         //---
         // The tie is determined with the following assumptions that need to be
         // verified:
         // 1) Rows and columns start at 1.
         // 2) The min / max latitudes longitudes go to the edge of the pixel.
         // 3) Latitude decreases by degPerPixelY with each line.
         // 4) Longitude increases by degPerPixelX with each sample.
         //---
         ossim_float64 ul_lat = (m_AdrgHeader->maxLatitude() - 
                                 ( (m_AdrgHeader->startRow() - 1) *
                                   degPerPixelY ) - ( degPerPixelY * 0.5 ) );
         ossim_float64 ul_lon = (m_AdrgHeader->minLongitude() +
                                 ( (m_AdrgHeader->startCol() -1) *
                                   degPerPixelX ) +  ( degPerPixelX * 0.5 ) );
         
         // projection type
         ossimKeywordlist kwl;
         const char* prefix = 0;
         kwl.add(prefix,
                 ossimKeywordNames::TYPE_KW,
                 "ossimEquDistCylProjection",
                 true);
         
         // datum.
         kwl.add(prefix,
                 ossimKeywordNames::DATUM_KW,
                 "WGE",
                 true);
         
         // origin latitude
         kwl.add(prefix,
                 ossimKeywordNames::ORIGIN_LATITUDE_KW,
                 originLatitude,
                 true);

         // central meridin
         kwl.add(prefix,
                 ossimKeywordNames::CENTRAL_MERIDIAN_KW,
                 centralMeridian,
                 true);

         // Save the tie point.
         kwl.add(prefix,
                 ossimKeywordNames::TIE_POINT_XY_KW,
                 ossimDpt(ul_lon, ul_lat).toString().c_str(),
                 true);
         kwl.add(prefix,
                 ossimKeywordNames::TIE_POINT_UNITS_KW,
                 ossimUnitTypeLut::instance()->getEntryString(OSSIM_DEGREES),
                 true);

         // Save the scale.
         kwl.add(prefix,
                 ossimKeywordNames::TIE_POINT_LAT_KW,
                 ul_lat,
                 true);
   
         kwl.add(prefix,
                 ossimKeywordNames::TIE_POINT_LON_KW,
                 ul_lon,
                 true);

         // Save the scale.
         kwl.add(prefix,
                 ossimKeywordNames::PIXEL_SCALE_XY_KW,
                 ossimDpt(degPerPixelX, degPerPixelY).toString().c_str(),
                 true);
         kwl.add(prefix,
                 ossimKeywordNames::PIXEL_SCALE_UNITS_KW,
                 ossimUnitTypeLut::instance()->getEntryString(OSSIM_DEGREES),
                 true);  

         // lines
         kwl.add(prefix,
                 ossimKeywordNames::NUMBER_LINES_KW,
                 getNumberOfLines());

         // samples
         kwl.add(prefix,
                 ossimKeywordNames::NUMBER_SAMPLES_KW,
                 getNumberOfSamples());

         // res sets
         kwl.add(prefix,
                 ossimKeywordNames::NUMBER_REDUCED_RES_SETS_KW,
                 getNumberOfDecimationLevels());

         // bands
         kwl.add(prefix,
                 ossimKeywordNames::NUMBER_INPUT_BANDS_KW,
                 getNumberOfInputBands());

         // bands
         kwl.add(prefix,
                 ossimKeywordNames::NUMBER_OUTPUT_BANDS_KW,
                 getNumberOfOutputBands());
   
         if (traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG)
               << "\nminLon:             " << m_AdrgHeader->minLon()
               << "\nminLond:            " << m_AdrgHeader->minLongitude() 
               << "\nminLat:             " << m_AdrgHeader->minLat()
               << "\nminLatd:            " << m_AdrgHeader->minLatitude()
               << "\nmaxLon:             " << m_AdrgHeader->maxLon()
               << "\nmaxLond:            " << m_AdrgHeader->maxLongitude()
               << "\nmaxLat:             " << m_AdrgHeader->maxLat()
               << "\nmaxLatd:            " << m_AdrgHeader->maxLatitude()
               << "\nstartRow:           " << m_AdrgHeader->startRow()
               << "\nstartCol:           " << m_AdrgHeader->startCol()
               << "\nstopRow:            " << m_AdrgHeader->stopRow()
               << "\nstopCol:            " << m_AdrgHeader->stopCol()
               << "\nfull image lines:   " << lines
               << "\nfull image samples: " << samples
               << "\nkwl:\n"               << kwl
               << std::endl;
         }

         ossimProjection* new_proj = ossimProjectionFactoryRegistry::instance()->createProjection(kwl);
         theGeometry = new ossimImageGeometry;
         theGeometry->setProjection(new_proj);  // assumes management of projection instance
         
      } // matches (after getExternalImageGeometry()):  if ( !theGeometry ) 
      
      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
      
   } // matches: if ( !theGeometry )

   return theGeometry;
}
//*************************************************************************************************
// I know what I am. I am a Quickbird TIFF image. I may be standalone or tiled with row-column
// designation in the file name. My projection information is available (possibly) in an 
// accompanying RPC file and/or internal TIF tag, and my transform info (sub-image offset) is 
// available in a TILE info file (*.til) or internal TIF tag. Therefore, I (and not some outside
// factory) am best qualified for establishing my image geometry.
//*************************************************************************************************
ossimRefPtr<ossimImageGeometry> ossimQuickbirdTiffTileSource::getImageGeometry()
{
   if ( !theGeometry )
   {
      //---
      // Check factory for external geom:
      //---
      theGeometry = getExternalImageGeometry();
      
      if ( !theGeometry )
      {
         theGeometry = new ossimImageGeometry();
         
         // Fetch the tile info for this particular image:
         if ( m_tileInfoFilename.size() )
         {
            ossimQuickbirdTile tileFile;
            if ( tileFile.open(m_tileInfoFilename) ) 
            {
               ossimQuickbirdTileInfo info;
               bool infoStatus = tileFile.getInfo(info, theImageFile.file().upcase());
               if ( !infoStatus )
               {
                  infoStatus = tileFile.getInfo(info, theImageFile.file().downcase());
               }

               if ( infoStatus )
               {
                  // Establish sub-image offset (shift) for this tile:
                  ossimDpt shift(0,0);
                  if ((info.theUlXOffset != OSSIM_INT_NAN) && (info.theUlYOffset != OSSIM_INT_NAN))
                     shift = ossimIpt(info.theUlXOffset, info.theUlYOffset);
                  
                  if(traceDebug())
                  {
                     ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimQuickbirdTiffTileSource::open() DEBUG:"
                        << "\nSub image offset  = " << shift << std::endl;
                  }

                  // Create the transform and set it in the geometry object:
                  ossimRefPtr<ossim2dTo2dTransform> transform =
                     new ossim2dTo2dShiftTransform(shift);

                  theGeometry->setTransform(transform.get());
   
                  // Next is the projection part of the image geometry. This should be available
                  // as an external RPC file or internal RPC's in the tiff file. Otherwise use
                  // the map projection specified in the 
                  // tiff file:
                  theGeometry->setProjection(0);
                  
                  ossimRefPtr<ossimQuickbirdRpcModel> model = new ossimQuickbirdRpcModel;
                  if (model->parseFile(theImageFile))
                  {
                     theGeometry->setProjection(model.get());
                  }
                  else
                  {
                     // Last resort to a projection factory:
                     ossimRefPtr<ossimProjection> proj = 
                        ossimProjectionFactoryRegistry::instance()->createProjection(this);
                     if (proj.valid()) theGeometry->setProjection(proj.get());
                  }
               }

               // Set image things the geometry object should know about.
               initImageParameters( theGeometry.get() );
            }
         }
      }
   }

   return theGeometry;
}
ossimRefPtr<ossimImageGeometry> ossimGeneralRasterTileSource::getImageGeometry()
{
   if ( !theGeometry.valid() )
   {
      // Check for external geom:
      theGeometry = getExternalImageGeometry();

      if ( !theGeometry.valid() )
      {
         theGeometry = new ossimImageGeometry();
         
         ossimString ext = theImageFile.ext();
         ossimFilename hdrFile = theImageFile;
         ossimFilename xmlFile = theImageFile;
         hdrFile = hdrFile.setExtension("hdr");
         xmlFile = xmlFile.setExtension("xml");
         if (hdrFile.exists())
         {
            ossimKeywordlist geoKwl;
            ossimKeywordlist kwl(hdrFile, ' ');
            kwl.downcaseKeywords();
            
            ossim_uint32 lines = 0;
            ossim_uint32 samples = 0;
            ossim_float32 ll_lon = 0.0;
            ossim_float32 ll_lat = 0.0;
            ossim_float32 xCellSize = 1.0;
            ossim_float32 yCellSize = 1.0;
            
            const char* lookup = kwl.find("ncols");
            if (lookup)
            {
               samples = ossimString(lookup).toUInt32();
               geoKwl.add(ossimKeywordNames::NUMBER_SAMPLES_KW, samples);
            }
            
            lookup = kwl.find("nrows");
            if (lookup)
            {
               lines = ossimString(lookup).toUInt32();
               geoKwl.add(ossimKeywordNames::NUMBER_LINES_KW, lines);
            }
            
            lookup = kwl.find("cellsize");
            if (lookup)
            {
               xCellSize = ossimString(lookup).toFloat32();
               yCellSize = xCellSize;
               geoKwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LAT, yCellSize);
               geoKwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LON, xCellSize);
            }
            
            lookup = kwl.find("xdim");
            if (lookup)
            {
               xCellSize = ossimString(lookup).toFloat32();
               geoKwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LON, xCellSize);
            }
            
            lookup = kwl.find("ydim");
            if (lookup)
            {
               yCellSize = ossimString(lookup).toFloat32();
               geoKwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LAT, yCellSize);
            }
            
            lookup = kwl.find("xllcenter");
            if (lookup)
            {
               ossim_float32 centerX = ossimString(lookup).toFloat32();
               ll_lon = centerX + xCellSize * 0.5;
               geoKwl.add(ossimKeywordNames::TIE_POINT_LON_KW, ll_lon);
            }
            
            lookup = kwl.find("yllcenter");
            if (lookup)
            {
               ossim_float32 centerY = ossimString(lookup).toFloat32();
               ll_lat = (centerY + (lines - 1) * yCellSize) + yCellSize * 0.5;
               geoKwl.add(ossimKeywordNames::TIE_POINT_LAT_KW, ll_lat);
            }
            
            lookup = kwl.find("xllcorner");
            if (lookup)
            {
               ll_lon = ossimString(lookup).toFloat32();
               geoKwl.add(ossimKeywordNames::TIE_POINT_LON_KW, ll_lon);
            }
            
            lookup = kwl.find("yllcorner");
            if (lookup)
            {
               ossim_uint32 centerY = ossimString(lookup).toFloat32();
               ll_lat = centerY + lines * yCellSize;
               geoKwl.add(ossimKeywordNames::TIE_POINT_LAT_KW, ll_lat);
            }
            
            lookup = kwl.find("ulxmap");
            if (lookup)
            {
               ll_lon = ossimString(lookup).toFloat32();
               geoKwl.add(ossimKeywordNames::TIE_POINT_LON_KW, ll_lon);
            }
            
            lookup = kwl.find("ulymap");
            if (lookup)
            {
               ossim_uint32 centerY = ossimString(lookup).toFloat32();
               ll_lat = centerY + lines * yCellSize;
               geoKwl.add(ossimKeywordNames::TIE_POINT_LAT_KW, ll_lat);
            }
            
            kwl.add(ossimKeywordNames::ORIGIN_LATITUDE_KW, ll_lat);
            
            geoKwl.add(ossimKeywordNames::TYPE_KW, "ossimEquDistCylProjection");
            
            geoKwl.add(ossimKeywordNames::DATUM_KW, ossimDatumFactory::instance()->wgs84()->
                       code());
            
            ossimRefPtr<ossimProjection> proj = ossimMapProjectionFactory::instance()->
               createProjection(geoKwl);

            if ( proj.valid() )
            {
               theGeometry->setProjection(proj.get());
            }
         }
         else if (xmlFile.exists())
         {
            ossimFgdcXmlDoc file;
            if ( file.open(xmlFile) )
            {
               ossimRefPtr<ossimProjection> proj = file.getProjection();
               if ( !proj.valid() )
               {
                  proj = file.getGridCoordSysProjection();
               }
               if ( proj.valid() )
               {
                  theGeometry->setProjection(proj.get());
               }
            }
            
         } // xml file exist...

      } // Matches second if ( !theGeometry.valid() )

      //---
      // WARNING:
      // Must have theGeometry at this point or the next call to
      // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
      // as it does a recursive call back to ossimImageHandler::getImageGeometry().
      //---         
      
      // Check for set projection.
      if ( !theGeometry->getProjection() )
      {
         // Try factories for projection.
         ossimImageGeometryRegistry::instance()->extendGeometry(this);
      }

      // Set image things the geometry object should know about.
      initImageParameters( theGeometry.get() );
      
   } // Matches first if ( !theGeometry.valid() )

   return theGeometry;
}