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