source: josm/trunk/src/org/openstreetmap/josm/data/projection/Puwg.java@ 5028

Last change on this file since 5028 was 4285, checked in by bastiK, 13 years ago

major projection rework

More modular structure, inspired by Proj.4.

There are almost no semantic changes to the projection algorithms. Mostly factors of 'a' and 180/PI have been moved from one place to the other. In UTM_France_DOM, the ellipsoid conversion for the first 3 projections has been changed from hayford <-> GRS80 to hayford <-> WGS84.

Some redundant algorithms have been removed. In particular:

  • UTM_France_DOM used to have its own Transverse Mercator implementation. It is different from the implementation in TransverseMercator.java as it has another series expansion. For EPSG::2975, there are numeric differences on centimeter scale. However, the new data fits better with Proj.4 output.
  • Also removed are alternate implementations of LambertConformalConic. (They are all quite similar, though.)
  • Property svn:eol-style set to native
File size: 7.9 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2// 2009 by Łukasz Stelmach
3package org.openstreetmap.josm.data.projection;
4
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.GridBagLayout;
8import java.awt.event.ActionListener;
9import java.util.Collection;
10import java.util.Collections;
11
12import javax.swing.JComboBox;
13import javax.swing.JLabel;
14import javax.swing.JPanel;
15
16import org.openstreetmap.josm.data.Bounds;
17import org.openstreetmap.josm.data.coor.LatLon;
18import org.openstreetmap.josm.data.projection.datum.GRS80Datum;
19import org.openstreetmap.josm.tools.GBC;
20
21/**
22 * PUWG 1992 and 2000 are the official cordinate systems in Poland.
23 * They use the same math as UTM only with different constants.
24 *
25 * @author steelman
26 */
27public class Puwg extends AbstractProjection implements ProjectionSubPrefs {
28
29 public static final int DEFAULT_ZONE = 0;
30
31 private int zone;
32
33 static PuwgData[] Zones = new PuwgData[] {
34 new Epsg2180(),
35 new Epsg2176(),
36 new Epsg2177(),
37 new Epsg2178(),
38 new Epsg2179()
39 };
40
41 public Puwg() {
42 this(DEFAULT_ZONE);
43 }
44
45 public Puwg(int zone) {
46 ellps = Ellipsoid.GRS80;
47 proj = new org.openstreetmap.josm.data.projection.proj.TransverseMercator(ellps);
48 datum = GRS80Datum.INSTANCE;
49 updateParameters(zone);
50 }
51
52 public void updateParameters(int zone) {
53 this.zone = zone;
54 PuwgData z = Zones[zone];
55 x_0 = z.getPuwgFalseEasting();
56 y_0 = z.getPuwgFalseNorthing();
57 lon_0 = z.getPuwgCentralMeridianDeg();
58 k_0 = z.getPuwgScaleFactor();
59 }
60
61 @Override
62 public String toString() {
63 return tr("PUWG (Poland)");
64 }
65
66 @Override
67 public Integer getEpsgCode() {
68 return Zones[zone].getEpsgCode();
69 }
70
71 @Override
72 public int hashCode() {
73 return getClass().getName().hashCode()+zone; // our only real variable
74 }
75
76 @Override
77 public String getCacheDirectoryName() {
78 return Zones[zone].getCacheDirectoryName();
79 }
80
81 @Override
82 public Bounds getWorldBoundsLatLon() {
83 return Zones[zone].getWorldBoundsLatLon();
84 }
85
86 @Override
87 public void setupPreferencePanel(JPanel p, ActionListener listener) {
88 JComboBox prefcb = new JComboBox(Puwg.Zones);
89
90 prefcb.setSelectedIndex(zone);
91 p.setLayout(new GridBagLayout());
92 p.add(new JLabel(tr("PUWG Zone")), GBC.std().insets(5,5,0,5));
93 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
94 /* Note: we use component position 2 below to find this again */
95 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
96 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
97
98 if (listener != null) {
99 prefcb.addActionListener(listener);
100 }
101 }
102
103 @Override
104 public Collection<String> getPreferences(JPanel p) {
105 Object prefcb = p.getComponent(2);
106 if(!(prefcb instanceof JComboBox))
107 return null;
108 int zone = ((JComboBox)prefcb).getSelectedIndex();
109 return Collections.singleton((Puwg.Zones[zone]).toCode());
110 }
111
112 @Override
113 public String[] allCodes() {
114 String[] zones = new String[Zones.length];
115 for (int zone = 0; zone < Zones.length; zone++) {
116 zones[zone] = Zones[zone].toCode();
117 }
118 return zones;
119 }
120
121 @Override
122 public Collection<String> getPreferencesFromCode(String code) {
123 for (PuwgData p : Puwg.Zones) {
124 if (code.equals(p.toCode()))
125 return Collections.singleton(code);
126 }
127 return null;
128 }
129
130 @Override
131 public void setPreferences(Collection<String> args) {
132 int z = DEFAULT_ZONE;
133 if (args != null) {
134 try {
135 for (String s : args) {
136 for (int i=0; i < Zones.length; ++i)
137 if (s.equals(Zones[i].toCode())) {
138 z = i;
139 break;
140 }
141 break;
142 }
143 } catch (NullPointerException e) {}
144 }
145 updateParameters(z);
146 }
147}
148
149interface PuwgData {
150 double getPuwgCentralMeridianDeg();
151 double getPuwgCentralMeridian();
152 double getPuwgFalseEasting();
153 double getPuwgFalseNorthing();
154 double getPuwgScaleFactor();
155
156 // Projection methods
157 Integer getEpsgCode();
158 String toCode();
159 String getCacheDirectoryName();
160 Bounds getWorldBoundsLatLon();
161}
162
163class Epsg2180 implements PuwgData {
164
165 private static final double Epsg2180FalseEasting = 500000.0; /* y */
166 private static final double Epsg2180FalseNorthing = -5300000.0; /* x */
167 private static final double Epsg2180ScaleFactor = 0.9993;
168 private static final double Epsg2180CentralMeridian = 19.0;
169
170 @Override public String toString() {
171 return tr("PUWG 1992 (Poland)");
172 }
173
174 @Override
175 public Integer getEpsgCode() {
176 return 2180;
177 }
178
179 @Override
180 public String toCode() {
181 return "EPSG:" + getEpsgCode();
182 }
183
184 @Override
185 public String getCacheDirectoryName() {
186 return "epsg2180";
187 }
188
189 @Override
190 public Bounds getWorldBoundsLatLon()
191 {
192 return new Bounds(
193 new LatLon(49.00, 14.12),
194 new LatLon(54.84, 24.15));
195 }
196
197 @Override public double getPuwgCentralMeridianDeg() { return Epsg2180CentralMeridian; }
198 @Override public double getPuwgCentralMeridian() { return Math.toRadians(Epsg2180CentralMeridian); }
199 @Override public double getPuwgFalseEasting() { return Epsg2180FalseEasting; }
200 @Override public double getPuwgFalseNorthing() { return Epsg2180FalseNorthing; }
201 @Override public double getPuwgScaleFactor() { return Epsg2180ScaleFactor; }
202}
203
204abstract class Puwg2000 implements PuwgData {
205
206 private static final double PuwgFalseEasting = 500000.0;
207 private static final double PuwgFalseNorthing = 0;
208 private static final double PuwgScaleFactor = 0.999923;
209 //final private double[] Puwg2000CentralMeridian = {15.0, 18.0, 21.0, 24.0};
210 final private Integer[] Puwg2000Code = { 2176, 2177, 2178, 2179 };
211 final private String[] Puwg2000CDName = { "epsg2176", "epsg2177", "epsg2178", "epsg2179" };
212
213 @Override public String toString() {
214 return tr("PUWG 2000 Zone {0} (Poland)", Integer.toString(getZone()));
215 }
216
217 @Override
218 public Integer getEpsgCode() {
219 return Puwg2000Code[getZoneIndex()];
220 }
221
222 @Override
223 public String toCode() {
224 return "EPSG:" + getEpsgCode();
225 }
226
227 @Override
228 public String getCacheDirectoryName() {
229 return Puwg2000CDName[getZoneIndex()];
230 }
231
232 @Override
233 public Bounds getWorldBoundsLatLon()
234 {
235 return new Bounds(
236 new LatLon(49.00, (3 * getZone()) - 1.5),
237 new LatLon(54.84, (3 * getZone()) + 1.5));
238 }
239
240 @Override public double getPuwgCentralMeridianDeg() { return getZone() * 3.0; }
241 @Override public double getPuwgCentralMeridian() { return Math.toRadians(getZone() * 3.0); }
242 @Override public double getPuwgFalseNorthing() { return PuwgFalseNorthing;}
243 @Override public double getPuwgFalseEasting() { return 1e6 * getZone() + PuwgFalseEasting; }
244 @Override public double getPuwgScaleFactor() { return PuwgScaleFactor; }
245 public abstract int getZone();
246
247 public int getZoneIndex() { return getZone() - 5; }
248
249}
250
251class Epsg2176 extends Puwg2000 {
252 private static final int PuwgZone = 5;
253
254 @Override
255 public int getZone() { return PuwgZone; }
256}
257
258class Epsg2177 extends Puwg2000 {
259 private static final int PuwgZone = 6;
260
261 @Override
262 public int getZone() { return PuwgZone; }
263}
264
265class Epsg2178 extends Puwg2000 {
266 private static final int PuwgZone = 7;
267
268 @Override
269 public int getZone() { return PuwgZone; }
270}
271
272class Epsg2179 extends Puwg2000 {
273 private static final int PuwgZone = 8;
274
275 @Override
276 public int getZone() { return PuwgZone; }
277}
Note: See TracBrowser for help on using the repository browser.