Esempio n. 1
0
  /**
   * Convert from lat/lon (GDC) coordinates to UTM coords. Note this finds UTM x/y and corresponding
   * UTM zones (1...60) - use method getZoneNumbers(), and hemisphere flags == true if north - use
   * method getHemisphereFlags(). All positions' elevations are set to zero.
   *
   * @param latlon lat/lon values (lat = latlon[0][i], lon=latlon[1][i])
   * @return UTM coordinates (x = result[0][i], y=result[1][i])
   * @throws VisADException unable to make transformation
   */
  public float[][] fromReference(float[][] latlon) throws VisADException {

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

    // set array sizes
    zone = new int[MAX_POINTS];
    hemisphere_north = new boolean[MAX_POINTS];
    Gdc_Coord_3d gdc[] = new Gdc_Coord_3d[MAX_POINTS]; // these need to be the same len
    Utm_Coord_3d utm[] = new Utm_Coord_3d[MAX_POINTS];

    // move lat lon to right kind of object for geotransform menthods
    // use cstr Gdc_Coord_3d( double lat, double lon, double elev )
    for (int i = 0; i < MAX_POINTS; i++) {
      gdc[i] = new Gdc_Coord_3d(latlon[0][i], latlon[1][i], 0.0);
      utm[i] = new Utm_Coord_3d();
    }

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

    // switch utm coords back to double [][] array
    float[][] result = new float[2][MAX_POINTS];
    for (int i = 0; i < MAX_POINTS; i++) {
      Utm_Coord_3d utmCoord = utm[i];
      result[0][i] =
          // TODO:  Can we convert from one UTM zone to another?
          // (float) ((utmCoord.zone - onezone)*10E6 + utmCoord.x);
          (utmCoord.zone != onezone) ? Float.NaN : (float) utmCoord.x;
      result[1][i] = (utmCoord.zone != onezone) ? Float.NaN : (float) utmCoord.y;
      this.zone[i] = utmCoord.zone;
      this.hemisphere_north[i] = utmCoord.hemisphere_north;
    }

    return result;
  }