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

Last change on this file since 2272 was 2114, checked in by stoecker, 15 years ago

see #3016 - patch by xeen - fixes some zooming issues

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