Ignore:
Timestamp:
2010-01-09T15:49:04+01:00 (14 years ago)
Author:
jttt
Message:

Fixed some FindBugs warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/UTM.java

    r2516 r2789  
    1212import javax.swing.JPanel;
    1313
    14 import org.openstreetmap.josm.Main;
    1514import org.openstreetmap.josm.data.Bounds;
    1615import org.openstreetmap.josm.data.coor.EastNorth;
     
    2928    private int zone = DEFAULT_ZONE;
    3029
    31     final private double UTMScaleFactor = 0.9996;
     30    final private static double UTMScaleFactor = 0.9996;
    3231
    3332    /* Ellipsoid model constants (WGS84) - TODO Use Elliposid class here too */
    34     final private double sm_EccSquared = 6.69437999013e-03;
     33    //final private double sm_EccSquared = 6.69437999013e-03;
    3534
    3635    /*
    37     * ArcLengthOfMeridian
    38     *
    39     * Computes the ellipsoidal distance from the equator to a point at a
    40     * given latitude.
    41     *
    42     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
    43     * GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
    44     *
    45     * Inputs:
    46     *     phi - Latitude of the point, in radians.
    47     *
    48     * Globals:
    49     *     Ellipsoid.GRS80.a - Ellipsoid model major axis.
    50     *     Ellipsoid.GRS80.b - Ellipsoid model minor axis.
    51     *
    52     * Returns:
    53     *     The ellipsoidal distance of the point from the equator, in meters.
    54     *
    55     */
     36     * ArcLengthOfMeridian
     37     *
     38     * Computes the ellipsoidal distance from the equator to a point at a
     39     * given latitude.
     40     *
     41     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
     42     * GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
     43     *
     44     * Inputs:
     45     *     phi - Latitude of the point, in radians.
     46     *
     47     * Globals:
     48     *     Ellipsoid.GRS80.a - Ellipsoid model major axis.
     49     *     Ellipsoid.GRS80.b - Ellipsoid model minor axis.
     50     *
     51     * Returns:
     52     *     The ellipsoidal distance of the point from the equator, in meters.
     53     *
     54     */
    5655    private double ArcLengthOfMeridian(double phi)
    5756    {
     
    6160        /* Precalculate alpha */
    6261        double alpha = ((Ellipsoid.GRS80.a + Ellipsoid.GRS80.b) / 2.0)
    63            * (1.0 + (Math.pow (n, 2.0) / 4.0) + (Math.pow (n, 4.0) / 64.0));
     62        * (1.0 + (Math.pow (n, 2.0) / 4.0) + (Math.pow (n, 4.0) / 64.0));
    6463
    6564        /* Precalculate beta */
    6665        double beta = (-3.0 * n / 2.0) + (9.0 * Math.pow (n, 3.0) / 16.0)
    67            + (-3.0 * Math.pow (n, 5.0) / 32.0);
     66        + (-3.0 * Math.pow (n, 5.0) / 32.0);
    6867
    6968        /* Precalculate gamma */
    7069        double gamma = (15.0 * Math.pow (n, 2.0) / 16.0)
    71             + (-15.0 * Math.pow (n, 4.0) / 32.0);
     70        + (-15.0 * Math.pow (n, 4.0) / 32.0);
    7271
    7372        /* Precalculate delta */
    7473        double delta = (-35.0 * Math.pow (n, 3.0) / 48.0)
    75             + (105.0 * Math.pow (n, 5.0) / 256.0);
     74        + (105.0 * Math.pow (n, 5.0) / 256.0);
    7675
    7776        /* Precalculate epsilon */
     
    8180        return alpha
    8281        * (phi + (beta * Math.sin (2.0 * phi))
    83             + (gamma * Math.sin (4.0 * phi))
    84             + (delta * Math.sin (6.0 * phi))
    85             + (epsilon * Math.sin (8.0 * phi)));
     82                + (gamma * Math.sin (4.0 * phi))
     83                + (delta * Math.sin (6.0 * phi))
     84                + (epsilon * Math.sin (8.0 * phi)));
    8685    }
    8786
    8887    /*
    89     * UTMCentralMeridian
    90     *
    91     * Determines the central meridian for the given UTM zone.
    92     *
    93     * Inputs:
    94     *     zone - An integer value designating the UTM zone, range [1,60].
    95     *
    96     * Returns:
    97     *   The central meridian for the given UTM zone, in radians, or zero
    98     *   if the UTM zone parameter is outside the range [1,60].
    99     *   Range of the central meridian is the radian equivalent of [-177,+177].
    100     *
    101     */
     88     * UTMCentralMeridian
     89     *
     90     * Determines the central meridian for the given UTM zone.
     91     *
     92     * Inputs:
     93     *     zone - An integer value designating the UTM zone, range [1,60].
     94     *
     95     * Returns:
     96     *   The central meridian for the given UTM zone, in radians, or zero
     97     *   if the UTM zone parameter is outside the range [1,60].
     98     *   Range of the central meridian is the radian equivalent of [-177,+177].
     99     *
     100     */
    102101    private double UTMCentralMeridian(int zone)
    103102    {
     
    110109
    111110    /*
    112     * FootpointLatitude
    113     *
    114     * Computes the footpoint latitude for use in converting transverse
    115     * Mercator coordinates to ellipsoidal coordinates.
    116     *
    117     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
    118     *   GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
    119     *
    120     * Inputs:
    121     *   y - The UTM northing coordinate, in meters.
    122     *
    123     * Returns:
    124     *   The footpoint latitude, in radians.
    125     *
    126     */
     111     * FootpointLatitude
     112     *
     113     * Computes the footpoint latitude for use in converting transverse
     114     * Mercator coordinates to ellipsoidal coordinates.
     115     *
     116     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
     117     *   GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
     118     *
     119     * Inputs:
     120     *   y - The UTM northing coordinate, in meters.
     121     *
     122     * Returns:
     123     *   The footpoint latitude, in radians.
     124     *
     125     */
    127126    private double FootpointLatitude(double y)
    128127    {
     
    133132        /* (Same as alpha in Eq. 10.17) */
    134133        double alpha_ = ((Ellipsoid.GRS80.a + Ellipsoid.GRS80.b) / 2.0)
    135             * (1 + (Math.pow (n, 2.0) / 4) + (Math.pow (n, 4.0) / 64));
     134        * (1 + (Math.pow (n, 2.0) / 4) + (Math.pow (n, 4.0) / 64));
    136135
    137136        /* Precalculate y_ (Eq. 10.23) */
     
    140139        /* Precalculate beta_ (Eq. 10.22) */
    141140        double beta_ = (3.0 * n / 2.0) + (-27.0 * Math.pow (n, 3.0) / 32.0)
    142             + (269.0 * Math.pow (n, 5.0) / 512.0);
     141        + (269.0 * Math.pow (n, 5.0) / 512.0);
    143142
    144143        /* Precalculate gamma_ (Eq. 10.22) */
    145144        double gamma_ = (21.0 * Math.pow (n, 2.0) / 16.0)
    146             + (-55.0 * Math.pow (n, 4.0) / 32.0);
     145        + (-55.0 * Math.pow (n, 4.0) / 32.0);
    147146
    148147        /* Precalculate delta_ (Eq. 10.22) */
    149148        double delta_ = (151.0 * Math.pow (n, 3.0) / 96.0)
    150             + (-417.0 * Math.pow (n, 5.0) / 128.0);
     149        + (-417.0 * Math.pow (n, 5.0) / 128.0);
    151150
    152151        /* Precalculate epsilon_ (Eq. 10.22) */
     
    155154        /* Now calculate the sum of the series (Eq. 10.21) */
    156155        return y_ + (beta_ * Math.sin (2.0 * y_))
    157             + (gamma_ * Math.sin (4.0 * y_))
    158             + (delta_ * Math.sin (6.0 * y_))
    159             + (epsilon_ * Math.sin (8.0 * y_));
     156        + (gamma_ * Math.sin (4.0 * y_))
     157        + (delta_ * Math.sin (6.0 * y_))
     158        + (epsilon_ * Math.sin (8.0 * y_));
    160159    }
    161160
    162161    /*
    163     * MapLatLonToXY
    164     *
    165     * Converts a latitude/longitude pair to x and y coordinates in the
    166     * Transverse Mercator projection.  Note that Transverse Mercator is not
    167     * the same as UTM; a scale factor is required to convert between them.
    168     *
    169     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
    170     * GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
    171     *
    172     * Inputs:
    173     *    phi - Latitude of the point, in radians.
    174     *    lambda - Longitude of the point, in radians.
    175     *    lambda0 - Longitude of the central meridian to be used, in radians.
    176     *
    177     * Outputs:
    178     *    xy - A 2-element array containing the x and y coordinates
    179     *         of the computed point.
    180     *
    181     * Returns:
    182     *    The function does not return a value.
    183     *
    184     */
    185     public EastNorth MapLatLonToXY(double phi, double lambda, double lambda0)
     162     * MapLatLonToXY
     163     *
     164     * Converts a latitude/longitude pair to x and y coordinates in the
     165     * Transverse Mercator projection.  Note that Transverse Mercator is not
     166     * the same as UTM; a scale factor is required to convert between them.
     167     *
     168     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
     169     * GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
     170     *
     171     * Inputs:
     172     *    phi - Latitude of the point, in radians.
     173     *    lambda - Longitude of the point, in radians.
     174     *    lambda0 - Longitude of the central meridian to be used, in radians.
     175     *
     176     * Outputs:
     177     *    xy - A 2-element array containing the x and y coordinates
     178     *         of the computed point.
     179     *
     180     * Returns:
     181     *    The function does not return a value.
     182     *
     183     */
     184    public EastNorth mapLatLonToXY(double phi, double lambda, double lambda0)
    186185    {
    187186        /* Precalculate ep2 */
     
    197196        double t = Math.tan (phi);
    198197        double t2 = t * t;
    199         double tmp = (t2 * t2 * t2) - Math.pow (t, 6.0);
    200198
    201199        /* Precalculate l */
     
    211209
    212210        double l5coef = 5.0 - 18.0 * t2 + (t2 * t2) + 14.0 * nu2
    213             - 58.0 * t2 * nu2;
     211        - 58.0 * t2 * nu2;
    214212
    215213        double l6coef = 61.0 - 58.0 * t2 + (t2 * t2) + 270.0 * nu2
    216             - 330.0 * t2 * nu2;
     214        - 330.0 * t2 * nu2;
    217215
    218216        double l7coef = 61.0 - 479.0 * t2 + 179.0 * (t2 * t2) - (t2 * t2 * t2);
     
    221219
    222220        return new EastNorth(
    223         /* Calculate easting (x) */
    224         N * Math.cos (phi) * l
    225             + (N / 6.0 * Math.pow (Math.cos (phi), 3.0) * l3coef * Math.pow (l, 3.0))
    226             + (N / 120.0 * Math.pow (Math.cos (phi), 5.0) * l5coef * Math.pow (l, 5.0))
    227             + (N / 5040.0 * Math.pow (Math.cos (phi), 7.0) * l7coef * Math.pow (l, 7.0)),
    228         /* Calculate northing (y) */
    229         ArcLengthOfMeridian (phi)
    230             + (t / 2.0 * N * Math.pow (Math.cos (phi), 2.0) * Math.pow (l, 2.0))
    231             + (t / 24.0 * N * Math.pow (Math.cos (phi), 4.0) * l4coef * Math.pow (l, 4.0))
    232             + (t / 720.0 * N * Math.pow (Math.cos (phi), 6.0) * l6coef * Math.pow (l, 6.0))
    233             + (t / 40320.0 * N * Math.pow (Math.cos (phi), 8.0) * l8coef * Math.pow (l, 8.0)));
     221                /* Calculate easting (x) */
     222                N * Math.cos (phi) * l
     223                + (N / 6.0 * Math.pow (Math.cos (phi), 3.0) * l3coef * Math.pow (l, 3.0))
     224                + (N / 120.0 * Math.pow (Math.cos (phi), 5.0) * l5coef * Math.pow (l, 5.0))
     225                + (N / 5040.0 * Math.pow (Math.cos (phi), 7.0) * l7coef * Math.pow (l, 7.0)),
     226                /* Calculate northing (y) */
     227                ArcLengthOfMeridian (phi)
     228                + (t / 2.0 * N * Math.pow (Math.cos (phi), 2.0) * Math.pow (l, 2.0))
     229                + (t / 24.0 * N * Math.pow (Math.cos (phi), 4.0) * l4coef * Math.pow (l, 4.0))
     230                + (t / 720.0 * N * Math.pow (Math.cos (phi), 6.0) * l6coef * Math.pow (l, 6.0))
     231                + (t / 40320.0 * N * Math.pow (Math.cos (phi), 8.0) * l8coef * Math.pow (l, 8.0)));
    234232    }
    235233
    236234    /*
    237     * MapXYToLatLon
    238     *
    239     * Converts x and y coordinates in the Transverse Mercator projection to
    240     * a latitude/longitude pair.  Note that Transverse Mercator is not
    241     * the same as UTM; a scale factor is required to convert between them.
    242     *
    243     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
    244     *   GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
    245     *
    246     * Inputs:
    247     *   x - The easting of the point, in meters.
    248     *   y - The northing of the point, in meters.
    249     *   lambda0 - Longitude of the central meridian to be used, in radians.
    250     *
    251     * Outputs:
    252     *   philambda - A 2-element containing the latitude and longitude
    253     *               in radians.
    254     *
    255     * Returns:
    256     *   The function does not return a value.
    257     *
    258     * Remarks:
    259     *   The local variables Nf, nuf2, tf, and tf2 serve the same purpose as
    260     *   N, nu2, t, and t2 in MapLatLonToXY, but they are computed with respect
    261     *   to the footpoint latitude phif.
    262     *
    263     *   x1frac, x2frac, x2poly, x3poly, etc. are to enhance readability and
    264     *   to optimize computations.
    265     *
    266     */
    267     public LatLon MapXYToLatLon(double x, double y, double lambda0)
     235     * MapXYToLatLon
     236     *
     237     * Converts x and y coordinates in the Transverse Mercator projection to
     238     * a latitude/longitude pair.  Note that Transverse Mercator is not
     239     * the same as UTM; a scale factor is required to convert between them.
     240     *
     241     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
     242     *   GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
     243     *
     244     * Inputs:
     245     *   x - The easting of the point, in meters.
     246     *   y - The northing of the point, in meters.
     247     *   lambda0 - Longitude of the central meridian to be used, in radians.
     248     *
     249     * Outputs:
     250     *   philambda - A 2-element containing the latitude and longitude
     251     *               in radians.
     252     *
     253     * Returns:
     254     *   The function does not return a value.
     255     *
     256     * Remarks:
     257     *   The local variables Nf, nuf2, tf, and tf2 serve the same purpose as
     258     *   N, nu2, t, and t2 in MapLatLonToXY, but they are computed with respect
     259     *   to the footpoint latitude phif.
     260     *
     261     *   x1frac, x2frac, x2poly, x3poly, etc. are to enhance readability and
     262     *   to optimize computations.
     263     *
     264     */
     265    public LatLon mapXYToLatLon(double x, double y, double lambda0)
    268266    {
    269267        /* Get the value of phif, the footpoint latitude. */
     
    272270        /* Precalculate ep2 */
    273271        double ep2 = (Math.pow (Ellipsoid.GRS80.a, 2.0) - Math.pow (Ellipsoid.GRS80.b, 2.0))
    274               / Math.pow (Ellipsoid.GRS80.b, 2.0);
     272        / Math.pow (Ellipsoid.GRS80.b, 2.0);
    275273
    276274        /* Precalculate cos (phif) */
     
    325323
    326324        return new LatLon(
    327         /* Calculate latitude */
    328         Math.toDegrees(
    329         phif + x2frac * x2poly * (x * x)
    330         + x4frac * x4poly * Math.pow (x, 4.0)
    331         + x6frac * x6poly * Math.pow (x, 6.0)
    332         + x8frac * x8poly * Math.pow (x, 8.0)),
    333         Math.toDegrees(
    334         /* Calculate longitude */
    335         lambda0 + x1frac * x
    336         + x3frac * x3poly * Math.pow (x, 3.0)
    337         + x5frac * x5poly * Math.pow (x, 5.0)
    338         + x7frac * x7poly * Math.pow (x, 7.0)));
     325                /* Calculate latitude */
     326                Math.toDegrees(
     327                        phif + x2frac * x2poly * (x * x)
     328                        + x4frac * x4poly * Math.pow (x, 4.0)
     329                        + x6frac * x6poly * Math.pow (x, 6.0)
     330                        + x8frac * x8poly * Math.pow (x, 8.0)),
     331                        Math.toDegrees(
     332                                /* Calculate longitude */
     333                                lambda0 + x1frac * x
     334                                + x3frac * x3poly * Math.pow (x, 3.0)
     335                                + x5frac * x5poly * Math.pow (x, 5.0)
     336                                + x7frac * x7poly * Math.pow (x, 7.0)));
    339337    }
    340338
    341339    public EastNorth latlon2eastNorth(LatLon p) {
    342         EastNorth a = MapLatLonToXY(Math.toRadians(p.lat()), Math.toRadians(p.lon()), UTMCentralMeridian(getzone()));
     340        EastNorth a = mapLatLonToXY(Math.toRadians(p.lat()), Math.toRadians(p.lon()), UTMCentralMeridian(getzone()));
    343341        return new EastNorth(a.east() * UTMScaleFactor + 3500000.0, a.north() * UTMScaleFactor);
    344342    }
    345343
    346344    public LatLon eastNorth2latlon(EastNorth p) {
    347         return MapXYToLatLon((p.east()-3500000.0)/UTMScaleFactor, p.north()/UTMScaleFactor, UTMCentralMeridian(getzone()));
     345        return mapXYToLatLon((p.east()-3500000.0)/UTMScaleFactor, p.north()/UTMScaleFactor, UTMCentralMeridian(getzone()));
    348346    }
    349347
     
    414412                {
    415413                    zone = Integer.parseInt(s);
    416                     if(zone <= 0 || zone > 60)
     414                    if(zone <= 0 || zone > 60) {
    417415                        zone = DEFAULT_ZONE;
     416                    }
    418417                    break;
    419418                }
     
    430429                int zoneval = Integer.parseInt(zonestring);
    431430                if(zoneval > 0 && zoneval <= 60)
    432                 {
    433431                    return Collections.singleton(zonestring);
    434                 }
    435432            } catch(NumberFormatException e) {}
    436433        }
Note: See TracChangeset for help on using the changeset viewer.