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 final 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 | BETA2007 = new NTV2GridShiftFile();
|
---|
50 | BETA2007.loadGridShiftFile(is, false);
|
---|
51 | } catch (Exception e) {
|
---|
52 | throw new RuntimeException(e);
|
---|
53 | }
|
---|
54 | }
|
---|
55 | updateParameters(zone);
|
---|
56 | }
|
---|
57 |
|
---|
58 | private void updateParameters(int zone) {
|
---|
59 | this.zone = zone;
|
---|
60 | ellps = Ellipsoid.Bessel1841;
|
---|
61 | nadgrids = BETA2007;
|
---|
62 | ////less acurrate datum (errors up to 3m):
|
---|
63 | //datum = new SevenParameterDatum(
|
---|
64 | // tr("Deutsches Hauptdreiecksnetz"), null, ellps,
|
---|
65 | // 598.1, 73.7, 418.2, 0.202, 0.045, -2.455, 6.70);
|
---|
66 | proj = new TransverseMercator(ellps);
|
---|
67 | x_0 = 1000000 * zone + 500000;
|
---|
68 | lon_0 = 3 * zone;
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public String toString() {
|
---|
73 | return tr("Gau\u00DF-Kr\u00FCger");
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public Integer getEpsgCode() {
|
---|
78 | return 31464 + zone;
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public String getCacheDirectoryName() {
|
---|
83 | return "gausskrueger"+zone;
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Override
|
---|
87 | public Bounds getWorldBoundsLatLon() {
|
---|
88 | return bounds[zone-2];
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | public void setupPreferencePanel(JPanel p, ActionListener listener) {
|
---|
93 | JComboBox prefcb = new JComboBox(zones);
|
---|
94 |
|
---|
95 | prefcb.setSelectedIndex(zone-2);
|
---|
96 | p.setLayout(new GridBagLayout());
|
---|
97 | p.add(new JLabel(tr("GK Zone")), GBC.std().insets(5,5,0,5));
|
---|
98 | p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
99 | /* Note: we use component position 2 below to find this again */
|
---|
100 | p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
|
---|
101 | p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
|
---|
102 |
|
---|
103 | if (listener != null) {
|
---|
104 | prefcb.addActionListener(listener);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Override
|
---|
109 | public Collection<String> getPreferences(JPanel p) {
|
---|
110 | Object prefcb = p.getComponent(2);
|
---|
111 | if(!(prefcb instanceof JComboBox))
|
---|
112 | return null;
|
---|
113 | int zone = ((JComboBox)prefcb).getSelectedIndex();
|
---|
114 | return Collections.singleton(Integer.toString(zone+2));
|
---|
115 | }
|
---|
116 |
|
---|
117 | @Override
|
---|
118 | public void setPreferences(Collection<String> args) {
|
---|
119 | int zone = DEFAULT_ZONE;
|
---|
120 | if (args != null) {
|
---|
121 | try {
|
---|
122 | for(String s : args)
|
---|
123 | {
|
---|
124 | zone = Integer.parseInt(s);
|
---|
125 | if(zone < 2 || zone > 5) {
|
---|
126 | zone = DEFAULT_ZONE;
|
---|
127 | }
|
---|
128 | break;
|
---|
129 | }
|
---|
130 | } catch(NumberFormatException e) {}
|
---|
131 | }
|
---|
132 | updateParameters(zone);
|
---|
133 | }
|
---|
134 |
|
---|
135 | @Override
|
---|
136 | public String[] allCodes() {
|
---|
137 | String[] zones = new String[4];
|
---|
138 | for (int zone = 2; zone <= 5; zone++) {
|
---|
139 | zones[zone-2] = "EPSG:" + (31464 + zone);
|
---|
140 | }
|
---|
141 | return zones;
|
---|
142 | }
|
---|
143 |
|
---|
144 | @Override
|
---|
145 | public Collection<String> getPreferencesFromCode(String code)
|
---|
146 | {
|
---|
147 | //zone 2 = EPSG:31466 up to zone 5 = EPSG:31469
|
---|
148 | for (int zone = 2; zone <= 5; zone++) {
|
---|
149 | String epsg = "EPSG:" + (31464 + zone);
|
---|
150 | if (epsg.equals(code))
|
---|
151 | return Collections.singleton(String.valueOf(zone));
|
---|
152 | }
|
---|
153 | return null;
|
---|
154 | }
|
---|
155 |
|
---|
156 | }
|
---|