Exemplo n.º 1
0
void GRID_UPS (long   *Letters,
               char   *Hemisphere,
               double *Easting,
               double *Northing,
               long   *Error)
{ /* BEGIN GRID_UPS */
  double feltr=0.0;               /* False easting for 2nd letter               */
  double fnltr=0.0;               /* False northing for 3rd letter              */
  // double sleast=0.0;              /* Longitude east limit - UTM                 */
  // double slwest=0.0;              /* Longitude west limit -UTM                  */
  // double spnor=0.0;               /* North latitude limits based on 1st letter  */
  double spsou=0.0;               /* South latitude limits based on 1st letter  */
  double x=0.0;                   /* easting                                    */
  double xltr=0.0;                /* easting for 100,000 meter grid square      */
  double xnum=0.0;                /* easting part of MGRS                       */
  double y=0.0;                   /* northing                                   */
  double yltr=0.0;                /* northing for 100,000 meter grid square     */
  double ynum=0.0;                /* northing part of MGRS                      */
  // long izone=0;                 /* Zone number                                */
  long ltrhi=0;                 /* 2nd letter range - high number             */
  long ltrhy=0;                 /* 3rd letter range - high number (UPS)       */
  long ltrlow=0;                /* 2nd letter range - low number              */
  long sign=0;
  double sphi=0.0;
  double slam=0.0;
  if ((Letters[0] == LETTER_Y) || (Letters[0] == LETTER_Z))
  {
    spsou = MAX_UTM_LAT;
    sign = 1;
  }
  else
  {
    spsou = MIN_UTM_LAT;
    sign = -1;
  }
  slam = PI / 2.e0;
  if ((Letters[0] == LETTER_Y) || (Letters[0] == LETTER_A))
  {
    slam = -slam;
  }
  // izone = 0;
  sphi = spsou;
  Set_UPS_Parameters(OSSIM_MGRS_a,OSSIM_MGRS_f);
  Convert_Geodetic_To_UPS(sphi,slam,Hemisphere,&x,&y);
  // spnor = sphi;
  // sleast = slam;
  // slwest = slam;
  UPSSET(Letters[0], &ltrlow, &ltrhi, &feltr, &fnltr, &ltrhy);
  LTR2UPS(Letters, ltrlow, ltrhi, ltrhy, Error, &xltr, &yltr, fnltr, feltr, 
          &x, &y, sign);
  xnum = *Easting;
  ynum = *Northing;
  y = (yltr + ynum);
  x = xltr + xnum;
  *Easting = x;
  *Northing = y;
  return;
} /* END OF GRID_UPS */
Exemplo n.º 2
0
long Convert_Geodetic_To_OSSIM_MGRS (double Latitude,
                               double Longitude,
                               long Precision,
                               char* OSSIM_MGRS)
/*
 *    Latitude   : Latitude in radians              (input)
 *    Longitude  : Longitude in radians             (input)
 *    OSSIM_MGRS       : OSSIM_MGRS coordinate string           (output)
 *  
 */
{ /* Convert_Geodetic_To_OSSIM_MGRS */
  long error_code = OSSIM_MGRS_NO_ERROR;
  long zone;
  char hemisphere;
  double easting;
  double northing;
  if ((Latitude < -PI_OVER_2) || (Latitude > PI_OVER_2))
  { /* Latitude out of range */
    error_code |= OSSIM_MGRS_LAT_ERROR;
  }
  if ((Longitude < -PI) || (Longitude > (2*PI)))
  { /* Longitude out of range */
    error_code |= OSSIM_MGRS_LON_ERROR;
  }
  if ((Precision < 0) || (Precision > MAX_PRECISION))
    error_code |= OSSIM_MGRS_PRECISION_ERROR;
  if (!error_code)
  {
    if ((Latitude < MIN_UTM_LAT) || (Latitude > MAX_UTM_LAT))
    {
      Set_UPS_Parameters (OSSIM_MGRS_a, OSSIM_MGRS_f);
      error_code |= Convert_Geodetic_To_UPS (Latitude, Longitude, &hemisphere, &easting, &northing);
      error_code |= Convert_UPS_To_OSSIM_MGRS (hemisphere, easting, northing, Precision, OSSIM_MGRS);
    }
    else
    {
      Set_UTM_Parameters (OSSIM_MGRS_a, OSSIM_MGRS_f, 0);
      error_code |= Convert_Geodetic_To_UTM (Latitude, Longitude, &zone, &hemisphere, &easting, &northing);
      error_code |= Convert_UTM_To_OSSIM_MGRS (zone, hemisphere, easting, northing, Precision, OSSIM_MGRS);
    }
  }
  return (error_code);
} /* Convert_Geodetic_To_OSSIM_MGRS */
Exemplo n.º 3
0
Arquivo: mgrs.c Projeto: dwyerk/mgrs
long Convert_Geodetic_To_MGRS (double Latitude,
                               double Longitude,
                               long Precision,
                               char* MGRS)
