//*************************************************************************************************
//! Given a projection instance, this method determines the corresponding EPSG code. Obviously
//! this is only needed if the projection does not have its PCS code assigned (it is NULL). This
//! happens when the projection was constructed with full parameters instead of the EPSG code.
//! Returns integer EPSG code if match was found or 0 if not found.
//*************************************************************************************************
ossim_uint32 
ossimEpsgProjectionDatabase::findProjectionCode(const ossimMapProjection& lost_proj) const
{
   ossimString lost_type (lost_proj.getClassName());

   // Shortcut for EPSG:4326 (WGS-85 geographic rectangular -- very common):
   if ((lost_type == "ossimEquDistCylProjection") && (lost_proj.getDatum()->epsgCode() == 6326))
      return 4326;

   ossim_uint32 found_code = 0;
   if (lost_type == "ossimUtmProjection")
   {
      found_code = getCodeFromUtmProj(dynamic_cast<const ossimUtmProjection*>(&lost_proj));
      if (found_code)
         return found_code;
   }

   if (m_projDatabase.empty())
      initialize();
   ossimString lookup;
   std::multimap<ossim_uint32, ossimRefPtr<ProjDbRecord> >::iterator db_iter =
      m_projDatabase.begin();
   while ((db_iter != m_projDatabase.end()) && (found_code == 0))
   {
      ossimRefPtr<ProjDbRecord> db_record = db_iter->second;
      if ( db_record.valid() )
      {
         // Has a projection already been created for this db iter?
         if (!db_record->proj.valid())
         {
            // No projection has been created yet for this DB entry. 
            // NOTE: THIS IS VERY SLOW BECAUSE WE ARE INSTANTIATING EVERY PROJECTION IN THE DB!!!
            db_record->proj = dynamic_cast<ossimMapProjection*>(findProjection(db_record->code));
         }
         if (db_record->proj.valid() && (*(db_record->proj.get()) == lost_proj))
         {
            found_code = db_record->code;
            
            // Hack to remap projection code 4087 to 4326 (which is not really a projection 
            // code but other packages like to see 4326 for geographic projections.
            // Hacked under protest (OLK, 08/2010)
            if (found_code == 4087)
               found_code = 4326;
         }
      }
      ++db_iter;
   }
   return found_code;
}
Пример #2
0
//*************************************************************************************************
//! Given a projection instance, this method determines the corresponding EPSG code. Obviously
//! this is only needed if the projection does not have its PCS code assigned (it is NULL). This
//! happens when the projection was constructed with full parameters instead of the EPSG code.
//! Returns integer EPSG code if match was found or 0 if not found.
//*************************************************************************************************
ossim_uint32 
ossimEpsgProjectionDatabase::findProjectionCode(const ossimMapProjection& lost_proj) const
{
   ossimString lost_type (lost_proj.getClassName());
   ossimString lookup;
   ossimRefPtr<ossimMapProjection> found_proj = 0;
   ossimMapProjectionFactory* factory = ossimMapProjectionFactory::instance();
   ossim_uint32 found_code = 0;

   std::vector<ProjRecord>::const_iterator db_iter = m_projDatabase.begin();
   while ((db_iter != m_projDatabase.end()) && (found_code == 0))
   {
      // To avoid having to instantiate all projections in the database, let's peek in the record's
      // KWL for the projection type and only instantiate those that match:
      lookup = db_iter->kwl.find(ossimKeywordNames::TYPE_KW);
      if (lost_type == lookup)
      {
         // We have a match, instantiate the projection from the associated KWL in the DB. Trick
         // the registry into using appropriate factory by setting PCS code temporarily to 0 to
         // avoid infinite recursion:
         ossimKeywordlist kwl (db_iter->kwl); // make copy since this is a const method
         kwl.remove(ossimKeywordNames::PCS_CODE_KW);
         found_proj = PTR_CAST(ossimMapProjection, factory->createProjection(kwl));

         // Test for same-ness between target and found, and return if matching:
         if (found_proj.valid() && (*found_proj == lost_proj))
         {
            found_code = db_iter->code;

            // Hack to remap projection code 4087 to 4326 (which is not really a projection 
            // code but other packages like to see 4326 for geographic projections.
            // Hacked under protest (OLK, 08/2010)
            if (found_code == 4087)
               found_code = 4326;
         }
      }
      db_iter++;
   }
   return found_code;
}