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

Proj parameter refactoring (see #7495)

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.