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.TransverseMercator;
|
---|
20 | import org.openstreetmap.josm.tools.GBC;
|
---|
21 |
|
---|
22 | public class GaussKrueger extends AbstractProjection implements ProjectionSubPrefs {
|
---|
23 |
|
---|
24 | public static int DEFAULT_ZONE = 2;
|
---|
25 | private int zone;
|
---|
26 |
|
---|
27 | private static Bounds[] bounds = {
|
---|
28 | new Bounds(new LatLon(-5, 3.5), new LatLon(85, 8.5)),
|
---|
29 | new Bounds(new LatLon(-5, 6.5), new LatLon(85, 11.5)),
|
---|
30 | new Bounds(new LatLon(-5, 9.5), new LatLon(85, 14.5)),
|
---|
31 | new Bounds(new LatLon(-5, 12.5), new LatLon(85, 17.5)),
|
---|
32 | };
|
---|
33 |
|
---|
34 | private static NTV2GridShiftFile BETA2007 = null;
|
---|
35 |
|
---|
36 | private static String[] zones = { "2", "3", "4", "5" };
|
---|
37 |
|
---|
38 | public GaussKrueger() {
|
---|
39 | this(DEFAULT_ZONE);
|
---|
40 | }
|
---|
41 |
|
---|
42 | public GaussKrueger(int zone) {
|
---|
43 | if (BETA2007 == null) {
|
---|
44 | try {
|
---|
45 | String gridFileName = "BETA2007.gsb";
|
---|
46 | InputStream is = Main.class.getResourceAsStream("/data/"+gridFileName);
|
---|
47 | if (is == null) {
|
---|
48 | throw new RuntimeException(tr("Error: failed to open input stream for resource ''/data/{0}''.", gridFileName));
|
---|
49 | }
|
---|
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(ellps);
|
---|
68 | x_0 = 1000000 * zone + 500000;
|
---|
69 | lon_0 = 3 * zone;
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Override
|
---|
73 | public String toString() {
|
---|
74 | return tr("Gau\u00DF-Kr\u00FCger");
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public Integer getEpsgCode() {
|
---|
79 | return 31464 + zone;
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public String getCacheDirectoryName() {
|
---|
84 | return "gausskrueger"+zone;
|
---|
85 | }
|
---|
86 |
|
---|
87 | @Override
|
---|
88 | public Bounds getWorldBoundsLatLon() {
|
---|
89 | return bounds[zone-2];
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Override
|
---|
93 | public void setupPreferencePanel(JPanel p, ActionListener listener) {
|
---|
94 | JComboBox prefcb = new JComboBox(zones);
|
---|
95 |
|
---|
96 | prefcb.setSelectedIndex(zone-2);
|
---|
97 | p.setLayout(new GridBagLayout());
|
---|
98 | p.add(new JLabel(tr("GK Zone")), GBC.std().insets(5,5,0,5));
|
---|
99 | p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
100 | /* Note: we use component position 2 below to find this again */
|
---|
101 | p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
|
---|
102 | p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
|
---|
103 |
|
---|
104 | if (listener != null) {
|
---|
105 | prefcb.addActionListener(listener);
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | @Override
|
---|
110 | public Collection<String> getPreferences(JPanel p) {
|
---|
111 | Object prefcb = p.getComponent(2);
|
---|
112 | if(!(prefcb instanceof JComboBox))
|
---|
113 | return null;
|
---|
114 | int zone = ((JComboBox)prefcb).getSelectedIndex();
|
---|
115 | return Collections.singleton(Integer.toString(zone+2));
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Override
|
---|
119 | public void setPreferences(Collection<String> args) {
|
---|
120 | int zone = DEFAULT_ZONE;
|
---|
121 | if (args != null) {
|
---|
122 | try {
|
---|
123 | for(String s : args)
|
---|
124 | {
|
---|
125 | zone = Integer.parseInt(s);
|
---|
126 | if(zone < 2 || zone > 5) {
|
---|
127 | zone = DEFAULT_ZONE;
|
---|
128 | }
|
---|
129 | break;
|
---|
130 | }
|
---|
131 | } catch(NumberFormatException e) {}
|
---|
132 | }
|
---|
133 | updateParameters(zone);
|
---|
134 | }
|
---|
135 |
|
---|
136 | @Override
|
---|
137 | public String[] allCodes() {
|
---|
138 | String[] zones = new String[4];
|
---|
139 | for (int zone = 2; zone <= 5; zone++) {
|
---|
140 | zones[zone-2] = "EPSG:" + (31464 + zone);
|
---|
141 | }
|
---|
142 | return zones;
|
---|
143 | }
|
---|
144 |
|
---|
145 | @Override
|
---|
146 | public Collection<String> getPreferencesFromCode(String code)
|
---|
147 | {
|
---|
148 | //zone 2 = EPSG:31466 up to zone 5 = EPSG:31469
|
---|
149 | for (int zone = 2; zone <= 5; zone++) {
|
---|
150 | String epsg = "EPSG:" + (31464 + zone);
|
---|
151 | if (epsg.equals(code))
|
---|
152 | return Collections.singleton(String.valueOf(zone));
|
---|
153 | }
|
---|
154 | return null;
|
---|
155 | }
|
---|
156 |
|
---|
157 | }
|
---|