Exemplo n.º 1
0
  /**
   * Constructs an instance of a UTM coordinate transform with the supplied Ellipsoid, zone and
   * hemisphere. The ellipsoid should be the one used as a basis for the UTM coordinates. The zone
   * is the UTM zone which has positions to be converted; hemiflag is a boolean, true if points are
   * northern hemisphere. You can convert points from more than one zone and hemisphere by using the
   * method ConvertUtmToLatLon.
   *
   * <p>The reference coordinate system is RealTupleType.LatitudeLongitudeTuple; the incoming units
   * are assumed to be UTM coords based on the input ellipsoid.
   *
   * <p>Most USGS topographic maps use the 1927 North American Datum (NAD 27); new maps are being
   * slowly revised to NAD 83. To construct Ellipsoids for the first argument, import
   * geotransform.jar, and do new CC_Ellipsoid() for NAD 27 (Clark 1866 ellipsoid), or new
   * RF_Ellipsoid() for NAD 83 (GRS 80 ellipsoid), or new WE_Ellipsoid() for WSG 84. See
   * http://www.ai.sri.com/geotransform/api.html for more details about 239 supported datums.
   *
   * @param ellipsoid the basis for some UTM coordinate system; many choices possible
   * @param zone the UTM zone which has positions to be converted
   * @param bounds Linear2DSet describing the bounds of this MapProjection
   * @param hemiflag a boolean, true if points are in the northern hemisphere
   * @throws VisADException
   */
  public UTMCoordinateSystem(Ellipsoid ellipsoid, int zone, boolean hemiflag, Rectangle2D bounds)
      throws VisADException {

    super(RealTupleType.LatitudeLongitudeTuple, new Unit[] {CommonUnit.meter, CommonUnit.meter});

    if (ellipsoid == null) {
      throw new NullPointerException();
    }

    if ((zone < 1) || (zone > 60)) {
      throw new IllegalArgumentException("UTM zone number not in range 1-60");
    }

    if (bounds != null) {
      startX = bounds.getX();
      startY = bounds.getY();
      width = bounds.getWidth();
      height = bounds.getHeight();
    }

    this.ellipsoid = ellipsoid;
    this.onezone = zone;
    this.onehemiflag = hemiflag;

    // initialize the converters
    Utm_To_Gdc_Converter.Init(ellipsoid);
    Gdc_To_Utm_Converter.Init(ellipsoid);
  }
Exemplo n.º 2
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.º 3
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;
  }