1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.projection;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 | import java.awt.event.ActionListener;
|
---|
8 | import java.io.InputStream;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.Collections;
|
---|
11 |
|
---|
12 | import javax.swing.JComboBox;
|
---|
13 | import javax.swing.JLabel;
|
---|
14 | import javax.swing.JPanel;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.Main;
|
---|
17 | import org.openstreetmap.josm.data.Bounds;
|
---|
18 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
19 | import org.openstreetmap.josm.data.projection.proj.ProjParameters;
|
---|
20 | import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
|
---|
21 | import org.openstreetmap.josm.tools.GBC;
|
---|
22 |
|
---|
23 | public 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 NTV2GridShiftFile BETA2007 = null;
|
---|
36 |
|
---|
37 | private static String[] zones = { "2", "3", "4", "5" };
|
---|
38 |
|
---|
39 | public GaussKrueger() {
|
---|
40 | this(DEFAULT_ZONE);
|
---|
41 | }
|
---|
42 |
|
---|
43 | public GaussKrueger(int zone) {
|
---|
44 | if (BETA2007 == null) {
|
---|
45 | try {
|
---|
46 | String gridFileName = "BETA2007.gsb";
|
---|
47 | InputStream is = Main.class.getResourceAsStream("/data/"+gridFileName);
|
---|
48 | if (is == null)
|
---|
49 | throw new RuntimeException(tr("Error: failed to open input stream for resource ''/data/{0}''.", gridFileName));
|
---|
50 | BETA2007 = new NTV2GridShiftFile();
|
---|
51 | BETA2007.loadGridShiftFile(is, false);
|
---|
52 | } catch (Exception e) {
|
---|
53 | throw new RuntimeException(e);
|
---|
54 | }
|
---|
55 | }
|
---|
56 | updateParameters(zone);
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void updateParameters(int zone) {
|
---|
60 | this.zone = zone;
|
---|
61 | ellps = Ellipsoid.Bessel1841;
|
---|
62 | nadgrids = BETA2007;
|
---|
63 | ////less acurrate datum (errors up to 3m):
|
---|
64 | //datum = new SevenParameterDatum(
|
---|
65 | // tr("Deutsches Hauptdreiecksnetz"), null, ellps,
|
---|
66 | // 598.1, 73.7, 418.2, 0.202, 0.045, -2.455, 6.70);
|
---|
67 | proj = new TransverseMercator();
|
---|
68 | try {
|
---|
69 | proj.initialize(new ProjParameters() {{ ellps = GaussKrueger.this.ellps; }});
|
---|
70 | } catch (ProjectionConfigurationException e) {
|
---|
71 | throw new RuntimeException(e);
|
---|
72 | }
|
---|
73 | x_0 = 1000000 * zone + 500000;
|
---|
74 | lon_0 = 3 * zone;
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public String toString() {
|
---|
79 | return tr("Gau\u00DF-Kr\u00FCger");
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public Integer getEpsgCode() {
|
---|
84 | return 31464 + zone;
|
---|
85 | }
|
---|
86 |
|
---|
87 | @Override
|
---|
88 | public String getCacheDirectoryName() {
|
---|
89 | return "gausskrueger"+zone;
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Override
|
---|
93 | public Bounds getWorldBoundsLatLon() {
|
---|
94 | return bounds[zone-2];
|
---|
95 | }
|
---|
96 |
|
---|
97 | @Override
|
---|
98 | public void setupPreferencePanel(JPanel p, ActionListener listener) {
|
---|
99 | JComboBox prefcb = new JComboBox(zones);
|
---|
100 |
|
---|
101 | prefcb.setSelectedIndex(zone-2);
|
---|
102 | p.setLayout(new GridBagLayout());
|
---|
103 | p.add(new JLabel(tr("GK Zone")), GBC.std().insets(5,5,0,5));
|
---|
104 | p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
105 | /* Note: we use component position 2 below to find this again */
|
---|
106 | p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
|
---|
107 | p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
|
---|
108 |
|
---|
109 | if (listener != null) {
|
---|
110 | prefcb.addActionListener(listener);
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | @Override
|
---|
115 | public Collection<String> getPreferences(JPanel p) {
|
---|
116 | Object prefcb = p.getComponent(2);
|
---|
117 | if(!(prefcb instanceof JComboBox))
|
---|
118 | return null;
|
---|
119 | int zone = ((JComboBox)prefcb).getSelectedIndex();
|
---|
120 | return Collections.singleton(Integer.toString(zone+2));
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Override
|
---|
124 | public void setPreferences(Collection<String> args) {
|
---|
125 | int zone = DEFAULT_ZONE;
|
---|
126 | if (args != null) {
|
---|
127 | try {
|
---|
128 | for(String s : args)
|
---|
129 | {
|
---|
130 | zone = Integer.parseInt(s);
|
---|
131 | if(zone < 2 || zone > 5) {
|
---|
132 | zone = DEFAULT_ZONE;
|
---|
133 | }
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | } catch(NumberFormatException e) {}
|
---|
137 | }
|
---|
138 | updateParameters(zone);
|
---|
139 | }
|
---|
140 |
|
---|
141 | @Override
|
---|
142 | public String[] allCodes() {
|
---|
143 | String[] zones = new String[4];
|
---|
144 | for (int zone = 2; zone <= 5; zone++) {
|
---|
145 | zones[zone-2] = "EPSG:" + (31464 + zone);
|
---|
146 | }
|
---|
147 | return zones;
|
---|
148 | }
|
---|
149 |
|
---|
150 | @Override
|
---|
151 | public Collection<String> getPreferencesFromCode(String code)
|
---|
152 | {
|
---|
153 | //zone 2 = EPSG:31466 up to zone 5 = EPSG:31469
|
---|
154 | for (int zone = 2; zone <= 5; zone++) {
|
---|
155 | String epsg = "EPSG:" + (31464 + zone);
|
---|
156 | if (epsg.equals(code))
|
---|
157 | return Collections.singleton(String.valueOf(zone));
|
---|
158 | }
|
---|
159 | return null;
|
---|
160 | }
|
---|
161 |
|
---|
162 | }
|
---|