source: josm/trunk/src/org/openstreetmap/josm/data/projection/LambertEST.java@ 4153

Last change on this file since 4153 was 3676, checked in by stoecker, 13 years ago

apply #5664 - patch by verbatium - Fix Lambert EST

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
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.
5package org.openstreetmap.josm.data.projection;
6
7import static org.openstreetmap.josm.tools.I18n.tr;
8
9import org.openstreetmap.josm.data.Bounds;
10import org.openstreetmap.josm.data.coor.EastNorth;
11import org.openstreetmap.josm.data.coor.LatLon;
12
13public class LambertEST implements Projection {
14
15 public static final double ef = 500000; //Easting at false origin = 5000000 m
16 public static final double nf = 6375000; //Northing at false origin = 6375000 m
17 public static final double lat1 = Math.toRadians(59 + 1.0/3.0); //Latitude of 1st standard parallel = 59o20`0`` N
18 public static final double lat2 = Math.toRadians( 58);//Latitude of 2nd standard parallel = 58o0`0`` N
19 public static final double latf = Math.toRadians(57.517553930555555555555555555556);//'Latitude of false origin = 57o31`3,19415`` N
20 public static final double lonf = Math.toRadians( 24.0);
21 public static final double a = 6378137;
22 public static final double ee = 0.081819191042815792;
23 public static final double m1 = Math.cos(lat1) / (Math.sqrt(1 - ee *ee * Math.pow(Math.sin(lat1), 2)));
24 public static final double m2 = Math.cos(lat2) / (Math.sqrt(1 - ee *ee * Math.pow(Math.sin(lat2), 2)));
25 public static final double t1 = Math.tan(Math.PI / 4.0 - lat1 / 2.0)
26 / Math.pow(( (1.0 - ee * Math.sin(lat1)) / (1.0 + ee * Math.sin(lat1))) ,(ee / 2.0));
27 public static final double t2 = Math.tan(Math.PI / 4.0 - lat2 / 2.0)
28 / Math.pow(( (1.0 - ee * Math.sin(lat2)) / (1.0 + ee * Math.sin(lat2))) ,(ee / 2.0));
29 public static final double tf = Math.tan(Math.PI / 4.0 - latf / 2.0)
30 / Math.pow(( (1.0 - ee * Math.sin(latf)) / (1.0 + ee * Math.sin(latf))) ,(ee / 2.0));
31 public static final double n = (Math.log(m1) - Math.log(m2))
32 / (Math.log(t1) - Math.log(t2));
33 public static final double f = m1 / (n * Math.pow(t1, n));
34 public static final double rf = a * f * Math.pow(tf, n);
35
36 /**
37 * precision in iterative schema
38 */
39 public static final double epsilon = 1e-11;
40
41 /**
42 * @param p WGS84 lat/lon (ellipsoid GRS80) (in degree)
43 * @return eastnorth projection in Lambert Zone (ellipsoid GRS80)
44 */
45 public EastNorth latlon2eastNorth(LatLon p)
46 {
47
48 double t = Math.tan(Math.PI / 4.0 - Math.toRadians(p.lat()) / 2.0)
49 / Math.pow(( (1.0 - ee * Math.sin(Math.toRadians(p.lat()))) / (1.0
50 + ee * Math.sin(Math.toRadians(p.lat())))) ,(ee / 2.0));
51 double r = a * f * Math.pow(t, n);
52 double theta = n * (Math.toRadians(p.lon()) - lonf);
53
54 double x = ef + r * Math.sin(theta); //587446.7
55 double y = nf + rf - r * Math.cos(theta); //6485401.6
56
57 return new EastNorth(x,y);
58 }
59
60 public static double iterateAngle(double e, double t)
61 {
62 double a1 = 0.0;
63 double a2 = 3.1415926535897931;
64 double a = 1.5707963267948966;
65 double b = 1.5707963267948966 - (2.0 * Math.atan(t * Math.pow((1.0
66 - (e * Math.sin(a))) / (1.0 + (e * Math.sin(a))), e / 2.0)));
67 while (Math.abs(a-b) > epsilon)
68 {
69 a = a1 + ((a2 - a1) / 2.0);
70 b = 1.5707963267948966 - (2.0 * Math.atan(t * Math.pow((1.0
71 - (e * Math.sin(a))) / (1.0 + (e * Math.sin(a))), e / 2.0)));
72 if (a1 == a2)
73 return 0.0;
74 if (b > a) {
75 a1 = a;
76 } else {
77 a2 = a;
78 }
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 @Override
104 public int hashCode() {
105 return getClass().getName().hashCode(); // we have no variables
106 }
107
108 public String getCacheDirectoryName() {
109 return "lambertest";
110 }
111
112 public Bounds getWorldBoundsLatLon()
113 {
114 return new Bounds(
115 new LatLon(56.05, 21.64),
116 new LatLon(61.13, 28.58));
117 }
118
119 public double getDefaultZoomInPPD() {
120 return 10;
121 }
122}
Note: See TracBrowser for help on using the repository browser.