1 | //License: GPL. For details, see LICENSE file.
|
---|
2 | //Thanks to Johan Montagnat and its geoconv java converter application
|
---|
3 | //(http://www.i3s.unice.fr/~johan/gps/ , published under GPL license)
|
---|
4 | //from which some code and constants have been reused here.
|
---|
5 | package org.openstreetmap.josm.data.projection;
|
---|
6 |
|
---|
7 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
11 |
|
---|
12 | public class LambertEST implements Projection {
|
---|
13 |
|
---|
14 | public static final double ef = 500000; //Easting at false origin = 5000000 m
|
---|
15 | public static final double nf = 6375000; //Northing at false origin = 6375000 m
|
---|
16 | public static final double lat1 = Math.toRadians(59 + 1.0/3.0); //Latitude of 1st standard parallel = 59o20`0`` N
|
---|
17 | public static final double lat2 = Math.toRadians( 58);//Latitude of 2nd standard parallel = 58o0`0`` N
|
---|
18 | public static final double latf = Math.toRadians(57.517553930555555555555555555556);//'Latitude of false origin = 57o31`3,19415`` N
|
---|
19 | public static final double lonf = Math.toRadians( 24.0);
|
---|
20 | public static final double a = 6378137;
|
---|
21 | public static final double ee = 0.081819191042815792;
|
---|
22 | public static final double m1 = Math.cos(lat1) / (Math.sqrt(1 - ee *ee * Math.pow(Math.sin(lat1), 2)));
|
---|
23 | public static final double m2 = Math.cos(lat2) / (Math.sqrt(1 - ee *ee * Math.pow(Math.sin(lat2), 2)));
|
---|
24 | public static final double t1 = Math.tan(Math.PI / 4.0 - lat1 / 2.0)
|
---|
25 | / Math.pow(( (1.0 - ee * Math.sin(lat1)) / (1.0 + ee * Math.sin(lat1))) ,(ee / 2.0));
|
---|
26 | public static final double t2 = Math.tan(Math.PI / 4.0 - lat2 / 2.0)
|
---|
27 | / Math.pow(( (1.0 - ee * Math.sin(lat2)) / (1.0 + ee * Math.sin(lat2))) ,(ee / 2.0));
|
---|
28 | public static final double tf = Math.tan(Math.PI / 4.0 - latf / 2.0)
|
---|
29 | / Math.pow(( (1.0 - ee * Math.sin(latf)) / (1.0 + ee * Math.sin(latf))) ,(ee / 2.0));
|
---|
30 | public static final double n = (Math.log(m1) - Math.log(m2))
|
---|
31 | / (Math.log(t1) - Math.log(t2));
|
---|
32 | public static final double f = m1 / (n * Math.pow(t1, n));
|
---|
33 | public static final double rf = a * f * Math.pow(tf, n);
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * precision in iterative schema
|
---|
37 | */
|
---|
38 | public static final double epsilon = 1e-11;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * @param p WGS84 lat/lon (ellipsoid GRS80) (in degree)
|
---|
42 | * @return eastnorth projection in Lambert Zone (ellipsoid GRS80)
|
---|
43 | */
|
---|
44 | public EastNorth latlon2eastNorth(LatLon p)
|
---|
45 | {
|
---|
46 |
|
---|
47 | double t = Math.tan(Math.PI / 4.0 - Math.toRadians(p.lat()) / 2.0)
|
---|
48 | / Math.pow(( (1.0 - ee * Math.sin(Math.toRadians(p.lat()))) / (1.0
|
---|
49 | + ee * Math.sin(Math.toRadians(p.lat())))) ,(ee / 2.0));
|
---|
50 | double r = a * f * Math.pow(t, n);
|
---|
51 | double theta = n * (Math.toRadians(p.lon()) - lonf);
|
---|
52 |
|
---|
53 | double x = ef + r * Math.sin(theta); //587446.7
|
---|
54 | double y = nf + rf - r * Math.cos(theta); //6485401.6
|
---|
55 |
|
---|
56 | return new EastNorth(x,y);
|
---|
57 | }
|
---|
58 |
|
---|
59 | public static double IterateAngle(double e, double t)
|
---|
60 | {
|
---|
61 | double a1 = 0.0;
|
---|
62 | double a2 = 3.1415926535897931;
|
---|
63 | double a = 1.5707963267948966;
|
---|
64 | double b = 1.5707963267948966 - (2.0 * Math.atan(t * Math.pow((1.0
|
---|
65 | - (e * Math.sin(a))) / (1.0 + (e * Math.sin(a))), e / 2.0)));
|
---|
66 | while (Math.abs(a-b) > epsilon)
|
---|
67 | {
|
---|
68 | a = a1 + ((a2 - a1) / 2.0);
|
---|
69 | b = 1.5707963267948966 - (2.0 * Math.atan(t * Math.pow((1.0
|
---|
70 | - (e * Math.sin(a))) / (1.0 + (e * Math.sin(a))), e / 2.0)));
|
---|
71 | if (a1 == a2)
|
---|
72 | {
|
---|
73 | return 0.0;
|
---|
74 | }
|
---|
75 | if (b > a)
|
---|
76 | a1 = a;
|
---|
77 | else
|
---|
78 | a2 = a;
|
---|
79 | }
|
---|
80 | return b;
|
---|
81 | }
|
---|
82 |
|
---|
83 | public LatLon eastNorth2latlon(EastNorth p)
|
---|
84 | {
|
---|
85 | double r = Math.sqrt(Math.pow((p.getX() - ef), 2.0) + Math.pow((rf
|
---|
86 | - p.getY() + nf), 2.0) ) * Math.signum(n);
|
---|
87 | double T = Math.pow((r / (a * f)), (1.0/ n)) ;
|
---|
88 | double theta = Math.atan((p.getX() - ef) / (rf - p.getY() + nf));
|
---|
89 | double y = (theta / n + lonf) ;
|
---|
90 | double x = (IterateAngle(ee, T)) ;
|
---|
91 | return new LatLon(Math.toDegrees(x),Math.toDegrees(y));
|
---|
92 | }
|
---|
93 |
|
---|
94 | @Override
|
---|
95 | public String toString() {
|
---|
96 | return tr("Lambert Zone (Estonia)");
|
---|
97 | }
|
---|
98 |
|
---|
99 | public String toCode() {
|
---|
100 | return "EPSG:3301";
|
---|
101 | }
|
---|
102 |
|
---|
103 | public String getCacheDirectoryName() {
|
---|
104 | return "lambertest";
|
---|
105 | }
|
---|
106 |
|
---|
107 | public double scaleFactor() {
|
---|
108 | return 1.0 / 360;
|
---|
109 | }
|
---|
110 |
|
---|
111 | @Override
|
---|
112 | public boolean equals(Object o) {
|
---|
113 | return o instanceof LambertEST;
|
---|
114 | }
|
---|
115 |
|
---|
116 | @Override
|
---|
117 | public int hashCode() {
|
---|
118 | return LambertEST.class.hashCode();
|
---|
119 | }
|
---|
120 | }
|
---|