source: josm/trunk/src/org/openstreetmap/josm/data/projection/SwissGrid.java@ 1887

Last change on this file since 1887 was 1823, checked in by stoecker, 15 years ago

some projection and zoom cleanups - projection classes still need better handling of outside-world coordinates

File size: 3.6 KB
Line 
1//License: GPL. For details, see LICENSE file.
2
3package org.openstreetmap.josm.data.projection;
4
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import org.openstreetmap.josm.Main;
8import org.openstreetmap.josm.data.coor.EastNorth;
9import org.openstreetmap.josm.data.coor.LatLon;
10import org.openstreetmap.josm.data.Bounds;
11import org.openstreetmap.josm.data.ProjectionBounds;
12
13/**
14 * Projection for the SwissGrid, see http://de.wikipedia.org/wiki/Swiss_Grid.
15 *
16 * Calculations are based on formula from
17 * http://www.swisstopo.admin.ch/internet/swisstopo/en/home/topics/survey/sys/refsys/switzerland.parsysrelated1.37696.downloadList.12749.DownloadFile.tmp/ch1903wgs84en.pdf
18 *
19 */
20public class SwissGrid implements Projection {
21 /**
22 * @param wgs WGS84 lat/lon (ellipsoid GRS80) (in degree)
23 * @return eastnorth projection in Swiss National Grid (ellipsoid Bessel)
24 */
25 public EastNorth latlon2eastNorth(LatLon wgs) {
26 double phi = 3600d * wgs.lat();
27 double lambda = 3600d * wgs.lon();
28
29 double phiprime = (phi - 169028.66d) / 10000d;
30 double lambdaprime = (lambda - 26782.5d) / 10000d;
31
32 // precompute squares for lambdaprime and phiprime
33 //
34 double lambdaprime_2 = Math.pow(lambdaprime,2);
35 double phiprime_2 = Math.pow(phiprime,2);
36
37
38 double north =
39 200147.07d
40 + 308807.95d * phiprime
41 + 3745.25d * lambdaprime_2
42 + 76.63d * phiprime_2
43 - 194.56d * lambdaprime_2 * phiprime
44 + 119.79d * Math.pow(phiprime,3);
45
46
47 double east =
48 600072.37d
49 + 211455.93d * lambdaprime
50 - 10938.51d * lambdaprime * phiprime
51 - 0.36d * lambdaprime * phiprime_2
52 - 44.54d * Math.pow(lambdaprime,3);
53
54 return new EastNorth(east, north);
55 }
56
57 /**
58 * @param xy SwissGrid east/north (in meters)
59 * @return LatLon WGS84 (in degree)
60 */
61
62 public LatLon eastNorth2latlon(EastNorth xy) {
63 double yp = (xy.east() - 600000d) / 1000000d;
64 double xp = (xy.north() - 200000d) / 1000000d;
65
66 // precompute squares of xp and yp
67 //
68 double xp_2 = Math.pow(xp,2);
69 double yp_2 = Math.pow(yp,2);
70
71 // lambda = latitude, phi = longitude
72 double lmbp = 2.6779094d
73 + 4.728982d * yp
74 + 0.791484d * yp * xp
75 + 0.1306d * yp * xp_2
76 - 0.0436d * Math.pow(yp,3);
77
78 double phip = 16.9023892d
79 + 3.238272d * xp
80 - 0.270978d * yp_2
81 - 0.002528d * xp_2
82 - 0.0447d * yp_2 * xp
83 - 0.0140d * Math.pow(xp,3);
84
85 double lmb = lmbp * 100.0d / 36.0d;
86 double phi = phip * 100.0d / 36.0d;
87
88 return new LatLon(phi,lmb);
89 }
90
91 @Override public String toString() {
92 return tr("Swiss Grid (Switzerland)");
93 }
94
95 public String toCode() {
96 return "EPSG:21781";
97 }
98
99 public String getCacheDirectoryName() {
100 return "swissgrid";
101 }
102
103 public Bounds getWorldBoundsLatLon()
104 {
105 return new Bounds(
106 new LatLon(45.7, 5.7),
107 new LatLon(47.9, 10.6));
108 }
109}
Note: See TracBrowser for help on using the repository browser.