root / trunk / libraries / libCq CMS for java.old / src / org / cresques / ui / cts / CSSelectionModel.java @ 8120
History | View | Annotate | Download (15.6 KB)
1 | 2809 | nacho | /*
|
---|---|---|---|
2 | * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
||
3 | *
|
||
4 | * Copyright (C) 2004-5.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | * For more information, contact:
|
||
21 | *
|
||
22 | * cresques@gmail.com
|
||
23 | */
|
||
24 | package org.cresques.ui.cts; |
||
25 | |||
26 | import org.cresques.cts.IProjection; |
||
27 | import org.cresques.cts.ProjectionPool; |
||
28 | |||
29 | |||
30 | /**
|
||
31 | * @author Luis W. Sevilla (sevilla_lui@gva.es)
|
||
32 | */
|
||
33 | public class CSSelectionModel { |
||
34 | public static int NONE = 0x01; |
||
35 | public static int GEODETIC = 0x02; |
||
36 | public static int TRANSVERSAL = 0x03; |
||
37 | public String[] datumList = { |
||
38 | 8120 | jmvivo | "WGS 84", "European 1950", "Datum 73", |
39 | "North American Datum 1927",
|
||
40 | "North American Datum 1983",
|
||
41 | "La Canoa",
|
||
42 | "NTF (Paris)",
|
||
43 | "ETRS 89",
|
||
44 | "Moon (IAU 2000)",
|
||
45 | "Mars (IAU 2000)",
|
||
46 | "Campo_Inchauspe",
|
||
47 | "RGF93"
|
||
48 | }; |
||
49 | /*private String[] projList = {
|
||
50 | "Geodesica",
|
||
51 | "(UTM) Universal Transversal Mercator",
|
||
52 | "Datum 73 / Modified Portuguese Grid",
|
||
53 | "WGS 84 / LCC Canada",
|
||
54 | "NAD83 / NRCan LCC Canada",
|
||
55 | "Lambert Etendu",
|
||
56 | "RGF93 / Lambert-93",
|
||
57 | "WGS 84 / Mercator",
|
||
58 | "Campo Inchauspe / Zonas 1-7"
|
||
59 | };*/
|
||
60 | private String[][] projList = { |
||
61 | {"Geodesica", "(UTM) Universal Transversal Mercator", |
||
62 | "LCC Canada", "Mercator"}, // WGS84 |
||
63 | {"Geodesica", "(UTM) Universal Transversal Mercator"}, // ED50 |
||
64 | {"Geodesica", "Modified Portuguese Grid"}, //Datum 73 |
||
65 | {"Geodesica", "(UTM) Universal Transversal Mercator"}, // NAD27 |
||
66 | {"Geodesica", "(UTM) Universal Transversal Mercator", "NRCan LCC Canada"}, // NAD83 |
||
67 | {"Geodesica", "(UTM) Universal Transversal Mercator"}, // La Canoa |
||
68 | {"Geodesica", "Lambert Etendu"}, // NTF (Paris) |
||
69 | {"Geodesica", "(UTM) Universal Transversal Mercator"}, // ETRS89 |
||
70 | {"Geodesica"}, // Moon |
||
71 | {"Geodesica"}, // Mars |
||
72 | {"Geodesica", "Zonas 1-7"}, // CampoInchauspe |
||
73 | {"Geodesica", "Lambert-93"} // RFG93 |
||
74 | }; |
||
75 | |||
76 | private int[][] projType = { |
||
77 | {GEODETIC, TRANSVERSAL, NONE, NONE}, |
||
78 | {GEODETIC, TRANSVERSAL}, |
||
79 | {GEODETIC, NONE}, |
||
80 | {GEODETIC, TRANSVERSAL}, |
||
81 | {GEODETIC, TRANSVERSAL, NONE}, |
||
82 | {GEODETIC, TRANSVERSAL}, |
||
83 | {GEODETIC, NONE}, |
||
84 | {GEODETIC, TRANSVERSAL}, |
||
85 | {GEODETIC}, |
||
86 | {GEODETIC}, |
||
87 | {GEODETIC, TRANSVERSAL}, |
||
88 | {GEODETIC, NONE} |
||
89 | }; |
||
90 | |||
91 | private int [][] zoneRange = { |
||
92 | {1,60}, |
||
93 | {1,60}, |
||
94 | {0,0}, |
||
95 | {3,23}, |
||
96 | {3,23}, |
||
97 | {18,21}, |
||
98 | {0,0}, |
||
99 | {28,38}, |
||
100 | {0,0}, |
||
101 | {0,0}, |
||
102 | {1,7}, |
||
103 | {0,0} |
||
104 | }; |
||
105 | private String[] zoneList = { }; |
||
106 | 2809 | nacho | private int selectedDatum = 0; |
107 | private int selectedProj = 0; |
||
108 | 8120 | jmvivo | private int selectedZone = 0; |
109 | 2809 | nacho | |
110 | /**
|
||
111 | *
|
||
112 | */
|
||
113 | public CSSelectionModel() {
|
||
114 | super();
|
||
115 | 8120 | jmvivo | zoneList = new String[60]; |
116 | 2809 | nacho | |
117 | for (int i = 1; i <= 60; i++) |
||
118 | 8120 | jmvivo | zoneList[i - 1] = "Huso " + Integer.toString(i); |
119 | 2809 | nacho | } |
120 | 8120 | jmvivo | |
121 | 2809 | nacho | |
122 | public String[] getDatumList() { |
||
123 | return datumList;
|
||
124 | } |
||
125 | |||
126 | public String[] getProjectionList() { |
||
127 | 8120 | jmvivo | return projList[getSelectedDatum()];
|
128 | 2809 | nacho | } |
129 | |||
130 | 8120 | jmvivo | public String[] getZoneList() { |
131 | int [] r = zoneRange[getSelectedDatum()]; |
||
132 | return getZoneList(r[0],r[1]); |
||
133 | 2809 | nacho | } |
134 | |||
135 | 8120 | jmvivo | public String[] getZoneList(int from, int to) { |
136 | zoneList = new String[to-from+1]; |
||
137 | |||
138 | for (int i = from; i <= to; i++) |
||
139 | zoneList[i - from] = "Huso " + Integer.toString(i); |
||
140 | return zoneList;
|
||
141 | } |
||
142 | 2809 | nacho | public void setSelectedDatum(int opNr) { |
143 | selectedDatum = opNr; |
||
144 | } |
||
145 | |||
146 | public void setSelectedDatum(Object item) { |
||
147 | String[] list = datumList; |
||
148 | |||
149 | for (int i = 0; i < list.length; i++) |
||
150 | if (list[i].compareTo((String) item) == 0) { |
||
151 | selectedDatum = i; |
||
152 | 8120 | jmvivo | break;
|
153 | 2809 | nacho | } |
154 | } |
||
155 | |||
156 | public int getSelectedDatum() { |
||
157 | return selectedDatum;
|
||
158 | } |
||
159 | |||
160 | public void setSelectedProj(int opNr) { |
||
161 | selectedProj = opNr; |
||
162 | } |
||
163 | |||
164 | public void setSelectedProj(Object item) { |
||
165 | 8120 | jmvivo | String[] list = projList[getSelectedDatum()]; |
166 | 2809 | nacho | |
167 | for (int i = 0; i < list.length; i++) |
||
168 | if (list[i].compareTo((String) item) == 0) { |
||
169 | selectedProj = i; |
||
170 | 8120 | jmvivo | break;
|
171 | 2809 | nacho | } |
172 | } |
||
173 | |||
174 | public int getSelectedProj() { |
||
175 | return selectedProj;
|
||
176 | } |
||
177 | |||
178 | public int getSelectedProjType() { |
||
179 | 8120 | jmvivo | return projType[getSelectedDatum()][selectedProj];
|
180 | 2809 | nacho | } |
181 | |||
182 | 8120 | jmvivo | public void setSelectedZone(int opNr) { |
183 | selectedZone = opNr; |
||
184 | 2809 | nacho | } |
185 | |||
186 | 8120 | jmvivo | public void setSelectedZone(Object item) { |
187 | String[] list = zoneList; |
||
188 | 2809 | nacho | |
189 | for (int i = 0; i < list.length; i++) |
||
190 | if (list[i].compareTo((String) item) == 0) { |
||
191 | 8120 | jmvivo | selectedZone = i; |
192 | break;
|
||
193 | 2809 | nacho | } |
194 | } |
||
195 | |||
196 | 8120 | jmvivo | public int getSelectedZone() { |
197 | return selectedZone;
|
||
198 | 2809 | nacho | } |
199 | |||
200 | public void setProjection(IProjection proj) { |
||
201 | String key = proj.getAbrev();
|
||
202 | 8120 | jmvivo | // Para usos posteriores.
|
203 | // String db = key.split(":")[0];
|
||
204 | key = key.split(":")[1]; |
||
205 | 2809 | nacho | |
206 | 8120 | jmvivo | setSelectedProj(0);
|
207 | setSelectedZone(-1);
|
||
208 | |||
209 | if (key.endsWith("4326")) { |
||
210 | 2809 | nacho | setSelectedDatum(0);
|
211 | 8120 | jmvivo | } else if (key.endsWith("4230")) { |
212 | 2809 | nacho | setSelectedDatum(1);
|
213 | 8120 | jmvivo | } else if (key.endsWith("4274")) { |
214 | 2809 | nacho | setSelectedDatum(2);
|
215 | 8120 | jmvivo | } else if (key.endsWith("4267")) { |
216 | 2809 | nacho | setSelectedDatum(3);
|
217 | 8120 | jmvivo | } else if (key.endsWith("4269")) { |
218 | setSelectedDatum(4);
|
||
219 | } else if (key.endsWith("4247")) { |
||
220 | 2809 | nacho | setSelectedDatum(5);
|
221 | 8120 | jmvivo | } else if (key.endsWith("4807")) { |
222 | setSelectedDatum(6);
|
||
223 | } else if (key.endsWith("4258")) { |
||
224 | setSelectedDatum(7);
|
||
225 | } else if (key.endsWith("30100")) { |
||
226 | setSelectedDatum(8);
|
||
227 | } else if (key.endsWith("49900")) { |
||
228 | setSelectedDatum(9);
|
||
229 | } else if (key.endsWith("4221")) { |
||
230 | setSelectedDatum(10);
|
||
231 | } else if (key.endsWith("4171")) { |
||
232 | setSelectedDatum(11);
|
||
233 | 2809 | nacho | } else if (key.startsWith("326")) { |
234 | setSelectedDatum(0);
|
||
235 | setSelectedProj(1);
|
||
236 | 8120 | jmvivo | setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
237 | 2809 | nacho | } else if (key.startsWith("230")) { |
238 | setSelectedDatum(1);
|
||
239 | setSelectedProj(1);
|
||
240 | 8120 | jmvivo | setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
241 | 2809 | nacho | } else if (key.startsWith("267")) { |
242 | 8120 | jmvivo | setSelectedDatum(3);
|
243 | 2809 | nacho | setSelectedProj(1);
|
244 | 8120 | jmvivo | setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
245 | 2809 | nacho | } else if (key.startsWith("269")) { |
246 | 8120 | jmvivo | setSelectedDatum(4);
|
247 | 2809 | nacho | setSelectedProj(1);
|
248 | 8120 | jmvivo | setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
249 | 2809 | nacho | } else if (key.startsWith("247")) { |
250 | 8120 | jmvivo | setSelectedDatum(5);
|
251 | 2809 | nacho | setSelectedProj(1);
|
252 | 8120 | jmvivo | setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
253 | } else if (key.startsWith("258")) { |
||
254 | setSelectedDatum(7);
|
||
255 | setSelectedProj(1);
|
||
256 | setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
||
257 | } else if (key.startsWith("221")) { |
||
258 | setSelectedDatum(10);
|
||
259 | setSelectedProj(1);
|
||
260 | setSelectedZone("Huso "+ Integer.parseInt(key.substring(4))); |
||
261 | } else if (key.endsWith("27492")) { // Datum 73 / Modified Portuguese Grid |
||
262 | setSelectedDatum(2);
|
||
263 | setSelectedProj(1);
|
||
264 | setSelectedZone(-1);
|
||
265 | } else if (key.endsWith("42101")) { // WGS 84 / LCC Canada |
||
266 | setSelectedDatum(0);
|
||
267 | 2809 | nacho | setSelectedProj(2);
|
268 | 8120 | jmvivo | setSelectedZone(-1);
|
269 | } else if (key.endsWith("9804")) { // WGS 84 / Mercator |
||
270 | setSelectedDatum(0);
|
||
271 | 2809 | nacho | setSelectedProj(3);
|
272 | 8120 | jmvivo | setSelectedZone(-1);
|
273 | } else if (key.endsWith("30100")) { // Moon |
||
274 | setSelectedDatum(8);
|
||
275 | setSelectedProj(0);
|
||
276 | setSelectedZone(-1);
|
||
277 | } else if (key.endsWith("49900")) { // Mars |
||
278 | setSelectedDatum(9);
|
||
279 | setSelectedProj(0);
|
||
280 | setSelectedZone(-1);
|
||
281 | } else if (key.endsWith("42304")) { // NAD83 / / LCC Canada |
||
282 | setSelectedDatum(4);
|
||
283 | setSelectedProj(2);
|
||
284 | setSelectedZone(-1);
|
||
285 | } else if (key.endsWith("27582")) { // NTFParis / / Lambert Etendu |
||
286 | setSelectedDatum(6);
|
||
287 | setSelectedProj(1);
|
||
288 | setSelectedZone(-1);
|
||
289 | } else if (key.equals("2154")) { // RGF93 / / Lambert 93 |
||
290 | setSelectedDatum(11);
|
||
291 | setSelectedProj(1);
|
||
292 | setSelectedZone(-1);
|
||
293 | } else {
|
||
294 | 2809 | nacho | System.err.println("CAGADA EN EL PARSING DE LA PROYECCION: " + key); |
295 | } |
||
296 | } |
||
297 | |||
298 | public IProjection getProjection() {
|
||
299 | IProjection proj = null;
|
||
300 | String datum = "326"; |
||
301 | |||
302 | if (selectedDatum == 0) { |
||
303 | datum = "326";
|
||
304 | 8120 | jmvivo | if (selectedProj == 0) |
305 | return new ProjectionPool().get("EPSG:4"+datum); |
||
306 | else if (selectedProj == 1) { |
||
307 | String zone = Integer.toString(selectedZone + 1); |
||
308 | if (selectedZone < 9) zone = "0" + zone; |
||
309 | return new ProjectionPool().get("EPSG:" + datum + zone); |
||
310 | } else if (selectedProj == 2) |
||
311 | return new ProjectionPool().get("EPSG:42101"); |
||
312 | else if (selectedProj == 3) |
||
313 | return new ProjectionPool().get("EPSG:9804"); |
||
314 | |||
315 | 2809 | nacho | } else if (selectedDatum == 1) { |
316 | datum = "230";
|
||
317 | 8120 | jmvivo | if (selectedProj == 0) |
318 | return new ProjectionPool().get("EPSG:4"+datum); |
||
319 | else if (selectedProj == 1) { |
||
320 | String zone = Integer.toString(selectedZone + 1); |
||
321 | if (selectedZone < 9) zone = "0" + zone; |
||
322 | return new ProjectionPool().get("EPSG:" + datum + zone); |
||
323 | } |
||
324 | |||
325 | } else if (selectedDatum == 2) { // Lisboa 73 |
||
326 | datum = "274";
|
||
327 | if (selectedProj == 0) |
||
328 | return new ProjectionPool().get("EPSG:4"+datum); |
||
329 | else if (selectedProj == 1) |
||
330 | return new ProjectionPool().get("EPSG:"+datum+"92"); |
||
331 | |||
332 | } else if (selectedDatum == 3) { |
||
333 | 2809 | nacho | datum = "267";
|
334 | 8120 | jmvivo | if (selectedProj == 0) |
335 | return new ProjectionPool().get("EPSG:4"+datum); |
||
336 | else if (selectedProj == 1) { |
||
337 | String zone = Integer.toString(selectedZone + 3); |
||
338 | if (selectedZone+3 <= 9) zone = "0" + zone; |
||
339 | return new ProjectionPool().get("EPSG:" + datum + zone); |
||
340 | } |
||
341 | |||
342 | } else if (selectedDatum == 4) { |
||
343 | 2809 | nacho | datum = "269";
|
344 | 8120 | jmvivo | if (selectedProj == 0) |
345 | return new ProjectionPool().get("EPSG:4"+datum); |
||
346 | else if (selectedProj == 1) { |
||
347 | String zone = Integer.toString(selectedZone + 3); |
||
348 | if (selectedZone+3 <= 9) zone = "0" + zone; |
||
349 | return new ProjectionPool().get("EPSG:" + datum + zone); |
||
350 | } else if (selectedProj == 2) |
||
351 | return new ProjectionPool().get("EPSG:42304"); |
||
352 | |||
353 | 2809 | nacho | } else if (selectedDatum == 5) { |
354 | datum = "247";
|
||
355 | 8120 | jmvivo | if (selectedProj == 0) |
356 | return new ProjectionPool().get("EPSG:4"+datum); |
||
357 | else if (selectedProj == 1) { |
||
358 | String zone = Integer.toString(selectedZone + 18); |
||
359 | return new ProjectionPool().get("EPSG:" + datum + zone); |
||
360 | } |
||
361 | |||
362 | } else if (selectedDatum == 6) { |
||
363 | datum = "807";
|
||
364 | if (selectedProj == 0) |
||
365 | return new ProjectionPool().get("EPSG:4"+datum); |
||
366 | else if (selectedProj == 1) |
||
367 | return new ProjectionPool().get("EPSG:27582"); |
||
368 | |||
369 | } else if (selectedDatum == 7) { |
||
370 | datum = "258";
|
||
371 | if (selectedProj == 0) |
||
372 | return new ProjectionPool().get("EPSG:4"+datum); |
||
373 | else if (selectedProj == 1) { |
||
374 | String zone = Integer.toString(selectedZone + 28); |
||
375 | return new ProjectionPool().get("EPSG:" + datum + zone); |
||
376 | } |
||
377 | |||
378 | } else if (selectedDatum == 8) { |
||
379 | datum = "30100";
|
||
380 | return new ProjectionPool().get("IAU2000:" + datum); |
||
381 | |||
382 | } else if (selectedDatum == 9) { |
||
383 | datum = "49900";
|
||
384 | return new ProjectionPool().get("IAU2000:" + datum); |
||
385 | |||
386 | } else if (selectedDatum == 10) { |
||
387 | datum = "221";
|
||
388 | if (selectedProj == 0) |
||
389 | return new ProjectionPool().get("EPSG:4"+datum); |
||
390 | else if (selectedProj == 1) { |
||
391 | String zone = Integer.toString(selectedZone + 1); |
||
392 | return new ProjectionPool().get("EPSG:" + datum + "9"+ zone); |
||
393 | } |
||
394 | |||
395 | } else if (selectedDatum == 11) { |
||
396 | if (selectedProj == 0) |
||
397 | return new ProjectionPool().get("EPSG:4171"); |
||
398 | else if (selectedProj == 1) |
||
399 | return new ProjectionPool().get("EPSG:2154"); |
||
400 | 2809 | nacho | } |
401 | |||
402 | 8120 | jmvivo | if (selectedProj == 2) { |
403 | return new ProjectionPool().get("EPSG:27492"); |
||
404 | } else if (selectedProj == 3) { |
||
405 | return new ProjectionPool().get("EPSG:42101"); |
||
406 | } else if (selectedProj == 4) { |
||
407 | return new ProjectionPool().get("EPSG:42304"); |
||
408 | } else if (selectedProj == 5) { |
||
409 | return new ProjectionPool().get("EPSG:27582"); |
||
410 | } else if (selectedProj == 6) { |
||
411 | return new ProjectionPool().get("EPSG:2154"); |
||
412 | } else if (selectedProj == 7) { |
||
413 | return new ProjectionPool().get("EPSG:9804"); |
||
414 | } else if (selectedProj == 8) { |
||
415 | datum = "221";
|
||
416 | String zone = "9"; |
||
417 | //if (selectedDatum == 10) {
|
||
418 | if (selectedZone < 1) { |
||
419 | zone += "1";
|
||
420 | } else if (selectedZone > 7) { |
||
421 | zone += "7";
|
||
422 | } else
|
||
423 | zone += (selectedZone+1)+""; |
||
424 | // }
|
||
425 | return new ProjectionPool().get("EPSG:" + datum + zone); |
||
426 | } |
||
427 | |||
428 | |||
429 | 2809 | nacho | if (selectedProj == 0) { |
430 | 8120 | jmvivo | return new ProjectionPool().get("EPSG:4" + datum); |
431 | 2809 | nacho | } else if (selectedProj == 1) { |
432 | 8120 | jmvivo | String Zone = Integer.toString(selectedZone + 1); |
433 | 2809 | nacho | |
434 | 8120 | jmvivo | if (selectedZone < 9) { |
435 | Zone = "0" + Zone;
|
||
436 | 2809 | nacho | } |
437 | |||
438 | if ((selectedDatum == 2) || (selectedDatum == 3)) { |
||
439 | 8120 | jmvivo | if (selectedZone < 3) { |
440 | Zone = "03";
|
||
441 | 2809 | nacho | } |
442 | |||
443 | 8120 | jmvivo | if (selectedZone > 23) { |
444 | Zone = "23";
|
||
445 | 2809 | nacho | } |
446 | } |
||
447 | |||
448 | 8120 | jmvivo | if (selectedDatum == 5) { |
449 | if (selectedZone < 18) { |
||
450 | Zone = "18";
|
||
451 | 2809 | nacho | } |
452 | |||
453 | 8120 | jmvivo | if (selectedZone > 22) { |
454 | Zone = "22";
|
||
455 | 2809 | nacho | } |
456 | } |
||
457 | |||
458 | 8120 | jmvivo | if (selectedDatum == 7) { |
459 | if (selectedZone < 28) { |
||
460 | Zone = "28";
|
||
461 | } |
||
462 | 2809 | nacho | |
463 | 8120 | jmvivo | if (selectedZone > 38) { |
464 | Zone = "38";
|
||
465 | } |
||
466 | } |
||
467 | return new ProjectionPool().get("EPSG:" + datum + Zone); |
||
468 | } |
||
469 | |||
470 | 2809 | nacho | return proj;
|
471 | } |
||
472 | } |