Exemplo n.º 1
0
  /**
   * Convert an array of UTM positions to lat/lon. All elevations zero. The UTM positions may be in
   * more than one zone or one hemisphere. Each UTM position has an x,y pair, a zone number, and a
   * hemisphere boolean flag. Lengths of all three arrays should be the same, the number of
   * positions to convert., or both "zone" and "hemisphere_north" may both have one value for the
   * case where all UTM positions are in the same zone.
   *
   * @param utmcoords array with UTM x,y values; x=utmcoords[0][i], y=utmcoords[1][i]
   * @param zone array of the UTM zones for each of these positions
   * @param hemisphere_north array of the UTM flags for each of these positions true if the UTM
   *     position is in the northern hemisphere
   * @return a double[][] array of lat/lon; lat=result[0][i], lon=result[1][i]
   * @throws VisADException
   */
  public double[][] ConvertUtmToLatLon(double[][] utmcoords, int zone[], boolean hemisphere_north[])
      throws VisADException {

    // this.zone = zone;
    // this.hemisphere_north = hemisphere_north;

    int MAX_POINTS = (utmcoords[0].length);
    // set working array sizes
    Gdc_Coord_3d gdc[] = new Gdc_Coord_3d[MAX_POINTS];
    Utm_Coord_3d utm[] = new Utm_Coord_3d[MAX_POINTS];

    if ((zone.length == 1) && (hemisphere_north.length == 1))
    // case of single zone and hemisphere
    {
      for (int i = 0; i < MAX_POINTS; i++) {
        gdc[i] = new Gdc_Coord_3d();
        utm[i] =
            new Utm_Coord_3d(
                utmcoords[0][i], utmcoords[1][i], 0.0, (byte) (zone[0]), hemisphere_north[0]);
      }
    } else if ((zone.length == MAX_POINTS) && (hemisphere_north.length == MAX_POINTS))
    // usual general purpose case
    {
      for (int i = 0; i < MAX_POINTS; i++) {
        gdc[i] = new Gdc_Coord_3d();
        utm[i] =
            new Utm_Coord_3d(
                utmcoords[0][i], utmcoords[1][i], 0.0, (byte) (zone[i]), hemisphere_north[i]);
      }
    } else {
      System.out.println(" size of input zone and hemi arrays does not match number of positions");
      double[][] dummy = {{0.0}, {0.0}};
      return dummy;
    }

    // initialize the converter
    // Utm_To_Gdc_Converter.Init(getEllip());

    // convert the positions
    Utm_To_Gdc_Converter.Convert(utm, gdc);

    // switch to double [][] array
    double[][] result = new double[2][MAX_POINTS];
    for (int i = 0; i < MAX_POINTS; i++) {
      result[0][i] = gdc[i].latitude;
      result[1][i] = gdc[i].longitude;
    }

    return result;
  }
Exemplo n.º 2
0
  /**
   * Convert an array of UTM positions to lat/lon. The UTM positions are all assumed have the zone
   * and hemisphere used in the cstr.
   *
   * <p>Each UTM position has an x,y pair, a zone number, and a hemisphere boolean flag. Treats all
   * positions as at zero elevation.
   *
   * @param utmcoords array with UTM x,y values; x=utmcoords[0][i], y=utmcoords[1][i]
   * @return a double [][] array of lat/lon; lat=result[0][i], lon=result[1][i]
   * @throws VisADException
   */
  public float[][] toReference(float[][] utmcoords) throws VisADException {

    // initialize the coordinates in geotransform arrays
    int MAX_POINTS = (utmcoords[0].length);

    Gdc_Coord_3d gdc[] = new Gdc_Coord_3d[MAX_POINTS];
    Utm_Coord_3d utm[] = new Utm_Coord_3d[MAX_POINTS];
    for (int i = 0; i < MAX_POINTS; i++) {
      gdc[i] = new Gdc_Coord_3d();
      utm[i] = new Utm_Coord_3d(utmcoords[0][i], utmcoords[1][i], 0.0, (byte) onezone, onehemiflag);
    }

    // convert the positions
    Utm_To_Gdc_Converter.Convert(utm, gdc);

    // switch to double [][] array
    float[][] result = new float[2][MAX_POINTS];
    for (int i = 0; i < MAX_POINTS; i++) {
      result[0][i] = (float) gdc[i].latitude;
      result[1][i] = (float) gdc[i].longitude;
    }

    return result;
  }