root / branches / v10 / libraries / libCq CMS for java.old / src / org / cresques / ui / cts / CSSelectionModel.java @ 8005
History | View | Annotate | Download (15.1 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 |
} |
153 |
} |
154 |
|
155 |
public int getSelectedDatum() { |
156 |
return selectedDatum;
|
157 |
} |
158 |
|
159 |
public void setSelectedProj(int opNr) { |
160 |
selectedProj = opNr; |
161 |
} |
162 |
|
163 |
public void setSelectedProj(Object item) { |
164 |
String[] list = projList[getSelectedDatum()]; |
165 |
|
166 |
for (int i = 0; i < list.length; i++) |
167 |
if (list[i].compareTo((String) item) == 0) { |
168 |
selectedProj = i; |
169 |
} |
170 |
} |
171 |
|
172 |
public int getSelectedProj() { |
173 |
return selectedProj;
|
174 |
} |
175 |
|
176 |
public int getSelectedProjType() { |
177 |
return projType[getSelectedDatum()][selectedProj];
|
178 |
} |
179 |
|
180 |
public void setSelectedZone(int opNr) { |
181 |
selectedZone = opNr; |
182 |
} |
183 |
|
184 |
public void setSelectedZone(Object item) { |
185 |
String[] list = zoneList; |
186 |
|
187 |
for (int i = 0; i < list.length; i++) |
188 |
if (list[i].compareTo((String) item) == 0) { |
189 |
selectedZone = i; |
190 |
} |
191 |
} |
192 |
|
193 |
public int getSelectedZone() { |
194 |
return selectedZone;
|
195 |
} |
196 |
|
197 |
public void setProjection(IProjection proj) { |
198 |
String key = proj.getAbrev();
|
199 |
// Para usos posteriores.
|
200 |
// String db = key.split(":")[0];
|
201 |
key = key.split(":")[1]; |
202 |
|
203 |
setSelectedProj(0);
|
204 |
setSelectedZone(-1);
|
205 |
|
206 |
if (key.endsWith("4326")) { |
207 |
setSelectedDatum(0);
|
208 |
} else if (key.endsWith("4230")) { |
209 |
setSelectedDatum(1);
|
210 |
} else if (key.endsWith("4274")) { |
211 |
setSelectedDatum(2);
|
212 |
} else if (key.endsWith("4267")) { |
213 |
setSelectedDatum(3);
|
214 |
} else if (key.endsWith("4269")) { |
215 |
setSelectedDatum(4);
|
216 |
} else if (key.endsWith("4247")) { |
217 |
setSelectedDatum(5);
|
218 |
} else if (key.endsWith("4807")) { |
219 |
setSelectedDatum(6);
|
220 |
} else if (key.endsWith("4258")) { |
221 |
setSelectedDatum(7);
|
222 |
} else if (key.endsWith("30100")) { |
223 |
setSelectedDatum(8);
|
224 |
} else if (key.endsWith("49900")) { |
225 |
setSelectedDatum(9);
|
226 |
} else if (key.endsWith("4221")) { |
227 |
setSelectedDatum(10);
|
228 |
} else if (key.endsWith("4171")) { |
229 |
setSelectedDatum(11);
|
230 |
} else if (key.startsWith("326")) { |
231 |
setSelectedDatum(0);
|
232 |
setSelectedProj(1);
|
233 |
setSelectedZone(Integer.parseInt(key.substring(3)) - 1); |
234 |
} else if (key.startsWith("230")) { |
235 |
setSelectedDatum(1);
|
236 |
setSelectedProj(1);
|
237 |
setSelectedZone(Integer.parseInt(key.substring(3)) - 1); |
238 |
} else if (key.startsWith("267")) { |
239 |
setSelectedDatum(3);
|
240 |
setSelectedProj(1);
|
241 |
setSelectedZone(Integer.parseInt(key.substring(3)) - 1); |
242 |
} else if (key.startsWith("269")) { |
243 |
setSelectedDatum(4);
|
244 |
setSelectedProj(1);
|
245 |
setSelectedZone(Integer.parseInt(key.substring(3)) - 1); |
246 |
} else if (key.startsWith("247")) { |
247 |
setSelectedDatum(5);
|
248 |
setSelectedProj(1);
|
249 |
setSelectedZone(Integer.parseInt(key.substring(3)) - 1); |
250 |
} else if (key.startsWith("258")) { |
251 |
setSelectedDatum(7);
|
252 |
setSelectedProj(1);
|
253 |
setSelectedZone(Integer.parseInt(key.substring(3)) - 1); |
254 |
} else if (key.startsWith("221")) { |
255 |
setSelectedDatum(10);
|
256 |
setSelectedProj(1);
|
257 |
setSelectedZone(Integer.parseInt(key.substring(3)) - 1); |
258 |
} else if (key.endsWith("27492")) { // Datum 73 / Modified Portuguese Grid |
259 |
setSelectedDatum(2);
|
260 |
setSelectedProj(1);
|
261 |
setSelectedZone(-1);
|
262 |
} else if (key.endsWith("42101")) { // WGS 84 / LCC Canada |
263 |
setSelectedDatum(0);
|
264 |
setSelectedProj(2);
|
265 |
setSelectedZone(-1);
|
266 |
} else if (key.endsWith("9804")) { // WGS 84 / Mercator |
267 |
setSelectedDatum(0);
|
268 |
setSelectedProj(3);
|
269 |
setSelectedZone(-1);
|
270 |
} else if (key.endsWith("30100")) { // Moon |
271 |
setSelectedDatum(8);
|
272 |
setSelectedProj(0);
|
273 |
setSelectedZone(-1);
|
274 |
} else if (key.endsWith("49900")) { // Mars |
275 |
setSelectedDatum(9);
|
276 |
setSelectedProj(0);
|
277 |
setSelectedZone(-1);
|
278 |
} else if (key.endsWith("42304")) { // NAD83 / / LCC Canada |
279 |
setSelectedDatum(4);
|
280 |
setSelectedProj(2);
|
281 |
setSelectedZone(-1);
|
282 |
} else if (key.endsWith("27582")) { // NTFParis / / Lambert Etendu |
283 |
setSelectedDatum(5);
|
284 |
setSelectedProj(1);
|
285 |
setSelectedZone(-1);
|
286 |
} else {
|
287 |
System.err.println("CAGADA EN EL PARSING DE LA PROYECCION: " + key); |
288 |
} |
289 |
} |
290 |
|
291 |
public IProjection getProjection() {
|
292 |
IProjection proj = null;
|
293 |
String datum = "326"; |
294 |
|
295 |
if (selectedDatum == 0) { |
296 |
datum = "326";
|
297 |
if (selectedProj == 0) |
298 |
return new ProjectionPool().get("EPSG:4"+datum); |
299 |
else if (selectedProj == 1) { |
300 |
String zone = Integer.toString(selectedZone + 1); |
301 |
if (selectedZone < 9) zone = "0" + zone; |
302 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
303 |
} else if (selectedProj == 2) |
304 |
return new ProjectionPool().get("EPSG:42101"); |
305 |
else if (selectedProj == 3) |
306 |
return new ProjectionPool().get("EPSG:9804"); |
307 |
|
308 |
} else if (selectedDatum == 1) { |
309 |
datum = "230";
|
310 |
if (selectedProj == 0) |
311 |
return new ProjectionPool().get("EPSG:4"+datum); |
312 |
else if (selectedProj == 1) { |
313 |
String zone = Integer.toString(selectedZone + 1); |
314 |
if (selectedZone < 9) zone = "0" + zone; |
315 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
316 |
} |
317 |
|
318 |
} else if (selectedDatum == 2) { // Lisboa 73 |
319 |
datum = "274";
|
320 |
if (selectedProj == 0) |
321 |
return new ProjectionPool().get("EPSG:4"+datum); |
322 |
else if (selectedProj == 1) |
323 |
return new ProjectionPool().get("EPSG:"+datum+"92"); |
324 |
|
325 |
} else if (selectedDatum == 3) { |
326 |
datum = "267";
|
327 |
if (selectedProj == 0) |
328 |
return new ProjectionPool().get("EPSG:4"+datum); |
329 |
|
330 |
} else if (selectedDatum == 4) { |
331 |
datum = "269";
|
332 |
if (selectedProj == 0) |
333 |
return new ProjectionPool().get("EPSG:4"+datum); |
334 |
else if (selectedProj == 1) { |
335 |
String zone = Integer.toString(selectedZone + 4); |
336 |
if (selectedZone+3 < 9) zone = "0" + zone; |
337 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
338 |
} else if (selectedProj == 2) |
339 |
return new ProjectionPool().get("EPSG:42304"); |
340 |
|
341 |
} else if (selectedDatum == 5) { |
342 |
datum = "247";
|
343 |
if (selectedProj == 0) |
344 |
return new ProjectionPool().get("EPSG:4"+datum); |
345 |
else if (selectedProj == 1) { |
346 |
String zone = Integer.toString(selectedZone + 18); |
347 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
348 |
} |
349 |
|
350 |
} else if (selectedDatum == 6) { |
351 |
datum = "807";
|
352 |
if (selectedProj == 0) |
353 |
return new ProjectionPool().get("EPSG:4"+datum); |
354 |
else if (selectedProj == 1) |
355 |
return new ProjectionPool().get("EPSG:27582"); |
356 |
|
357 |
} else if (selectedDatum == 7) { |
358 |
datum = "258";
|
359 |
if (selectedProj == 0) |
360 |
return new ProjectionPool().get("EPSG:4"+datum); |
361 |
else if (selectedProj == 1) { |
362 |
String zone = Integer.toString(selectedZone + 28); |
363 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
364 |
} |
365 |
|
366 |
} else if (selectedDatum == 8) { |
367 |
datum = "30100";
|
368 |
return new ProjectionPool().get("IAU2000:" + datum); |
369 |
|
370 |
} else if (selectedDatum == 9) { |
371 |
datum = "49900";
|
372 |
return new ProjectionPool().get("IAU2000:" + datum); |
373 |
|
374 |
} else if (selectedDatum == 10) { |
375 |
datum = "221";
|
376 |
if (selectedProj == 0) |
377 |
return new ProjectionPool().get("EPSG:4"+datum); |
378 |
else if (selectedProj == 1) { |
379 |
String zone = Integer.toString(selectedZone + 1); |
380 |
return new ProjectionPool().get("EPSG:" + datum + "9"+ zone); |
381 |
} |
382 |
|
383 |
} else if (selectedDatum == 11) { |
384 |
if (selectedProj == 0) |
385 |
return new ProjectionPool().get("EPSG:4171"); |
386 |
else if (selectedProj == 1) |
387 |
return new ProjectionPool().get("EPSG:2154"); |
388 |
} |
389 |
|
390 |
if (selectedProj == 2) { |
391 |
return new ProjectionPool().get("EPSG:27492"); |
392 |
} else if (selectedProj == 3) { |
393 |
return new ProjectionPool().get("EPSG:42101"); |
394 |
} else if (selectedProj == 4) { |
395 |
return new ProjectionPool().get("EPSG:42304"); |
396 |
} else if (selectedProj == 5) { |
397 |
return new ProjectionPool().get("EPSG:27582"); |
398 |
} else if (selectedProj == 6) { |
399 |
return new ProjectionPool().get("EPSG:2154"); |
400 |
} else if (selectedProj == 7) { |
401 |
return new ProjectionPool().get("EPSG:9804"); |
402 |
} else if (selectedProj == 8) { |
403 |
datum = "221";
|
404 |
String zone = "9"; |
405 |
//if (selectedDatum == 10) {
|
406 |
if (selectedZone < 1) { |
407 |
zone += "1";
|
408 |
} else if (selectedZone > 7) { |
409 |
zone += "7";
|
410 |
} else
|
411 |
zone += (selectedZone+1)+""; |
412 |
// }
|
413 |
return new ProjectionPool().get("EPSG:" + datum + zone); |
414 |
} |
415 |
|
416 |
|
417 |
if (selectedProj == 0) { |
418 |
return new ProjectionPool().get("EPSG:4" + datum); |
419 |
} else if (selectedProj == 1) { |
420 |
String Zone = Integer.toString(selectedZone + 1); |
421 |
|
422 |
if (selectedZone < 9) { |
423 |
Zone = "0" + Zone;
|
424 |
} |
425 |
|
426 |
if ((selectedDatum == 2) || (selectedDatum == 3)) { |
427 |
if (selectedZone < 3) { |
428 |
Zone = "03";
|
429 |
} |
430 |
|
431 |
if (selectedZone > 23) { |
432 |
Zone = "23";
|
433 |
} |
434 |
} |
435 |
|
436 |
if (selectedDatum == 5) { |
437 |
if (selectedZone < 18) { |
438 |
Zone = "18";
|
439 |
} |
440 |
|
441 |
if (selectedZone > 22) { |
442 |
Zone = "22";
|
443 |
} |
444 |
} |
445 |
|
446 |
if (selectedDatum == 7) { |
447 |
if (selectedZone < 28) { |
448 |
Zone = "28";
|
449 |
} |
450 |
|
451 |
if (selectedZone > 38) { |
452 |
Zone = "38";
|
453 |
} |
454 |
} |
455 |
return new ProjectionPool().get("EPSG:" + datum + Zone); |
456 |
} |
457 |
|
458 |
return proj;
|
459 |
} |
460 |
} |