Ignore:
Timestamp:
2012-03-10T16:18:23+01:00 (8 years ago)
Author:
bastiK
Message:

Proj parameter refactoring (see #7495)

Location:
trunk/src/org/openstreetmap/josm/data/projection/proj
Files:
1 added
5 edited

Legend:

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

    r5040 r5066  
    77
    88import org.openstreetmap.josm.data.projection.Ellipsoid;
     9import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
    910
    1011/**
     
    1415 */
    1516public class LambertConformalConic implements Proj {
    16    
     17
    1718    protected Ellipsoid ellps;
    1819    protected double e;
    19    
     20
    2021    public static abstract class Parameters {
    2122        public final double latitudeOrigin;
     
    2425        }
    2526    };
    26    
     27
    2728    public static class Parameters1SP extends Parameters {
    2829        public Parameters1SP(double latitudeOrigin) {
     
    4243
    4344    private Parameters params;
    44    
     45
    4546    /**
    4647     * projection exponent
     
    5253    protected double F;
    5354    /**
    54      * radius of the parallel of latitude of the false origin (2SP) or at 
     55     * radius of the parallel of latitude of the false origin (2SP) or at
    5556     * natural origin (1SP)
    5657     */
    57     protected double r0; 
    58    
     58    protected double r0;
     59
    5960    /**
    6061     * precision in iterative schema
     
    6263    protected static final double epsilon = 1e-12;
    6364
    64     /**
    65      * Constructor.
    66      * Call one of the updateParameters... methods for initialization.
    67      */
    68     public LambertConformalConic() {
     65    @Override
     66    public void initialize(ProjParameters params) throws ProjectionConfigurationException {
     67        ellps = params.ellps;
     68        e = ellps.e;
     69        if (params.lcc_n != null && params.lcc_F != null && params.lcc_r0 != null) {
     70            initializeDirect(params.lcc_n, params.lcc_F, params.lcc_r0);
     71        } else {
     72            if (params.lat_0 == null)
     73                throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", "lat_0"));
     74            if (params.lat_1 != null && params.lat_2 != null) {
     75                initialize2SP(params.lat_0, params.lat_1, params.lat_2);
     76            } else {
     77                initialize1SP(params.lat_0);
     78            }
     79        }
    6980    }
    7081
    7182    /**
    7283     * Initialize for LCC with 2 standard parallels.
    73      *
    74      * @param ellps the ellipsoid
     84     *
    7585     * @param lat_0 latitude of false origin (in degrees)
    7686     * @param lat_1 latitude of first standard parallel (in degrees)
    7787     * @param lat_2 latitude of second standard parallel (in degrees)
    7888     */
    79     public void updateParameters2SP(Ellipsoid ellps, double lat_0, double lat_1, double lat_2) {
     89    private void initialize2SP(double lat_0, double lat_1, double lat_2) {
    8090        this.params = new Parameters2SP(lat_0, lat_1, lat_2);
    81         this.ellps = ellps;
    82         this.e = ellps.e;
    83        
     91
    8492        final double m1 = m(toRadians(lat_1));
    8593        final double m2 = m(toRadians(lat_2));
    86        
     94
    8795        final double t1 = t(toRadians(lat_1));
    8896        final double t2 = t(toRadians(lat_2));
    8997        final double tf = t(toRadians(lat_0));
    90        
     98
    9199        n  = (log(m1) - log(m2)) / (log(t1) - log(t2));
    92100        F  = m1 / (n * pow(t1, n));
    93101        r0 = F * pow(tf, n);
    94102    }
    95    
     103
    96104    /**
    97105     * Initialize for LCC with 1 standard parallel.
    98      *
    99      * @param ellps the ellipsoid
     106     *
    100107     * @param lat_0 latitude of natural origin (in degrees)
    101108     */
    102     public void updateParameters1SP(Ellipsoid ellps, double lat_0) {
     109    private void initialize1SP(double lat_0) {
    103110        this.params = new Parameters1SP(lat_0);
    104         this.ellps = ellps;
    105         this.e = ellps.e;
    106111        final double lat_0_rad = toRadians(lat_0);
    107        
     112
    108113        final double m0 = m(lat_0_rad);
    109114        final double t0 = t(lat_0_rad);
    110        
     115
    111116        n = sin(lat_0_rad);
    112117        F  = m0 / (n * pow(t0, n));
     
    116121    /**
    117122     * Initialize LCC by providing the projection parameters directly.
    118      *
    119      * @param ellps the ellipsoid
     123     *
    120124     * @param n see field n
    121125     * @param F see field F
    122126     * @param r0 see field r0
    123127     */
    124     public void updateParametersDirect(Ellipsoid ellps, double n, double F, double r0) {
     128    private void initializeDirect(double n, double F, double r0) {
    125129        this.params = null;
    126         this.ellps = ellps;
    127         this.e = ellps.e;
    128130        this.n = n;
    129131        this.F = F;
     
    145147        return cos(lat_rad) / (sqrt(1 - e * e * pow(sin(lat_rad), 2)));
    146148    }
    147    
     149
    148150    @Override
    149151    public String getName() {
     
    166168        return new double[] { X, Y };
    167169    }
    168    
     170
    169171    @Override
    170172    public double[] invproject(double east, double north) {
     
    176178        return new double[] { phi, lambda };
    177179    }
    178    
     180
    179181    public final Parameters getParameters() {
    180182        return params;
  • trunk/src/org/openstreetmap/josm/data/projection/proj/Mercator.java

    r4285 r5066  
    66import static org.openstreetmap.josm.tools.I18n.tr;
    77
     8import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
     9
    810/**
    911 * Mercator Projection.
    1012 */
    1113public class Mercator implements Proj {
    12    
     14
    1315    @Override
    1416    public String getName() {
     
    1921    public String getProj4Id() {
    2022        return "merc";
     23    }
     24
     25    @Override
     26    public void initialize(ProjParameters params) throws ProjectionConfigurationException {
    2127    }
    2228
  • trunk/src/org/openstreetmap/josm/data/projection/proj/Proj.java

    r4285 r5066  
    22package org.openstreetmap.josm.data.projection.proj;
    33
     4import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
     5
    46/**
    57 * A projection (in the narrow sense).
    6  * 
     8 *
    79 * Converts lat/lon the east/north and the other way around.
    8  * 
    9  * Datum conversion, false easting / northing, origin of longitude 
     10 *
     11 * Datum conversion, false easting / northing, origin of longitude
    1012 * and general scale factor is already applied when the projection is invoked.
    11  * 
     13 *
    1214 * Lat/lon is not in degrees, but in radians (unlike other parts of JOSM).
    13  * Additional parameters in the constructor arguments are usually still in 
    14  * degrees. So to avoid confusion, you can follow the convention, that 
     15 * Additional parameters in the constructor arguments are usually still in
     16 * degrees. So to avoid confusion, you can follow the convention, that
    1517 * coordinates in radians are called lat_rad/lon_rad or phi/lambda.
    16  * 
    17  * East/north values are not in meters, but in meters divided by the semi major 
    18  * axis of the ellipsoid (earth radius). (Usually this is what you get anyway, 
     18 *
     19 * East/north values are not in meters, but in meters divided by the semi major
     20 * axis of the ellipsoid (earth radius). (Usually this is what you get anyway,
    1921 * unless you multiply by 'a' somehow implicitly or explicitly.)
    2022 *
     
    2830    /**
    2931     * The Proj.4 identifier.
    30      * 
     32     *
    3133     * (as reported by cs2cs -lp)
    3234     * If no id exists, return null.
    3335     */
    3436    String getProj4Id();
    35    
     37
     38    /**
     39     * Initialize the projection using the provided parameters.
     40     *
     41     * @throws ProjectionConfigurationException in case parameters are not suitable
     42     */
     43    void initialize(ProjParameters params) throws ProjectionConfigurationException;
     44
    3645    /**
    3746     * Convert lat/lon to east/north.
    38      * 
     47     *
    3948     * @param lat_rad the latitude in radians
    4049     * @param lon_rad the longitude in radians
     
    4352     */
    4453    double[] project(double lat_rad, double lon_rad);
    45    
     54
    4655    /**
    4756     * Convert east/north to lat/lon.
    48      * 
     57     *
    4958     * @param east east value in meters, divided by the semi major axis of the ellipsoid
    5059     * @param north north value in meters, divided by the semi major axis of the ellipsoid
     
    5261     */
    5362    double[] invproject(double east, double north);
     63
    5464}
  • trunk/src/org/openstreetmap/josm/data/projection/proj/SwissObliqueMercator.java

    r4285 r5066  
    77
    88import org.openstreetmap.josm.data.projection.Ellipsoid;
     9import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
    910
    1011/**
     
    1920public class SwissObliqueMercator implements Proj {
    2021
    21     private final Ellipsoid ellps;
     22    private Ellipsoid ellps;
    2223    private double kR;
    2324    private double alpha;
    2425    private double b0;
    2526    private double K;
    26    
     27
    2728    private static final double EPSILON = 1e-11;
    28    
    29     public SwissObliqueMercator(Ellipsoid ellps, double lat_0) {
    30         this.ellps = ellps;
    31         updateParameters(lat_0);
     29
     30    @Override
     31    public void initialize(ProjParameters params) throws ProjectionConfigurationException {
     32        if (params.lat_0 == null)
     33            throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", "lat_0"));
     34        ellps = params.ellps;
     35        initialize(params.lat_0);
    3236    }
    3337
    34     public void updateParameters(double lat_0) {
     38    private void initialize(double lat_0) {
    3539        double phi0 = toRadians(lat_0);
    3640        kR = sqrt(1 - ellps.e2) / (1 - (ellps.e2 * pow(sin(phi0), 2)));
     
    4145            * log((1 + ellps.e * sin(phi0)) / (1 - ellps.e * sin(phi0)));
    4246    }
    43    
     47
    4448    @Override
    4549    public String getName() {
     
    9498        return new double[] { phi, lambda };
    9599    }
    96    
     100
    97101}
  • trunk/src/org/openstreetmap/josm/data/projection/proj/TransverseMercator.java

    r4285 r5066  
    77
    88import org.openstreetmap.josm.data.projection.Ellipsoid;
     9import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
    910
    1011/**
     
    1314 * @author Dirk Stöcker
    1415 * code based on JavaScript from Chuck Taylor
    15  * 
     16 *
    1617 */
    1718public class TransverseMercator implements Proj {
     
    1920    protected double a, b;
    2021
    21     public TransverseMercator(Ellipsoid ellps) {
    22         this.a = ellps.a;
    23         this.b = ellps.b;
    24     }
    25    
    2622    @Override
    2723    public String getName() {
     
    3228    public String getProj4Id() {
    3329        return "tmerc";
     30    }
     31
     32    @Override
     33    public void initialize(ProjParameters params) throws ProjectionConfigurationException {
     34        this.a = params.ellps.a;
     35        this.b = params.ellps.b;
    3436    }
    3537
     
    4143     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
    4244     * GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
    43      * 
     45     *
    4446     * @param phi Latitude of the point, in radians
    4547     * @param lambda Longitude of the point, in radians
     
    4951    @Override
    5052    public double[] project(double phi, double lambda) {
    51        
     53
    5254        /* Precalculate ep2 */
    5355        double ep2 = (pow(a, 2.0) - pow(b, 2.0)) / pow(b, 2.0);
     
    105107     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
    106108     *   GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
    107      * 
     109     *
    108110     * Remarks:
    109111     *   The local variables Nf, nuf2, tf, and tf2 serve the same purpose as
     
    113115     *   x1frac, x2frac, x2poly, x3poly, etc. are to enhance readability and
    114116     *   to optimize computations.
    115      * 
     117     *
    116118     * @param x The easting of the point, in meters, divided by the semi major axis of the ellipsoid
    117119     * @param y The northing of the point, in meters, divided by the semi major axis of the ellipsoid
     
    190192                        + x7frac * x7poly * pow(x, 7.0) };
    191193    }
    192    
     194
    193195    /**
    194196     * ArcLengthOfMeridian
     
    199201     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
    200202     * GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
    201      * 
     203     *
    202204     * @param phi Latitude of the point, in radians
    203205     * @return The ellipsoidal distance of the point from the equator
     
    234236                    + (epsilon * sin(8.0 * phi)));
    235237    }
    236        
     238
    237239    /**
    238240     * FootpointLatitude
     
    243245     * Reference: Hoffmann-Wellenhof, B., Lichtenegger, H., and Collins, J.,
    244246     *   GPS: Theory and Practice, 3rd ed.  New York: Springer-Verlag Wien, 1994.
    245      * 
     247     *
    246248     * @param y northing coordinate, in meters, divided by the semi major axis of the ellipsoid
    247249     * @return The footpoint latitude, in radians
     
    280282            + (epsilon_ * sin(8.0 * y_));
    281283    }
    282    
     284
    283285}
Note: See TracChangeset for help on using the changeset viewer.