/*
 * The function Convert_Geodetic_To_MGRS converts Geodetic (latitude and
 * longitude) coordinates to an MGRS coordinate string, according to the
 * current ellipsoid parameters.  If any errors occur, the error code(s)
 * are returned by the function, otherwise MGRS_NO_ERROR is returned.
 *
 *    Latitude   : Latitude in radians              (input)
 *    Longitude  : Longitude in radians             (input)
 *    Precision  : Precision level of MGRS string   (input)
 *    MGRS       : MGRS coordinate string           (output)
 *
 */
{ /* Convert_Geodetic_To_MGRS */
  long zone;
  char hemisphere;
  double easting;
  double northing;
  long temp_error_code = MGRS_NO_ERROR;
  long error_code = MGRS_NO_ERROR;

  if ((Latitude < -PI_OVER_2) || (Latitude > PI_OVER_2))
  { /* Latitude out of range */
    error_code |= MGRS_LAT_ERROR;
  }
  if ((Longitude < -PI) || (Longitude > (2*PI)))
  { /* Longitude out of range */
    error_code |= MGRS_LON_ERROR;
  }
  if ((Precision < 0) || (Precision > MAX_PRECISION))
    error_code |= MGRS_PRECISION_ERROR;
  if (!error_code)
  {
    if ((Latitude < MIN_UTM_LAT) || (Latitude > MAX_UTM_LAT))
    {
      temp_error_code = Set_UPS_Parameters (MGRS_a, MGRS_f);
      if(!temp_error_code)
      {
        temp_error_code = Convert_Geodetic_To_UPS (Latitude, Longitude, &hemisphere, &easting, &northing);
        if(!temp_error_code)
        {
          error_code |= Convert_UPS_To_MGRS (hemisphere, easting, northing, Precision, MGRS);
        }
        else
        {
          if(temp_error_code & UPS_LAT_ERROR)
            error_code |= MGRS_LAT_ERROR;
          if(temp_error_code & UPS_LON_ERROR)
            error_code |= MGRS_LON_ERROR;
        }
      }
      else
      {
        if(temp_error_code & UPS_A_ERROR)
          error_code |= MGRS_A_ERROR;
        if(temp_error_code & UPS_INV_F_ERROR)
          error_code |= MGRS_INV_F_ERROR;
      }
    }
    else
    {
      temp_error_code = Set_UTM_Parameters (MGRS_a, MGRS_f, 0);
      if(!temp_error_code)
      {
        temp_error_code = Convert_Geodetic_To_UTM (Latitude, Longitude, &zone, &hemisphere, &easting, &northing);
        if(!temp_error_code)
          error_code |= UTM_To_MGRS (zone, hemisphere, Longitude, Latitude, easting, northing, Precision, MGRS);
        else
        {
          if(temp_error_code & UTM_LAT_ERROR)
            error_code |= MGRS_LAT_ERROR;
          if(temp_error_code & UTM_LON_ERROR)
            error_code |= MGRS_LON_ERROR;
          if(temp_error_code & UTM_ZONE_OVERRIDE_ERROR)
            error_code |= MGRS_ZONE_ERROR;
          if(temp_error_code & UTM_EASTING_ERROR)
            error_code |= MGRS_EASTING_ERROR;
          if(temp_error_code & UTM_NORTHING_ERROR)
            error_code |= MGRS_NORTHING_ERROR;
        }
      }
      else
      {
        if(temp_error_code & UTM_A_ERROR)
          error_code |= MGRS_A_ERROR;
        if(temp_error_code & UTM_INV_F_ERROR)
          error_code |= MGRS_INV_F_ERROR;
        if(temp_error_code & UTM_ZONE_OVERRIDE_ERROR)
          error_code |= MGRS_ZONE_ERROR;
      }
    }
  }
  return (error_code);
} /* Convert_Geodetic_To_MGRS */