root / trunk / libraries / libCq_CMS_praster / src / org / cresques / ui / cts / CSSelectionModel.java @ 8026
History | View | Annotate | Download (7.68 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 |
"Nouvelle Triangulation Francaise",
|
43 |
*/
|
44 |
}; |
45 |
private String[] projList = { |
46 |
"Geodesica",
|
47 |
"(UTM) Universal Transversal Mercator",
|
48 |
"Datum 73 / Modified Portuguese Grid",
|
49 |
"WGS 84 / LCC Canada",
|
50 |
"NAD83 / NRCan LCC Canada"
|
51 |
}; |
52 |
private int[] projType = { GEODETIC, TRANSVERSAL, NONE, NONE, NONE }; |
53 |
private String[] huseList = { }; |
54 |
private int selectedDatum = 0; |
55 |
private int selectedProj = 0; |
56 |
private int selectedHuse = 0; |
57 |
|
58 |
/**
|
59 |
*
|
60 |
*/
|
61 |
public CSSelectionModel() {
|
62 |
super();
|
63 |
huseList = new String[60]; |
64 |
|
65 |
for (int i = 1; i <= 60; i++) |
66 |
huseList[i - 1] = "Huso " + Integer.toString(i); |
67 |
} |
68 |
|
69 |
public String[] getDatumList() { |
70 |
return datumList;
|
71 |
} |
72 |
|
73 |
public String[] getProjectionList() { |
74 |
return projList;
|
75 |
} |
76 |
|
77 |
public String[] getHuseList() { |
78 |
return huseList;
|
79 |
} |
80 |
|
81 |
public void setSelectedDatum(int opNr) { |
82 |
selectedDatum = opNr; |
83 |
} |
84 |
|
85 |
public void setSelectedDatum(Object item) { |
86 |
String[] list = datumList; |
87 |
|
88 |
for (int i = 0; i < list.length; i++) |
89 |
if (list[i].compareTo((String) item) == 0) { |
90 |
selectedDatum = i; |
91 |
} |
92 |
} |
93 |
|
94 |
public int getSelectedDatum() { |
95 |
return selectedDatum;
|
96 |
} |
97 |
|
98 |
public void setSelectedProj(int opNr) { |
99 |
selectedProj = opNr; |
100 |
} |
101 |
|
102 |
public void setSelectedProj(Object item) { |
103 |
String[] list = projList; |
104 |
|
105 |
for (int i = 0; i < list.length; i++) |
106 |
if (list[i].compareTo((String) item) == 0) { |
107 |
selectedProj = i; |
108 |
} |
109 |
} |
110 |
|
111 |
public int getSelectedProj() { |
112 |
return selectedProj;
|
113 |
} |
114 |
|
115 |
public int getSelectedProjType() { |
116 |
return projType[selectedProj];
|
117 |
} |
118 |
|
119 |
public void setSelectedHuse(int opNr) { |
120 |
selectedHuse = opNr; |
121 |
} |
122 |
|
123 |
public void setSelectedHuse(Object item) { |
124 |
String[] list = huseList; |
125 |
|
126 |
for (int i = 0; i < list.length; i++) |
127 |
if (list[i].compareTo((String) item) == 0) { |
128 |
selectedHuse = i; |
129 |
} |
130 |
} |
131 |
|
132 |
public int getSelectedHuse() { |
133 |
return selectedHuse;
|
134 |
} |
135 |
|
136 |
public void setProjection(IProjection proj) { |
137 |
String key = proj.getAbrev();
|
138 |
key = key.substring(key.length() - 5);
|
139 |
|
140 |
if (key.endsWith(":4326")) { |
141 |
setSelectedDatum(0);
|
142 |
setSelectedProj(0);
|
143 |
setSelectedHuse(-1);
|
144 |
} else if (key.endsWith(":4230")) { |
145 |
setSelectedDatum(1);
|
146 |
setSelectedProj(0);
|
147 |
setSelectedHuse(-1);
|
148 |
} else if (key.endsWith(":4267")) { |
149 |
setSelectedDatum(2);
|
150 |
setSelectedProj(0);
|
151 |
setSelectedHuse(-1);
|
152 |
} else if (key.endsWith(":4269")) { |
153 |
setSelectedDatum(3);
|
154 |
setSelectedProj(0);
|
155 |
setSelectedHuse(-1);
|
156 |
} else if (key.endsWith(":4247")) { |
157 |
setSelectedDatum(5);
|
158 |
setSelectedProj(0);
|
159 |
setSelectedHuse(-1);
|
160 |
} else if (key.startsWith("326")) { |
161 |
setSelectedDatum(0);
|
162 |
setSelectedProj(1);
|
163 |
setSelectedHuse(Integer.parseInt(key.substring(3)) - 1); |
164 |
} else if (key.startsWith("230")) { |
165 |
setSelectedDatum(1);
|
166 |
setSelectedProj(1);
|
167 |
setSelectedHuse(Integer.parseInt(key.substring(3)) - 1); |
168 |
} else if (key.startsWith("267")) { |
169 |
setSelectedDatum(2);
|
170 |
setSelectedProj(1);
|
171 |
setSelectedHuse(Integer.parseInt(key.substring(3)) - 1); |
172 |
} else if (key.startsWith("269")) { |
173 |
setSelectedDatum(3);
|
174 |
setSelectedProj(1);
|
175 |
setSelectedHuse(Integer.parseInt(key.substring(3)) - 1); |
176 |
} else if (key.startsWith("247")) { |
177 |
setSelectedDatum(3);
|
178 |
setSelectedProj(1);
|
179 |
setSelectedHuse(Integer.parseInt(key.substring(3)) - 1); |
180 |
} else if (key.startsWith("27492")) { // Datum 73 / Modified Portuguese Grid |
181 |
setSelectedDatum(-1);
|
182 |
setSelectedProj(2);
|
183 |
setSelectedHuse(-1);
|
184 |
} else if (key.startsWith("42101")) { // WGS 84 / LCC Canada |
185 |
setSelectedDatum(-1);
|
186 |
setSelectedProj(3);
|
187 |
setSelectedHuse(-1);
|
188 |
} else if (key.startsWith("42304")) { // NAD83 / / LCC Canada |
189 |
setSelectedDatum(-1);
|
190 |
setSelectedProj(4);
|
191 |
setSelectedHuse(-1);
|
192 |
} else {
|
193 |
System.err.println("CAGADA EN EL PARSING DE LA PROYECCION: " + key); |
194 |
} |
195 |
} |
196 |
|
197 |
public IProjection getProjection() {
|
198 |
if (selectedProj == 2) { |
199 |
return ProjectionPool.get("EPSG:27492"); |
200 |
} else if (selectedProj == 3) { |
201 |
return ProjectionPool.get("EPSG:42101"); |
202 |
} else if (selectedProj == 4) { |
203 |
return ProjectionPool.get("EPSG:42304"); |
204 |
} |
205 |
|
206 |
IProjection proj = null;
|
207 |
String datum = "326"; |
208 |
|
209 |
if (selectedDatum == 0) { |
210 |
datum = "326";
|
211 |
} else if (selectedDatum == 1) { |
212 |
datum = "230";
|
213 |
} else if (selectedDatum == 2) { |
214 |
datum = "267";
|
215 |
} else if (selectedDatum == 3) { |
216 |
datum = "269";
|
217 |
} else if (selectedDatum == 5) { |
218 |
datum = "247";
|
219 |
} |
220 |
|
221 |
if (selectedProj == 0) { |
222 |
return ProjectionPool.get("EPSG:4" + datum); |
223 |
} else if (selectedProj == 1) { |
224 |
String huse = Integer.toString(selectedHuse + 1); |
225 |
|
226 |
if (selectedHuse < 9) { |
227 |
huse = "0" + huse;
|
228 |
} |
229 |
|
230 |
if ((selectedDatum == 2) || (selectedDatum == 3)) { |
231 |
if (selectedHuse < 3) { |
232 |
huse = "03";
|
233 |
} |
234 |
|
235 |
if (selectedHuse > 23) { |
236 |
huse = "23";
|
237 |
} |
238 |
} |
239 |
|
240 |
if (selectedDatum == 53) { |
241 |
if (selectedHuse < 18) { |
242 |
huse = "18";
|
243 |
} |
244 |
|
245 |
if (selectedHuse > 22) { |
246 |
huse = "22";
|
247 |
} |
248 |
} |
249 |
|
250 |
return ProjectionPool.get("EPSG:" + datum + huse); |
251 |
} |
252 |
|
253 |
return proj;
|
254 |
} |
255 |
} |