[4285] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.projection.proj;
|
---|
| 3 |
|
---|
[6362] | 4 | import static java.lang.Math.PI;
|
---|
| 5 | import static java.lang.Math.abs;
|
---|
| 6 | import static java.lang.Math.atan;
|
---|
| 7 | import static java.lang.Math.cos;
|
---|
| 8 | import static java.lang.Math.exp;
|
---|
| 9 | import static java.lang.Math.log;
|
---|
| 10 | import static java.lang.Math.pow;
|
---|
| 11 | import static java.lang.Math.sin;
|
---|
| 12 | import static java.lang.Math.sqrt;
|
---|
| 13 | import static java.lang.Math.tan;
|
---|
| 14 | import static java.lang.Math.toRadians;
|
---|
[4285] | 15 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 16 |
|
---|
[8346] | 17 | import org.openstreetmap.josm.data.projection.CustomProjection.Param;
|
---|
[4285] | 18 | import org.openstreetmap.josm.data.projection.Ellipsoid;
|
---|
[5066] | 19 | import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
|
---|
[4285] | 20 |
|
---|
| 21 | /**
|
---|
| 22 | * Implementation of the Lambert Conformal Conic projection.
|
---|
| 23 | *
|
---|
| 24 | * @author Pieren
|
---|
| 25 | */
|
---|
| 26 | public class LambertConformalConic implements Proj {
|
---|
[5066] | 27 |
|
---|
[4285] | 28 | protected Ellipsoid ellps;
|
---|
| 29 | protected double e;
|
---|
[5066] | 30 |
|
---|
[6883] | 31 | public abstract static class Parameters {
|
---|
[5040] | 32 | public final double latitudeOrigin;
|
---|
| 33 | public Parameters(double latitudeOrigin) {
|
---|
| 34 | this.latitudeOrigin = latitudeOrigin;
|
---|
| 35 | }
|
---|
[6142] | 36 | }
|
---|
[5066] | 37 |
|
---|
[5040] | 38 | public static class Parameters1SP extends Parameters {
|
---|
| 39 | public Parameters1SP(double latitudeOrigin) {
|
---|
| 40 | super(latitudeOrigin);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
[4285] | 43 |
|
---|
[5040] | 44 | public static class Parameters2SP extends Parameters {
|
---|
| 45 | public final double standardParallel1;
|
---|
| 46 | public final double standardParallel2;
|
---|
| 47 | public Parameters2SP(double latitudeOrigin, double standardParallel1, double standardParallel2) {
|
---|
| 48 | super(latitudeOrigin);
|
---|
| 49 | this.standardParallel1 = standardParallel1;
|
---|
| 50 | this.standardParallel2 = standardParallel2;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | private Parameters params;
|
---|
[5066] | 55 |
|
---|
[4285] | 56 | /**
|
---|
| 57 | * projection exponent
|
---|
| 58 | */
|
---|
| 59 | protected double n;
|
---|
| 60 | /**
|
---|
| 61 | * projection factor
|
---|
| 62 | */
|
---|
[8346] | 63 | protected double f;
|
---|
[4285] | 64 | /**
|
---|
[5066] | 65 | * radius of the parallel of latitude of the false origin (2SP) or at
|
---|
[4285] | 66 | * natural origin (1SP)
|
---|
| 67 | */
|
---|
[5066] | 68 | protected double r0;
|
---|
| 69 |
|
---|
[4285] | 70 | /**
|
---|
| 71 | * precision in iterative schema
|
---|
| 72 | */
|
---|
| 73 | protected static final double epsilon = 1e-12;
|
---|
| 74 |
|
---|
[5066] | 75 | @Override
|
---|
| 76 | public void initialize(ProjParameters params) throws ProjectionConfigurationException {
|
---|
| 77 | ellps = params.ellps;
|
---|
| 78 | e = ellps.e;
|
---|
[8346] | 79 | if (params.lat0 == null)
|
---|
| 80 | throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", Param.lat_0.key));
|
---|
| 81 | if (params.lat1 != null && params.lat2 != null) {
|
---|
| 82 | initialize2SP(params.lat0, params.lat1, params.lat2);
|
---|
[5066] | 83 | } else {
|
---|
[8346] | 84 | initialize1SP(params.lat0);
|
---|
[5066] | 85 | }
|
---|
[4285] | 86 | }
|
---|
| 87 |
|
---|
| 88 | /**
|
---|
| 89 | * Initialize for LCC with 2 standard parallels.
|
---|
[5066] | 90 | *
|
---|
[4285] | 91 | * @param lat_0 latitude of false origin (in degrees)
|
---|
| 92 | * @param lat_1 latitude of first standard parallel (in degrees)
|
---|
| 93 | * @param lat_2 latitude of second standard parallel (in degrees)
|
---|
| 94 | */
|
---|
[5066] | 95 | private void initialize2SP(double lat_0, double lat_1, double lat_2) {
|
---|
[5040] | 96 | this.params = new Parameters2SP(lat_0, lat_1, lat_2);
|
---|
[5066] | 97 |
|
---|
[4285] | 98 | final double m1 = m(toRadians(lat_1));
|
---|
| 99 | final double m2 = m(toRadians(lat_2));
|
---|
[5066] | 100 |
|
---|
[4285] | 101 | final double t1 = t(toRadians(lat_1));
|
---|
| 102 | final double t2 = t(toRadians(lat_2));
|
---|
| 103 | final double tf = t(toRadians(lat_0));
|
---|
[5066] | 104 |
|
---|
[4285] | 105 | n = (log(m1) - log(m2)) / (log(t1) - log(t2));
|
---|
[8346] | 106 | f = m1 / (n * pow(t1, n));
|
---|
| 107 | r0 = f * pow(tf, n);
|
---|
[4285] | 108 | }
|
---|
[5066] | 109 |
|
---|
[4285] | 110 | /**
|
---|
| 111 | * Initialize for LCC with 1 standard parallel.
|
---|
[5066] | 112 | *
|
---|
[4285] | 113 | * @param lat_0 latitude of natural origin (in degrees)
|
---|
| 114 | */
|
---|
[5066] | 115 | private void initialize1SP(double lat_0) {
|
---|
[5040] | 116 | this.params = new Parameters1SP(lat_0);
|
---|
[4285] | 117 | final double lat_0_rad = toRadians(lat_0);
|
---|
[5066] | 118 |
|
---|
[4285] | 119 | final double m0 = m(lat_0_rad);
|
---|
| 120 | final double t0 = t(lat_0_rad);
|
---|
[5066] | 121 |
|
---|
[4285] | 122 | n = sin(lat_0_rad);
|
---|
[8346] | 123 | f = m0 / (n * pow(t0, n));
|
---|
| 124 | r0 = f * pow(t0, n);
|
---|
[4285] | 125 | }
|
---|
| 126 |
|
---|
| 127 | /**
|
---|
| 128 | * auxiliary function t
|
---|
| 129 | */
|
---|
| 130 | protected double t(double lat_rad) {
|
---|
| 131 | return tan(PI/4 - lat_rad / 2.0)
|
---|
[8345] | 132 | / pow((1.0 - e * sin(lat_rad)) / (1.0 + e * sin(lat_rad)), e/2);
|
---|
[4285] | 133 | }
|
---|
| 134 |
|
---|
| 135 | /**
|
---|
| 136 | * auxiliary function m
|
---|
| 137 | */
|
---|
| 138 | protected double m(double lat_rad) {
|
---|
| 139 | return cos(lat_rad) / (sqrt(1 - e * e * pow(sin(lat_rad), 2)));
|
---|
| 140 | }
|
---|
[5066] | 141 |
|
---|
[4285] | 142 | @Override
|
---|
| 143 | public String getName() {
|
---|
| 144 | return tr("Lambert Conformal Conic");
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | @Override
|
---|
| 148 | public String getProj4Id() {
|
---|
| 149 | return "lcc";
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | @Override
|
---|
| 153 | public double[] project(double phi, double lambda) {
|
---|
| 154 | double sinphi = sin(phi);
|
---|
| 155 | double L = (0.5*log((1+sinphi)/(1-sinphi))) - e/2*log((1+e*sinphi)/(1-e*sinphi));
|
---|
[8346] | 156 | double r = f*exp(-n*L);
|
---|
[4285] | 157 | double gamma = n*lambda;
|
---|
| 158 | double X = r*sin(gamma);
|
---|
| 159 | double Y = r0 - r*cos(gamma);
|
---|
| 160 | return new double[] { X, Y };
|
---|
| 161 | }
|
---|
[5066] | 162 |
|
---|
[4285] | 163 | @Override
|
---|
| 164 | public double[] invproject(double east, double north) {
|
---|
| 165 | double r = sqrt(pow(east,2) + pow(north-r0, 2));
|
---|
| 166 | double gamma = atan(east / (r0-north));
|
---|
| 167 | double lambda = gamma/n;
|
---|
[8346] | 168 | double latIso = (-1/n) * log(abs(r/f));
|
---|
[4285] | 169 | double phi = ellps.latitude(latIso, e, epsilon);
|
---|
| 170 | return new double[] { phi, lambda };
|
---|
| 171 | }
|
---|
[5066] | 172 |
|
---|
[5040] | 173 | public final Parameters getParameters() {
|
---|
| 174 | return params;
|
---|
| 175 | }
|
---|
[4285] | 176 | }
|
---|