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

Last change on this file since 4153 was 3779, checked in by Upliner, 13 years ago

Identify projections in offset bookmarks by EPSG codes, bugfixes in getPreferencesFromCode() functions as they're critical now.

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