svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / cts / CSSelectionModel.java @ 2312
History | View | Annotate | Download (5.9 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 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
31 |
*/
|
32 |
public class CSSelectionModel { |
33 |
public static int NONE = 0x01; |
34 |
public static int GEODETIC = 0x02; |
35 |
public static int TRANSVERSAL = 0x03; |
36 |
|
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 |
"Nouvelle Triangulation Francaise",
|
43 |
*/};
|
44 |
private String [] projList = { |
45 |
"Geodesica", "(UTM) Universal Transversal Mercator", |
46 |
"Datum 73 / Modified Portuguese Grid", "WGS 84 / LCC Canada", |
47 |
"NAD83 / NRCan LCC Canada"};
|
48 |
private int [] projType = {GEODETIC, TRANSVERSAL, NONE, NONE, NONE}; |
49 |
private String [] huseList = {}; |
50 |
private int selectedDatum = 0, selectedProj = 0, selectedHuse = 0; |
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
public CSSelectionModel() {
|
55 |
super();
|
56 |
huseList = new String[60]; |
57 |
for (int i=1; i<=60; i++) |
58 |
huseList[i-1] = "Huso "+Integer.toString(i); |
59 |
|
60 |
} |
61 |
|
62 |
public String [] getDatumList() { return datumList; } |
63 |
|
64 |
public String [] getProjectionList() { return projList; } |
65 |
|
66 |
public String [] getHuseList() { return huseList; } |
67 |
|
68 |
public void setSelectedDatum(int opNr) { selectedDatum = opNr; } |
69 |
public void setSelectedDatum(Object item) { |
70 |
String [] list = datumList; |
71 |
for (int i=0; i<list.length; i++) |
72 |
if (list[i].compareTo((String) item) == 0) |
73 |
selectedDatum = i; |
74 |
} |
75 |
public int getSelectedDatum() { return selectedDatum; } |
76 |
|
77 |
public void setSelectedProj(int opNr) { selectedProj = opNr; } |
78 |
public void setSelectedProj(Object item) { |
79 |
String [] list = projList; |
80 |
for (int i=0; i<list.length; i++) |
81 |
if (list[i].compareTo((String) item) == 0) |
82 |
selectedProj = i; |
83 |
} |
84 |
public int getSelectedProj() { return selectedProj; } |
85 |
public int getSelectedProjType() { return projType[selectedProj]; } |
86 |
|
87 |
public void setSelectedHuse(int opNr) { selectedHuse = opNr; } |
88 |
public void setSelectedHuse(Object item) { |
89 |
String [] list = huseList; |
90 |
for (int i=0; i<list.length; i++) |
91 |
if (list[i].compareTo((String) item) == 0) |
92 |
selectedHuse = i; |
93 |
} |
94 |
public int getSelectedHuse() { return selectedHuse; } |
95 |
|
96 |
public void setProjection(IProjection proj) { |
97 |
String key = proj.getAbrev();
|
98 |
key = key.substring(key.length()-5);
|
99 |
if (key.endsWith(":4326")) { |
100 |
setSelectedDatum(0);
|
101 |
setSelectedProj(0);
|
102 |
setSelectedHuse(-1);
|
103 |
} else if (key.endsWith(":4230")) { |
104 |
setSelectedDatum(1);
|
105 |
setSelectedProj(0);
|
106 |
setSelectedHuse(-1);
|
107 |
} else if (key.endsWith(":4267")) { |
108 |
setSelectedDatum(2);
|
109 |
setSelectedProj(0);
|
110 |
setSelectedHuse(-1);
|
111 |
} else if (key.endsWith(":4269")) { |
112 |
setSelectedDatum(3);
|
113 |
setSelectedProj(0);
|
114 |
setSelectedHuse(-1);
|
115 |
} else if (key.endsWith(":4247")) { |
116 |
setSelectedDatum(5);
|
117 |
setSelectedProj(0);
|
118 |
setSelectedHuse(-1);
|
119 |
} else if (key.startsWith("326")) { |
120 |
setSelectedDatum(0);
|
121 |
setSelectedProj(1);
|
122 |
setSelectedHuse(Integer.parseInt(key.substring(3))-1); |
123 |
} else if (key.startsWith("230")) { |
124 |
setSelectedDatum(1);
|
125 |
setSelectedProj(1);
|
126 |
setSelectedHuse(Integer.parseInt(key.substring(3))-1); |
127 |
} else if (key.startsWith("267")) { |
128 |
setSelectedDatum(2);
|
129 |
setSelectedProj(1);
|
130 |
setSelectedHuse(Integer.parseInt(key.substring(3))-1); |
131 |
} else if (key.startsWith("269")) { |
132 |
setSelectedDatum(3);
|
133 |
setSelectedProj(1);
|
134 |
setSelectedHuse(Integer.parseInt(key.substring(3))-1); |
135 |
} else if (key.startsWith("247")) { |
136 |
setSelectedDatum(3);
|
137 |
setSelectedProj(1);
|
138 |
setSelectedHuse(Integer.parseInt(key.substring(3))-1); |
139 |
} else if (key.startsWith("27492")) { // Datum 73 / Modified Portuguese Grid |
140 |
setSelectedDatum(-1);
|
141 |
setSelectedProj(2);
|
142 |
setSelectedHuse(-1);
|
143 |
} else if (key.startsWith("42101")) { // WGS 84 / LCC Canada |
144 |
setSelectedDatum(-1);
|
145 |
setSelectedProj(3);
|
146 |
setSelectedHuse(-1);
|
147 |
} else if (key.startsWith("42304")) { // NAD83 / / LCC Canada |
148 |
setSelectedDatum(-1);
|
149 |
setSelectedProj(4);
|
150 |
setSelectedHuse(-1);
|
151 |
} else
|
152 |
System.err.println("CAGADA EN EL PARSING DE LA PROYECCION: "+key); |
153 |
} |
154 |
|
155 |
public IProjection getProjection() {
|
156 |
if (selectedProj == 2) { |
157 |
return ProjectionPool.get("EPSG:27492"); |
158 |
} else if (selectedProj == 3) { |
159 |
return ProjectionPool.get("EPSG:42101"); |
160 |
} else if (selectedProj == 4) { |
161 |
return ProjectionPool.get("EPSG:42304"); |
162 |
} |
163 |
IProjection proj = null;
|
164 |
String datum= "326"; |
165 |
if (selectedDatum == 0) |
166 |
datum = "326";
|
167 |
else if (selectedDatum == 1) |
168 |
datum = "230";
|
169 |
else if (selectedDatum == 2) |
170 |
datum = "267";
|
171 |
else if (selectedDatum == 3) |
172 |
datum = "269";
|
173 |
else if (selectedDatum == 5) |
174 |
datum = "247";
|
175 |
if (selectedProj == 0) { |
176 |
return ProjectionPool.get("EPSG:4"+datum); |
177 |
} else if (selectedProj == 1) { |
178 |
String huse = Integer.toString(selectedHuse+1); |
179 |
if (selectedHuse < 9) huse = "0"+huse; |
180 |
if (selectedDatum == 2 || selectedDatum == 3) { |
181 |
if (selectedHuse < 3) huse = "03"; |
182 |
if (selectedHuse > 23) huse = "23"; |
183 |
} |
184 |
if (selectedDatum == 53) { |
185 |
if (selectedHuse < 18) huse = "18"; |
186 |
if (selectedHuse > 22) huse = "22"; |
187 |
} |
188 |
return ProjectionPool.get("EPSG:"+datum+huse); |
189 |
} |
190 |
return proj;
|
191 |
} |
192 |
} |
193 |
|
194 |
|