Ejemplo 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);
  }
Ejemplo n.º 2
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;
  }