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

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

Large rework in projection handling - now allows only switching and more specific projections
TODO:

  • allow subprojections (i.e. settings for projections)
  • setup preferences for subprojections
  • better support of the new projection depending world bounds (how to handle valid data outside of world)
  • do not allow to zoom out of the world - zoom should stop when whole world is displayed
  • fix Lambert and SwissGrid to handle new OutOfWorld style and subprojections
  • fix new UTM projection
  • handle layers with fixed projection on projection change
  • allow easier projection switching (e.g. in menu)

NOTE:
This checkin very likely will cause problems. Please report or fix them. Older plugins may have trouble. The SVN plugins
have been fixed but may have problems nevertheless. This is a BIG change, but will make JOSMs internal structure much cleaner
and reduce lots of projection related problems.

File size: 3.9 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 @Override
104 public boolean equals(Object o) {
105 return o instanceof SwissGrid;
106 }
107
108 public ProjectionBounds getWorldBounds()
109 {
110 Bounds b = getWorldBoundsLatLon();
111 return new ProjectionBounds(latlon2eastNorth(b.min), latlon2eastNorth(b.max));
112 }
113
114 public Bounds getWorldBoundsLatLon()
115 {
116 return new Bounds(
117 new LatLon(45.7, 5.7),
118 new LatLon(47.9, 10.6));
119 }
120}
Note: See TracBrowser for help on using the repository browser.