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

Last change on this file since 3083 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 3.8 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 double north =
36 200147.07d
37 + 308807.95d * phiprime
38 + 3745.25d * lambdaprime_2
39 + 76.63d * phiprime_2
40 - 194.56d * lambdaprime_2 * phiprime
41 + 119.79d * Math.pow(phiprime,3);
42
43 double east =
44 600072.37d
45 + 211455.93d * lambdaprime
46 - 10938.51d * lambdaprime * phiprime
47 - 0.36d * lambdaprime * phiprime_2
48 - 44.54d * Math.pow(lambdaprime,3);
49
50 return new EastNorth(east, north);
51 }
52
53 /**
54 * @param xy SwissGrid east/north (in meters)
55 * @return LatLon WGS84 (in degree)
56 */
57
58 public LatLon eastNorth2latlon(EastNorth xy) {
59 double yp = (xy.east() - 600000d) / 1000000d;
60 double xp = (xy.north() - 200000d) / 1000000d;
61
62 // precompute squares of xp and yp
63 //
64 double xp_2 = Math.pow(xp,2);
65 double yp_2 = Math.pow(yp,2);
66
67 // lambda = latitude, phi = longitude
68 double lmbp = 2.6779094d
69 + 4.728982d * yp
70 + 0.791484d * yp * xp
71 + 0.1306d * yp * xp_2
72 - 0.0436d * Math.pow(yp,3);
73
74 double phip = 16.9023892d
75 + 3.238272d * xp
76 - 0.270978d * yp_2
77 - 0.002528d * xp_2
78 - 0.0447d * yp_2 * xp
79 - 0.0140d * Math.pow(xp,3);
80
81 double lmb = lmbp * 100.0d / 36.0d;
82 double phi = phip * 100.0d / 36.0d;
83
84 return new LatLon(phi,lmb);
85 }
86
87 @Override public String toString() {
88 return tr("Swiss Grid (Switzerland)");
89 }
90
91 public String toCode() {
92 return "EPSG:21781";
93 }
94
95 @Override
96 public int hashCode() {
97 return getClass().getName().hashCode(); // we have no variables
98 }
99
100 public String getCacheDirectoryName() {
101 return "swissgrid";
102 }
103
104 public Bounds getWorldBoundsLatLon()
105 {
106 return new Bounds(
107 new LatLon(45.7, 5.7),
108 new LatLon(47.9, 10.6));
109 }
110
111 public double getDefaultZoomInPPD() {
112 // This will set the scale bar to about 100 m
113 return 1.01;
114 }
115}
Note: See TracBrowser for help on using the repository browser.