svn-gvsig-desktop / tags / v1_0_2_Build_905 / libraries / libCq CMS for java.old / src / org / cresques / ui / cts / CSSelectionModel.java @ 10767
History | View | Annotate | Download (15.6 KB)
1 |
/*
|
---|---|
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 |
"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 |
private int selectedDatum = 0; |
107 |
private int selectedProj = 0; |
108 |
private int selectedZone = 0; |
109 |
|
110 |
/**
|
111 |
*
|
112 |
*/
|
113 |
public CSSelectionModel() {
|
114 |
super();
|
115 |
zoneList = new String[60]; |
116 |
|
117 |
for (int i = 1; i <= 60; i++) |
118 |
zoneList[i - 1] = "Huso " + Integer.toString(i); |
119 |
} |
120 |
|
121 |
|
122 |
public String[] getDatumList() { |
123 |
return datumList;
|
124 |
} |
125 |
|
126 |
public String[] getProjectionList() { |
127 |
return projList[getSelectedDatum()];
|
128 |
} |
129 |
|
130 |
public String[] getZoneList() { |
131 |
int [] r = zoneRange[getSelectedDatum()]; |
132 |
return getZoneList(r[0],r[1]); |
133 |
} |
134 |
|
135 |
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 |
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 |
break;
|
153 |
} |
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 |
String[] list = projList[getSelectedDatum()]; |
166 |
|
167 |
for (int i = 0; i < list.length; i++) |
168 |
if (list[i].compareTo((String) item) == 0) { |
169 |
selectedProj = i; |
170 |
break;
|
171 |
} |
172 |
} |
173 |
|
174 |
public int getSelectedProj() { |
175 |
return selectedProj;
|
176 |
} |
177 |
|
178 |
public int getSelectedProjType() { |
179 |
return projType[getSelectedDatum()][selectedProj];
|
180 |
} |
181 |
|
182 |
public void setSelectedZone(int opNr) { |
183 |
selectedZone = opNr; |
184 |
} |
185 |
|
186 |
public void setSelectedZone(Object item) { |
187 |
String[] list = zoneList; |
188 |
|
189 |
for (int i = 0; i < list.length; i++) |
190 |
if (list[i].compareTo((String) item) == 0) { |
191 |
selectedZone = i; |
192 |
break;
|
193 |
} |
194 |
} |
195 |
|
196 |
public int getSelectedZone() { |
197 |
return selectedZone;
|
198 |
} |
199 |
|
200 |
public void setProjection(IProjection proj) { |
201 |
String key = proj.getAbrev();
|
202 |
// Para usos posteriores.
|
203 |
// String db = key.split(":")[0];
|
204 |
key = key.split(":")[1]; |
205 |
|
206 |
setSelectedProj(0);
|
207 |
setSelectedZone(-1);
|
208 |
|
209 |
if (key.endsWith("4326")) { |
210 |
setSelectedDatum(0);
|
211 |
} else if (key.endsWith("4230")) { |
212 |
setSelectedDatum(1);
|
213 |
} else if (key.endsWith("4274")) { |
214 |
setSelectedDatum(2);
|
215 |
} else if (key.endsWith("4267")) { |
216 |
setSelectedDatum(3);
|
217 |
} else if (key.endsWith("4269")) { |
218 |
setSelectedDatum(4);
|
219 |
} else if (key.endsWith("4247")) { |
220 |
setSelectedDatum(5);
|
221 |
} 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 |
} else if (key.startsWith("326")) { |
234 |
setSelectedDatum(0);
|
235 |
setSelectedProj(1);
|
236 |
setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
237 |
} else if (key.startsWith("230")) { |
238 |
setSelectedDatum(1);
|
239 |
setSelectedProj(1);
|
240 |
setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
241 |
} else if (key.startsWith("267")) { |
242 |
setSelectedDatum(3);
|
243 |
setSelectedProj(1);
|
244 |
setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
245 |
} else if (key.startsWith("269")) { |
246 |
setSelectedDatum(4);
|
247 |
setSelectedProj(1);
|
248 |
setSelectedZone("Huso "+ Integer.parseInt(key.substring(3))); |
249 |
} else if (key.startsWith("247")) { |
250 |
setSelectedDatum(5);
|
251 |
setSelectedProj(1);
|
252 |
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 |
setSelectedProj(2);
|
268 |
setSelectedZone(-1);
|
269 |
} else if (key.endsWith("54004") || |
270 |
key.endsWith("54004")) { // WGS 84 / Mercator |
271 |
setSelectedDatum(0);
|
272 |
setSelectedProj(3);
|
273 |
setSelectedZone(-1);
|
274 |
} else if (key.endsWith("30100")) { // Moon |
275 |
setSelectedDatum(8);
|
276 |
setSelectedProj(0);
|
277 |
setSelectedZone(-1);
|
278 |
} else if (key.endsWith("49900")) { // Mars |
279 |
setSelectedDatum(9);
|
280 |
setSelectedProj(0);
|
281 |
setSelectedZone(-1);
|
282 |
} else if (key.endsWith("42304")) { // NAD83 / / LCC Canada |
283 |
setSelectedDatum(4);
|
284 |
setSelectedProj(2);
|
285 |
setSelectedZone(-1);
|
286 |
} else if (key.endsWith("27582")) { // NTFParis / / Lambert Etendu |
287 |
setSelectedDatum(6);
|
288 |
setSelectedProj(1);
|
289 |
setSelectedZone(-1);
|
290 |
} else if (key.equals("2154")) { // RGF93 / / Lambert 93 |
291 |
setSelectedDatum(11);
|
292 |
setSelectedProj(1);
|
293 |
setSelectedZone(-1);
|
294 |
} else {
|
295 |
System.err.println("CAGADA EN EL PARSING DE LA PROYECCION: " + key); |
296 |
} |
297 |
} |
298 |
|
299 |
public IProjection getProjection() {
|
300 |
IProjection proj = null;
|
301 |
String datum = "326"; |
302 |
|
303 |
if (selectedDatum == 0) { |
304 |
datum = "326";
|
305 |
if (selectedProj == 0) |
306 |
return new ProjectionPool().get("EPSG:4"+datum); |
307 |
else if (selectedProj == 1) { |
308 |
String zone = Integer.toString(selectedZone + 1); |
309 |
if (selectedZone < 9) zone = "0" + zone; |
310 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
311 |
} else if (selectedProj == 2) |
312 |
return new ProjectionPool().get("EPSG:42101"); |
313 |
else if (selectedProj == 3) |
314 |
return new ProjectionPool().get("EPSG:54004"); |
315 |
|
316 |
} else if (selectedDatum == 1) { |
317 |
datum = "230";
|
318 |
if (selectedProj == 0) |
319 |
return new ProjectionPool().get("EPSG:4"+datum); |
320 |
else if (selectedProj == 1) { |
321 |
String zone = Integer.toString(selectedZone + 1); |
322 |
if (selectedZone < 9) zone = "0" + zone; |
323 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
324 |
} |
325 |
|
326 |
} else if (selectedDatum == 2) { // Lisboa 73 |
327 |
datum = "274";
|
328 |
if (selectedProj == 0) |
329 |
return new ProjectionPool().get("EPSG:4"+datum); |
330 |
else if (selectedProj == 1) |
331 |
return new ProjectionPool().get("EPSG:"+datum+"92"); |
332 |
|
333 |
} else if (selectedDatum == 3) { |
334 |
datum = "267";
|
335 |
if (selectedProj == 0) |
336 |
return new ProjectionPool().get("EPSG:4"+datum); |
337 |
else if (selectedProj == 1) { |
338 |
String zone = Integer.toString(selectedZone + 3); |
339 |
if (selectedZone+3 <= 9) zone = "0" + zone; |
340 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
341 |
} |
342 |
|
343 |
} else if (selectedDatum == 4) { |
344 |
datum = "269";
|
345 |
if (selectedProj == 0) |
346 |
return new ProjectionPool().get("EPSG:4"+datum); |
347 |
else if (selectedProj == 1) { |
348 |
String zone = Integer.toString(selectedZone + 3); |
349 |
if (selectedZone+3 <= 9) zone = "0" + zone; |
350 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
351 |
} else if (selectedProj == 2) |
352 |
return new ProjectionPool().get("EPSG:42304"); |
353 |
|
354 |
} else if (selectedDatum == 5) { |
355 |
datum = "247";
|
356 |
if (selectedProj == 0) |
357 |
return new ProjectionPool().get("EPSG:4"+datum); |
358 |
else if (selectedProj == 1) { |
359 |
String zone = Integer.toString(selectedZone + 18); |
360 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
361 |
} |
362 |
|
363 |
} else if (selectedDatum == 6) { |
364 |
datum = "807";
|
365 |
if (selectedProj == 0) |
366 |
return new ProjectionPool().get("EPSG:4"+datum); |
367 |
else if (selectedProj == 1) |
368 |
return new ProjectionPool().get("EPSG:27582"); |
369 |
|
370 |
} else if (selectedDatum == 7) { |
371 |
datum = "258";
|
372 |
if (selectedProj == 0) |
373 |
return new ProjectionPool().get("EPSG:4"+datum); |
374 |
else if (selectedProj == 1) { |
375 |
String zone = Integer.toString(selectedZone + 28); |
376 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
377 |
} |
378 |
|
379 |
} else if (selectedDatum == 8) { |
380 |
datum = "30100";
|
381 |
return new ProjectionPool().get("IAU2000:" + datum); |
382 |
|
383 |
} else if (selectedDatum == 9) { |
384 |
datum = "49900";
|
385 |
return new ProjectionPool().get("IAU2000:" + datum); |
386 |
|
387 |
} else if (selectedDatum == 10) { |
388 |
datum = "221";
|
389 |
if (selectedProj == 0) |
390 |
return new ProjectionPool().get("EPSG:4"+datum); |
391 |
else if (selectedProj == 1) { |
392 |
String zone = Integer.toString(selectedZone + 1); |
393 |
return new ProjectionPool().get("EPSG:" + datum + "9"+ zone); |
394 |
} |
395 |
|
396 |
} else if (selectedDatum == 11) { |
397 |
if (selectedProj == 0) |
398 |
return new ProjectionPool().get("EPSG:4171"); |
399 |
else if (selectedProj == 1) |
400 |
return new ProjectionPool().get("EPSG:2154"); |
401 |
} |
402 |
|
403 |
if (selectedProj == 2) { |
404 |
return new ProjectionPool().get("EPSG:27492"); |
405 |
} else if (selectedProj == 3) { |
406 |
return new ProjectionPool().get("EPSG:42101"); |
407 |
} else if (selectedProj == 4) { |
408 |
return new ProjectionPool().get("EPSG:42304"); |
409 |
} else if (selectedProj == 5) { |
410 |
return new ProjectionPool().get("EPSG:27582"); |
411 |
} else if (selectedProj == 6) { |
412 |
return new ProjectionPool().get("EPSG:2154"); |
413 |
} else if (selectedProj == 7) { |
414 |
return new ProjectionPool().get("EPSG:9804"); |
415 |
} else if (selectedProj == 8) { |
416 |
datum = "221";
|
417 |
String zone = "9"; |
418 |
//if (selectedDatum == 10) {
|
419 |
if (selectedZone < 1) { |
420 |
zone += "1";
|
421 |
} else if (selectedZone > 7) { |
422 |
zone += "7";
|
423 |
} else
|
424 |
zone += (selectedZone+1)+""; |
425 |
// }
|
426 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
427 |
} |
428 |
|
429 |
|
430 |
if (selectedProj == 0) { |
431 |
return new ProjectionPool().get("EPSG:4" + datum); |
432 |
} else if (selectedProj == 1) { |
433 |
String Zone = Integer.toString(selectedZone + 1); |
434 |
|
435 |
if (selectedZone < 9) { |
436 |
Zone = "0" + Zone;
|
437 |
} |
438 |
|
439 |
if ((selectedDatum == 2) || (selectedDatum == 3)) { |
440 |
if (selectedZone < 3) { |
441 |
Zone = "03";
|
442 |
} |
443 |
|
444 |
if (selectedZone > 23) { |
445 |
Zone = "23";
|
446 |
} |
447 |
} |
448 |
|
449 |
if (selectedDatum == 5) { |
450 |
if (selectedZone < 18) { |
451 |
Zone = "18";
|
452 |
} |
453 |
|
454 |
if (selectedZone > 22) { |
455 |
Zone = "22";
|
456 |
} |
457 |
} |
458 |
|
459 |
if (selectedDatum == 7) { |
460 |
if (selectedZone < 28) { |
461 |
Zone = "28";
|
462 |
} |
463 |
|
464 |
if (selectedZone > 38) { |
465 |
Zone = "38";
|
466 |
} |
467 |
} |
468 |
return new ProjectionPool().get("EPSG:" + datum + Zone); |
469 |
} |
470 |
|
471 |
return proj;
|
472 |
} |
473 |
} |