Example #1
0
ossimProjection* ossimNitfProjectionFactory::makeUtm(
   const ossimNitfImageHeader* hdr,
   const ossimString& coordinateSystem) const
{
   ossimUtmProjection* proj = 0;
   if (!hdr)
   {
      return proj;
   }

   ossimString geographicLocation = hdr->getGeographicLocation();

   std::vector<ossimDpt> utmPoints;
   ossim_uint32 zone;
   ossimDpt scale;
   parseUtmString(geographicLocation,
                  zone,
                  utmPoints);

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimNitfProjectionFactory::makeUtm DEBUG"
         << "\ngeo string: " << geographicLocation
         << std::endl;
      for (ossim_uint32 i=0; i<utmPoints.size(); ++i)
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "utmPoints[" << utmPoints[i] << std::endl;
      }
   }
   
   proj = new ossimUtmProjection;
   if(coordinateSystem == "S")
   {
      proj->setHemisphere('S');
   }
   else
   {
      proj->setHemisphere('N');
   }
   proj->setZone(zone);

   if(isSkewed(utmPoints))
   {
      std::vector<ossimGpt> gpts;

      // Try blocka points first as they are more accurate.
      if ( getBlockaPoints(hdr, gpts) == false )
      {
         ossimGpt ul = proj->inverse(utmPoints[0]);
         ossimGpt ur = proj->inverse(utmPoints[1]);
         ossimGpt lr = proj->inverse(utmPoints[2]);
         ossimGpt ll = proj->inverse(utmPoints[3]);
         gpts.push_back(ul);
         gpts.push_back(ur);
         gpts.push_back(lr);
         gpts.push_back(ll);
      }
      
      delete proj;
      proj = 0;
      return makeBilinear(hdr, gpts);
   }
   else
   {
      computeScaleInMeters(hdr, utmPoints, scale);
   }

   ossimProjection* result = 0;
   if(!scale.hasNans())
   {
      //---
      // Get the tie point.
      // 
      // Look for the the BLOCKA tag which may or may not be present.
      // This has six digit precision in decimal degrees which equates to
      // about 0.11 meters (at equator) as compared to 1.0 accuaracy of the
      // IGEOLO field.
      //---
      ossimDpt tie;
      std::vector<ossimGpt> gpts;
      if ( getBlockaPoints(hdr, gpts) )
      {
         if (traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG)
               << "ossimNitfProjectionFactory::makeUtm DEBUG:"
               << "\nTie point from blocka: " << gpts[0]
               << endl;
         }

         tie = proj->forward(gpts[0]);
         tie.x += scale.x/2.0;
         tie.y -= scale.y/2.0;
      }
      else
      {
         tie.x = utmPoints[0].x + scale.x/2.0;
         tie.y = utmPoints[0].y - scale.y/2.0;
      }
      
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "ossimNitfProjectionFactory::makeUtm DEBUG:"
            << "\nTie point: " << tie
            << "\nScale:     " << scale
            << endl;
      }
      
      proj->setUlEastingNorthing(tie);
      proj->setMetersPerPixel(scale);
      result = proj;
   }
   else
   {
      delete proj;
      proj = 0;
   }
   return result;
}
ossimProjection* ossimNitfProjectionFactory::makeUtm(
   const ossimNitfImageHeader* hdr,
   const ossimString& coordinateSystem) const
{
   ossimProjection* proj = 0;
   if (hdr)
   {
      ossimString geographicLocation = hdr->getGeographicLocation();

      if ( geographicLocation.size() )
      {
         std::vector<ossimDpt> utmPoints;
         ossim_uint32 zone;
         ossimDpt scale;
         char hemisphere = 'N';
         
         bool status = true;
         if ( coordinateSystem == "U")
         {
            // Sets zone, hemisphere and utmPoints. Returns true on success.
            status = parseMgrsString(geographicLocation, zone, hemisphere, utmPoints);
         }
         else
         {
            // Sets zone and utmPoints.  Void return...
            parseUtmString(geographicLocation, zone, utmPoints);
            if(coordinateSystem == "S")
            {
               hemisphere = 'S';
            }
         }
         
         if ( status )
         {
            if ( traceDebug() )
            {
               std::string s;
               s.push_back(hemisphere);
               ossimNotify(ossimNotifyLevel_DEBUG)
                  << "ossimNitfProjectionFactory::makeUtm DEBUG"
                  << "\ngeo string: " << geographicLocation
                  << "\nutm zone:   " << zone
                  << "\nhemisphere: " << hemisphere
                  << std::endl;
               for (ossim_uint32 i=0; i<utmPoints.size(); ++i)
               {
                  ossimNotify(ossimNotifyLevel_DEBUG)
                     << "utmPoints[" << utmPoints[i] << std::endl;
               }
            }
            
            ossimRefPtr<ossimUtmProjection> uproj = new ossimUtmProjection;
            uproj->setHemisphere(hemisphere);
            uproj->setZone(zone);
            
            if(isSkewed(utmPoints))
            {
               std::vector<ossimGpt> gpts;
               
               // Try blocka points first as they are more accurate.
               if ( getBlockaPoints(hdr, gpts) == false )
               {
                  ossimGpt ul = uproj->inverse(utmPoints[0]);
                  ossimGpt ur = uproj->inverse(utmPoints[1]);
                  ossimGpt lr = uproj->inverse(utmPoints[2]);
                  ossimGpt ll = uproj->inverse(utmPoints[3]);
                  gpts.push_back(ul);
                  gpts.push_back(ur);
                  gpts.push_back(lr);
                  gpts.push_back(ll);
               }

               //---
               // Make a bilinear either from our skewed utm points or the points from the blocka
               // tag.
               //---
               proj = makeBilinear(hdr, gpts);
               
               uproj = 0; // Done with utm projeciton
               
            }
            else
            {
               computeScaleInMeters(hdr, utmPoints, scale);
               
               //---
               // Assign our projection to the return "proj".
               // Use ossimRefPtr::release the so we don't delete proj when uproj
               // goes out of scope.
               //---
               proj = uproj.release(); 
            }
            
            if( scale.hasNans() == false )
            {
               //---
               // Get the tie point.
               // 
               // Look for the the BLOCKA tag which may or may not be present.
               // This has six digit precision in decimal degrees which equates to
               // about 0.11 meters (at equator) as compared to 1.0 accuaracy of the
               // IGEOLO field.
               //---
               ossimDpt tie;
               std::vector<ossimGpt> gpts;
               if ( getBlockaPoints(hdr, gpts) )
               {
                  if (traceDebug())
                  {
                     ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimNitfProjectionFactory::makeUtm DEBUG:"
                        << "\nTie point from blocka: " << gpts[0]
                        << endl;
                  }
                  
                  tie = proj->forward(gpts[0]);
                  tie.x += scale.x/2.0;
                  tie.y -= scale.y/2.0;
               }
               else
               {
                  tie.x = utmPoints[0].x + scale.x/2.0;
                  tie.y = utmPoints[0].y - scale.y/2.0;
               }
               
               if (traceDebug())
               {
                  ossimNotify(ossimNotifyLevel_DEBUG)
                     << "ossimNitfProjectionFactory::makeUtm DEBUG:"
                     << "\nTie point: " << tie
                     << "\nScale:     " << scale
                     << endl;
               }
               
               // Set the tie and scale.
               ossimMapProjection* mproj = dynamic_cast<ossimMapProjection*>(proj);
               if ( mproj )
               {
                  mproj->setUlEastingNorthing(tie);
                  mproj->setMetersPerPixel(scale);
               }
               else // cannot cast
               {
                  if ( proj )
                  {
                     delete proj;
                     proj = 0;
                  }
               }
            }
            else // Scale has nans
            {
               if ( proj )
               {
                  delete proj;
                  proj = 0;
               }
            }
            
         } // matches: if (status)

      } // matches:  if ( geographicLocation.size() )
         
   } // matches: if (hdr)
   
   return proj;
}