source: josm/trunk/src/org/openstreetmap/josm/data/projection/GaussKrueger.java@ 5230

Last change on this file since 5230 was 5226, checked in by bastiK, 12 years ago

improvements for custom projection

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.awt.event.ActionListener;
8import java.util.Collection;
9import java.util.Collections;
10
11import javax.swing.JComboBox;
12import javax.swing.JLabel;
13import javax.swing.JPanel;
14
15import org.openstreetmap.josm.data.Bounds;
16import org.openstreetmap.josm.data.coor.LatLon;
17import org.openstreetmap.josm.data.projection.datum.NTV2Datum;
18import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper;
19import org.openstreetmap.josm.data.projection.proj.ProjParameters;
20import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
21import org.openstreetmap.josm.tools.GBC;
22
23public class GaussKrueger extends AbstractProjection implements ProjectionSubPrefs {
24
25 public static final int DEFAULT_ZONE = 2;
26 private int zone;
27
28 private static Bounds[] bounds = {
29 new Bounds(new LatLon(-5, 3.5), new LatLon(85, 8.5)),
30 new Bounds(new LatLon(-5, 6.5), new LatLon(85, 11.5)),
31 new Bounds(new LatLon(-5, 9.5), new LatLon(85, 14.5)),
32 new Bounds(new LatLon(-5, 12.5), new LatLon(85, 17.5)),
33 };
34
35 private static String[] zones = { "2", "3", "4", "5" };
36
37 public GaussKrueger() {
38 this(DEFAULT_ZONE);
39 }
40
41 public GaussKrueger(int zone) {
42 updateParameters(zone);
43 }
44
45 private void updateParameters(int zone) {
46 this.zone = zone;
47 ellps = Ellipsoid.Bessel1841;
48 datum = new NTV2Datum("BETA2007", null, ellps, NTV2GridShiftFileWrapper.BETA2007);
49 ////less acurrate datum (errors up to 3m):
50 //datum = new SevenParameterDatum(
51 // tr("Deutsches Hauptdreiecksnetz"), null, ellps,
52 // 598.1, 73.7, 418.2, 0.202, 0.045, -2.455, 6.70);
53 proj = new TransverseMercator();
54 try {
55 proj.initialize(new ProjParameters() {{ ellps = GaussKrueger.this.ellps; }});
56 } catch (ProjectionConfigurationException e) {
57 throw new RuntimeException(e);
58 }
59 x_0 = 1000000 * zone + 500000;
60 lon_0 = 3 * zone;
61 }
62
63 @Override
64 public String toString() {
65 return tr("Gau\u00DF-Kr\u00FCger");
66 }
67
68 @Override
69 public Integer getEpsgCode() {
70 return 31464 + zone;
71 }
72
73 @Override
74 public String getCacheDirectoryName() {
75 return "gausskrueger"+zone;
76 }
77
78 @Override
79 public Bounds getWorldBoundsLatLon() {
80 return bounds[zone-2];
81 }
82
83 @Override
84 public void setupPreferencePanel(JPanel p, ActionListener listener) {
85 JComboBox prefcb = new JComboBox(zones);
86
87 prefcb.setSelectedIndex(zone-2);
88 p.setLayout(new GridBagLayout());
89 p.add(new JLabel(tr("GK Zone")), GBC.std().insets(5,5,0,5));
90 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
91 /* Note: we use component position 2 below to find this again */
92 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
93 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
94
95 if (listener != null) {
96 prefcb.addActionListener(listener);
97 }
98 }
99
100 @Override
101 public Collection<String> getPreferences(JPanel p) {
102 Object prefcb = p.getComponent(2);
103 if(!(prefcb instanceof JComboBox))
104 return null;
105 int zone = ((JComboBox)prefcb).getSelectedIndex();
106 return Collections.singleton(Integer.toString(zone+2));
107 }
108
109 @Override
110 public void setPreferences(Collection<String> args) {
111 int zone = DEFAULT_ZONE;
112 if (args != null) {
113 try {
114 for(String s : args)
115 {
116 zone = Integer.parseInt(s);
117 if(zone < 2 || zone > 5) {
118 zone = DEFAULT_ZONE;
119 }
120 break;
121 }
122 } catch(NumberFormatException e) {}
123 }
124 updateParameters(zone);
125 }
126
127 @Override
128 public String[] allCodes() {
129 String[] zones = new String[4];
130 for (int zone = 2; zone <= 5; zone++) {
131 zones[zone-2] = "EPSG:" + (31464 + zone);
132 }
133 return zones;
134 }
135
136 @Override
137 public Collection<String> getPreferencesFromCode(String code)
138 {
139 //zone 2 = EPSG:31466 up to zone 5 = EPSG:31469
140 for (int zone = 2; zone <= 5; zone++) {
141 String epsg = "EPSG:" + (31464 + zone);
142 if (epsg.equals(code))
143 return Collections.singleton(String.valueOf(zone));
144 }
145 return null;
146 }
147
148}
Note: See TracBrowser for help on using the repository browser.