Revision 279 org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.common/src/main/java/org/gvsig/crs/gui/panels/TransformationEpsgPanel.java
TransformationEpsgPanel.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ibez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha) |
|
34 |
* Campus Universitario s/n |
|
35 |
* 02071 Alabacete |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 967 599 200 |
|
39 |
*/ |
|
40 |
|
|
41 |
package org.gvsig.crs.gui.panels; |
|
42 |
|
|
43 |
import java.awt.BorderLayout; |
|
44 |
import java.awt.Component; |
|
45 |
import java.awt.Dimension; |
|
46 |
import java.sql.ResultSet; |
|
47 |
import java.sql.SQLException; |
|
48 |
import java.util.ArrayList; |
|
49 |
|
|
50 |
import javax.swing.BorderFactory; |
|
51 |
import javax.swing.JPanel; |
|
52 |
import javax.swing.JScrollPane; |
|
53 |
import javax.swing.JTable; |
|
54 |
import javax.swing.JTextArea; |
|
55 |
import javax.swing.ListSelectionModel; |
|
56 |
import javax.swing.table.DefaultTableModel; |
|
57 |
import javax.swing.table.TableColumn; |
|
58 |
|
|
59 |
import org.cresques.cts.IProjection; |
|
60 |
import org.gvsig.andami.PluginServices; |
|
61 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
62 |
import org.gvsig.app.gui.TableSorter; |
|
63 |
import org.gvsig.crs.CrsFactory; |
|
64 |
import org.gvsig.crs.ICrs; |
|
65 |
import org.gvsig.crs.persistence.RecentTrsPersistence; |
|
66 |
import org.gvsig.crs.persistence.TrData; |
|
67 |
|
|
68 |
|
|
69 |
import org.slf4j.Logger; |
|
70 |
import org.slf4j.LoggerFactory; |
|
71 |
|
|
72 |
import es.idr.teledeteccion.connection.EpsgConnection; |
|
73 |
import es.idr.teledeteccion.connection.Query; |
|
74 |
|
|
75 |
/** |
|
76 |
* Clase para la creacin y el manejo del panel de transformacin |
|
77 |
* para el caso de la EPSG |
|
78 |
* |
|
79 |
* @author Jos Luis Gmez Martnez (jolugomar@gmail.com) |
|
80 |
* @author Luisa Marina Fernndez (luisam.fernandez@uclm.es) |
|
81 |
* |
|
82 |
*/ |
|
83 |
public class TransformationEpsgPanel extends JPanel { |
|
84 |
public static final Logger logger = LoggerFactory.getLogger(TransformationEpsgPanel.class); |
|
85 |
/** |
|
86 |
* |
|
87 |
*/ |
|
88 |
private static final long serialVersionUID = 1L; |
|
89 |
private IProjection firstProj; |
|
90 |
|
|
91 |
String[] transformations = {"9603", "9606", "9607", "9613", "9615", "9633"}; |
|
92 |
|
|
93 |
private int transformation_code = -1; |
|
94 |
private String[] values; |
|
95 |
private String params = "+towgs84="; |
|
96 |
|
|
97 |
private JTable transformationTable; |
|
98 |
private JScrollPane jScrollPane = null; |
|
99 |
public boolean inverseTranformation = false; |
|
100 |
|
|
101 |
public EpsgConnection connect = null; |
|
102 |
public int crs_target = -1; |
|
103 |
|
|
104 |
public DefaultTableModel dtm = null; |
|
105 |
|
|
106 |
private int crs_source_code; |
|
107 |
private String cadWKT = ""; |
|
108 |
private ListSelectionModel lsm2 = null; |
|
109 |
public int selectedRowTable = -1; |
|
110 |
boolean tra = false; |
|
111 |
int real_target; |
|
112 |
String authority_target = ""; |
|
113 |
|
|
114 |
private JTextArea info; |
|
115 |
public TableSorter sorter = null; |
|
116 |
|
|
117 |
public TransformationEpsgPanel(String aut_target) { |
|
118 |
connect = new EpsgConnection(); |
|
119 |
connect.setConnectionEPSG(); |
|
120 |
String[] authority_target = aut_target.split(":"); |
|
121 |
setAuthorityTarget(authority_target[0]); |
|
122 |
int target = Integer.parseInt(authority_target[1]); |
|
123 |
real_target = target; |
|
124 |
String sentence = "SELECT source_geogcrs_code, coord_ref_sys_kind " + |
|
125 |
"FROM epsg_coordinatereferencesystem " + |
|
126 |
"WHERE coord_ref_sys_code = "+ target ; |
|
127 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
128 |
try { |
|
129 |
result.next(); |
|
130 |
String kind = result.getString("coord_ref_sys_kind"); |
|
131 |
if (kind.equals("projected")) |
|
132 |
target = result.getInt("source_geogcrs_code"); |
|
133 |
} catch (SQLException e1) { |
|
134 |
logger.info("Can't get values from resulset, sentence="+sentence+".",e1); |
|
135 |
} |
|
136 |
crs_target = target; |
|
137 |
initialize(); |
|
138 |
} |
|
139 |
|
|
140 |
private void initialize(){ |
|
141 |
setLayout(new BorderLayout(1,50)); |
|
142 |
setBorder( |
|
143 |
BorderFactory.createCompoundBorder( |
|
144 |
BorderFactory.createCompoundBorder( |
|
145 |
BorderFactory.createTitledBorder("Transformacion EPSG"), |
|
146 |
BorderFactory.createEmptyBorder(12,2,80,2)), |
|
147 |
getBorder())); |
|
148 |
add(getJScrollPane(),BorderLayout.CENTER); |
|
149 |
} |
|
150 |
|
|
151 |
private Component getInfo() { |
|
152 |
if (info == null){ |
|
153 |
info = new JTextArea(); |
|
154 |
info.setLineWrap(true); |
|
155 |
info.setWrapStyleWord(true); |
|
156 |
info.setPreferredSize(new Dimension(400, 240)); |
|
157 |
info.setEditable(false); |
|
158 |
info.append(getWKT()); |
|
159 |
} |
|
160 |
info.setText(getWKT()); |
|
161 |
return info; |
|
162 |
} |
|
163 |
|
|
164 |
public JTable getJTable() { |
|
165 |
if (transformationTable == null) { |
|
166 |
String[] columnNames= {PluginServices.getText(this,"code_transformation"), |
|
167 |
PluginServices.getText(this,"name_transformation"), |
|
168 |
PluginServices.getText(this,"type_transformation"), |
|
169 |
PluginServices.getText(this,"source_crs"), |
|
170 |
PluginServices.getText(this,"target_crs"), |
|
171 |
PluginServices.getText(this,"description_area")}; |
|
172 |
Object[][]data = {}; |
|
173 |
dtm = new DefaultTableModel(data, columnNames) |
|
174 |
{ |
|
175 |
private static final long serialVersionUID = 1L; |
|
176 |
public boolean isCellEditable(int row, int column) { |
|
177 |
return false; |
|
178 |
} |
|
179 |
/* |
|
180 |
* metodo necesario para cuando utilizamos tablas ordenadas |
|
181 |
* ya que sino al ordenar por algun campo no se queda con el orden |
|
182 |
* actual al seleccionar una fila (non-Javadoc) |
|
183 |
* @see javax.swing.table.TableModel#getColumnClass(int) |
|
184 |
*/ |
|
185 |
public Class getColumnClass(int column) |
|
186 |
{ |
|
187 |
return getValueAt(0, column).getClass(); |
|
188 |
} |
|
189 |
}; |
|
190 |
sorter = new TableSorter(dtm); |
|
191 |
|
|
192 |
transformationTable = new JTable(sorter); |
|
193 |
sorter.setTableHeader(transformationTable.getTableHeader()); |
|
194 |
transformationTable.setCellSelectionEnabled(false); |
|
195 |
transformationTable.setRowSelectionAllowed(true); |
|
196 |
transformationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
|
197 |
transformationTable.setColumnSelectionAllowed(false); |
|
198 |
transformationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
199 |
TableColumn column = null; |
|
200 |
for (int i = 0; i < columnNames.length; i++) { |
|
201 |
column = transformationTable.getColumnModel().getColumn(i); |
|
202 |
if (i == 0 || i == 3 || i == 4) { |
|
203 |
column.setPreferredWidth(40); |
|
204 |
}else if (i == 2) { |
|
205 |
column.setPreferredWidth(80); |
|
206 |
} |
|
207 |
else { |
|
208 |
column.setPreferredWidth(160); |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
return transformationTable; |
|
213 |
} |
|
214 |
|
|
215 |
private JScrollPane getJScrollPane() { |
|
216 |
if (jScrollPane == null) { |
|
217 |
jScrollPane = new JScrollPane(); |
|
218 |
jScrollPane.setPreferredSize(new Dimension(525,200)); |
|
219 |
jScrollPane.setBorder( |
|
220 |
BorderFactory.createCompoundBorder( |
|
221 |
BorderFactory.createCompoundBorder( |
|
222 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"transformations")), |
|
223 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
|
224 |
jScrollPane.getBorder())); |
|
225 |
jScrollPane.setViewportView(getJTable()); |
|
226 |
} |
|
227 |
return jScrollPane; |
|
228 |
} |
|
229 |
|
|
230 |
/** |
|
231 |
* Busca las tranformaciones directas entre el CRS de la capa y el CRS de la |
|
232 |
* vista. |
|
233 |
* @param crsCode |
|
234 |
*/ |
|
235 |
private void callTransformation(int _crsCode){ |
|
236 |
|
|
237 |
int crsCode = _crsCode; |
|
238 |
|
|
239 |
String sentence = "SELECT source_geogcrs_code " + |
|
240 |
"FROM epsg_coordinatereferencesystem " + |
|
241 |
"WHERE coord_ref_sys_code = "+ crsCode ; |
|
242 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
243 |
int source = 0; |
|
244 |
try { |
|
245 |
result.next(); |
|
246 |
source = result.getInt("source_geogcrs_code"); |
|
247 |
} catch (SQLException e1) { |
|
248 |
logger.info("Can't get values from resulset, sentence="+sentence+".",e1); |
|
249 |
} |
|
250 |
|
|
251 |
ResultSet result2 = null; |
|
252 |
ResultSet result3 = null; |
|
253 |
if (source != 0){ |
|
254 |
crsCode = source; |
|
255 |
} |
|
256 |
|
|
257 |
ArrayList codecs = new ArrayList(); |
|
258 |
codecs.add(String.valueOf(crsCode)); |
|
259 |
|
|
260 |
for (int j=0; j< codecs.size(); j++){ |
|
261 |
sentence = "SELECT coord_op_code, coord_op_name, coord_op_type, source_crs_code, target_crs_code, area_of_use_code, coord_op_method_code " + |
|
262 |
"FROM epsg_coordoperation " + |
|
263 |
"WHERE source_crs_code = " + codecs.get(j) + "AND target_crs_code = " + crs_target; |
|
264 |
|
|
265 |
result = Query.select(sentence,connect.getConnection()); |
|
266 |
|
|
267 |
try { |
|
268 |
while(result.next()) { |
|
269 |
Object[]data = new Object[6]; |
|
270 |
data[0] = String.valueOf(result.getInt("coord_op_code")); |
|
271 |
data[1] = result.getString("coord_op_name"); |
|
272 |
data[2] = result.getString("coord_op_type"); |
|
273 |
data[3] = String.valueOf(result.getInt("source_crs_code")); |
|
274 |
data[4] = String.valueOf(result.getInt("target_crs_code")); |
|
275 |
/*codecs.add(data[4]); |
|
276 |
codecs = deleteItems(codecs);*/ |
|
277 |
|
|
278 |
int aouc = Integer.parseInt(result.getString("area_of_use_code")); |
|
279 |
|
|
280 |
sentence = "SELECT area_of_use FROM epsg_area " + |
|
281 |
"WHERE area_code = "+ aouc ; |
|
282 |
|
|
283 |
result2 = Query.select(sentence,connect.getConnection()); |
|
284 |
while (result2.next()) |
|
285 |
data[5] = result2.getString("area_of_use"); |
|
286 |
|
|
287 |
String coord_op_method = result.getString("coord_op_method_code"); |
|
288 |
|
|
289 |
sentence = "SELECT reverse_op FROM epsg_coordoperationmethod "+ |
|
290 |
"WHERE coord_op_method_code LIKE " + coord_op_method; |
|
291 |
result3 = Query.select(sentence,connect.getConnection()); |
|
292 |
|
|
293 |
while(result3.next()){ |
|
294 |
if (Integer.parseInt(result3.getString("reverse_op")) == 1){ |
|
295 |
for (int i=0; i< transformations.length; i++){ |
|
296 |
if (coord_op_method.equals(transformations[i])){ |
|
297 |
dtm.addRow(data); |
|
298 |
} |
|
299 |
} |
|
300 |
} |
|
301 |
} |
|
302 |
} |
|
303 |
} |
|
304 |
catch (SQLException e1) { |
|
305 |
logger.info("Can't get values from resulset.",e1); |
|
306 |
} |
|
307 |
} |
|
308 |
} |
|
309 |
|
|
310 |
/** |
|
311 |
* Mtodo auxiliar para eliminar valores repetidos dentro del ArrayList |
|
312 |
* de codecs. |
|
313 |
* @param codecs |
|
314 |
* @return |
|
315 |
*/ |
|
316 |
private ArrayList deleteItems(ArrayList codecs) { |
|
317 |
ArrayList cod = new ArrayList(); |
|
318 |
boolean equal = false; |
|
319 |
for (int i = 0; i< codecs.size(); i++){ |
|
320 |
String c = (String) codecs.get(i); |
|
321 |
for (int j = 0; j<cod.size(); j++){ |
|
322 |
if (cod.get(j).equals(c)){ |
|
323 |
equal = true; |
|
324 |
} |
|
325 |
} |
|
326 |
if (!equal){ |
|
327 |
cod.add(c); |
|
328 |
} |
|
329 |
equal = false; |
|
330 |
} |
|
331 |
return cod; |
|
332 |
} |
|
333 |
|
|
334 |
/** |
|
335 |
* Busca las tranformaciones inversas entre el CRS de la capa y el CRS de la |
|
336 |
* vista. Aquellas cuyo valor de reverse_op sean iguales a uno. |
|
337 |
* @param crsCode |
|
338 |
*/ |
|
339 |
private void callInverseTransformation(int _crsCode){ |
|
340 |
|
|
341 |
int crsCode = _crsCode; |
|
342 |
//inverseTranformation = true; |
|
343 |
|
|
344 |
String sentence = "SELECT source_geogcrs_code " + |
|
345 |
"FROM epsg_coordinatereferencesystem " + |
|
346 |
"WHERE coord_ref_sys_code = "+ crsCode ; |
|
347 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
348 |
int source = 0; |
|
349 |
try { |
|
350 |
result.next(); |
|
351 |
source = result.getInt("source_geogcrs_code"); |
|
352 |
} catch (SQLException e1) { |
|
353 |
logger.info("Can't get value 'source_geogcrs_code' from resulset, sentence="+sentence+".",e1); |
|
354 |
} |
|
355 |
|
|
356 |
ResultSet result2 = null; |
|
357 |
ResultSet result3 = null; |
|
358 |
if (source != 0){ |
|
359 |
crsCode = source; |
|
360 |
} |
|
361 |
|
|
362 |
ArrayList codecs = new ArrayList(); |
|
363 |
codecs.add(String.valueOf(crsCode)); |
|
364 |
|
|
365 |
codecs = deleteItems(codecs); |
|
366 |
|
|
367 |
for (int j=0; j< codecs.size(); j++){ |
|
368 |
sentence = "SELECT coord_op_code, coord_op_name, coord_op_type, source_crs_code, target_crs_code, area_of_use_code, coord_op_method_code " + |
|
369 |
"FROM epsg_coordoperation " + |
|
370 |
"WHERE source_crs_code = " + codecs.get(j) + "AND target_crs_code = " + crs_target; |
|
371 |
|
|
372 |
result = Query.select(sentence,connect.getConnection()); |
|
373 |
|
|
374 |
try { |
|
375 |
while(result.next()) { |
|
376 |
Object[]data = new Object[6]; |
|
377 |
data[0] = String.valueOf(result.getInt("coord_op_code")); |
|
378 |
data[1] = result.getString("coord_op_name"); |
|
379 |
data[2] = result.getString("coord_op_type"); |
|
380 |
data[4] = String.valueOf(result.getInt("source_crs_code")); |
|
381 |
data[3] = String.valueOf(result.getInt("target_crs_code")); |
|
382 |
/*codecs.add(data[4]); |
|
383 |
codecs = deleteItems(codecs);*/ |
|
384 |
|
|
385 |
int aouc = Integer.parseInt(result.getString("area_of_use_code")); |
|
386 |
|
|
387 |
sentence = "SELECT area_of_use FROM epsg_area " + |
|
388 |
"WHERE area_code = "+ aouc ; |
|
389 |
|
|
390 |
result2 = Query.select(sentence,connect.getConnection()); |
|
391 |
while (result2.next()) |
|
392 |
data[5] = result2.getString("area_of_use"); |
|
393 |
|
|
394 |
String coord_op_method = result.getString("coord_op_method_code"); |
|
395 |
|
|
396 |
sentence = "SELECT reverse_op FROM epsg_coordoperationmethod "+ |
|
397 |
"WHERE coord_op_method_code LIKE " + coord_op_method; |
|
398 |
result3 = Query.select(sentence,connect.getConnection()); |
|
399 |
|
|
400 |
while(result3.next()){ |
|
401 |
if (Integer.parseInt(result3.getString("reverse_op")) == 1){ |
|
402 |
for (int i=0; i< transformations.length; i++){ |
|
403 |
if (coord_op_method.equals(transformations[i])){ |
|
404 |
dtm.addRow(data); |
|
405 |
} |
|
406 |
} |
|
407 |
} |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
catch (SQLException e1) { |
|
412 |
logger.info("Can't get values from resulset.",e1); |
|
413 |
|
|
414 |
} |
|
415 |
} |
|
416 |
} |
|
417 |
|
|
418 |
/** |
|
419 |
* |
|
420 |
* @param val |
|
421 |
*/ |
|
422 |
public void setValues(String[] val) { |
|
423 |
values = val; |
|
424 |
} |
|
425 |
|
|
426 |
/** |
|
427 |
* |
|
428 |
* @return |
|
429 |
*/ |
|
430 |
public String[] getValues() { |
|
431 |
return values; |
|
432 |
} |
|
433 |
|
|
434 |
/** |
|
435 |
* |
|
436 |
* @param t_cod |
|
437 |
*/ |
|
438 |
public void setTrasformation_code(int t_cod) { |
|
439 |
transformation_code = t_cod; |
|
440 |
} |
|
441 |
|
|
442 |
/** |
|
443 |
* |
|
444 |
* @return |
|
445 |
*/ |
|
446 |
public int getTransformation_code() { |
|
447 |
return transformation_code; |
|
448 |
} |
|
449 |
|
|
450 |
/** |
|
451 |
* |
|
452 |
* @return |
|
453 |
*/ |
|
454 |
public ICrs getProjection() { |
|
455 |
params += values[0]; |
|
456 |
for(int i = 1; i < values.length; i++) |
|
457 |
params +=","+values[i]; |
|
458 |
try { |
|
459 |
//ICrs crs = new CrsFactory().getCRS(crs_source_code,cadWKT,params); |
|
460 |
ICrs crs = new CrsFactory().getCRS("EPSG:"+crs_source_code); |
|
461 |
crs.setTransformationParams(params,null); |
|
462 |
return crs; |
|
463 |
} catch (org.gvsig.crs.CrsException e) { |
|
464 |
logger.info("Can't create EPSG CRS with code "+crs_source_code+" and transformation params '"+params+"'.",e); |
|
465 |
} |
|
466 |
return null; |
|
467 |
} |
|
468 |
|
|
469 |
/** |
|
470 |
* |
|
471 |
* @param proj |
|
472 |
*/ |
|
473 |
public void setProjection(IProjection proj) { |
|
474 |
firstProj = proj; |
|
475 |
} |
|
476 |
|
|
477 |
/** |
|
478 |
* |
|
479 |
* @param cad |
|
480 |
*/ |
|
481 |
public void setWKT(String cad){ |
|
482 |
cadWKT = cad; |
|
483 |
getInfo(); |
|
484 |
} |
|
485 |
|
|
486 |
/** |
|
487 |
* |
|
488 |
* @return |
|
489 |
*/ |
|
490 |
public String getWKT(){ |
|
491 |
return cadWKT; |
|
492 |
} |
|
493 |
|
|
494 |
/** |
|
495 |
* Indica el CRS que se utilizar en la capa y busca las transformaciones |
|
496 |
* directas e inversas que pueda tener |
|
497 |
* @param code |
|
498 |
*/ |
|
499 |
public void setSource(String fuente, int code){ |
|
500 |
connect = new EpsgConnection(); |
|
501 |
connect.setConnectionEPSG(); |
|
502 |
inverseTranformation = false; |
|
503 |
crs_source_code = code; |
|
504 |
int numRow = dtm.getRowCount(); |
|
505 |
|
|
506 |
while (numRow != 0) { |
|
507 |
numRow = numRow - 1; |
|
508 |
dtm.removeRow(numRow); |
|
509 |
} |
|
510 |
if (PluginServices.getText(this, fuente).equals(PluginServices.getText(this, "EPSG")) && |
|
511 |
PluginServices.getText(this, getAuthorityTarget()).equals(PluginServices.getText(this, "EPSG"))) { |
|
512 |
|
|
513 |
searchTransformationsForEpsgSource(code); |
|
514 |
} |
|
515 |
} |
|
516 |
|
|
517 |
/** |
|
518 |
* |
|
519 |
*/ |
|
520 |
private void searchTransformationsForEpsgSource(int src_code) { |
|
521 |
callTransformation(crs_source_code); |
|
522 |
|
|
523 |
int new_target = crs_target; |
|
524 |
int base_target = src_code; |
|
525 |
String sentence = "SELECT source_geogcrs_code, coord_ref_sys_kind " + |
|
526 |
"FROM epsg_coordinatereferencesystem " + |
|
527 |
"WHERE coord_ref_sys_code = "+ src_code; |
|
528 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
529 |
try { |
|
530 |
result.next(); |
|
531 |
String kind = result.getString("coord_ref_sys_kind"); |
|
532 |
if (kind.equals("projected")) |
|
533 |
base_target = result.getInt("source_geogcrs_code"); |
|
534 |
} catch (SQLException e1) { |
|
535 |
logger.info("Can't get values 'coord_ref_sys_kind/source_geogcrs_code' from resulset, sentence="+sentence+".",e1); |
|
536 |
} |
|
537 |
crs_target = base_target; |
|
538 |
|
|
539 |
crs_source_code = new_target; |
|
540 |
callInverseTransformation(crs_source_code); |
|
541 |
|
|
542 |
crs_target = new_target; |
|
543 |
crs_source_code = src_code; |
|
544 |
|
|
545 |
int numr = dtm.getRowCount(); |
|
546 |
if (numr > 0 ){ |
|
547 |
this.getJTable().setRowSelectionInterval(0,0); |
|
548 |
} |
|
549 |
} |
|
550 |
|
|
551 |
/** |
|
552 |
* Indica el CRS que se utilizar en la capa y busca las transformaciones |
|
553 |
* directas e inversas que pueda tener para las transformaciones compuestas |
|
554 |
* @param code |
|
555 |
*/ |
|
556 |
public void setSourceCompuesta(String aut){ |
|
557 |
connect = new EpsgConnection(); |
|
558 |
connect.setConnectionEPSG(); |
|
559 |
inverseTranformation = false; |
|
560 |
String[] authority = aut.split(":"); |
|
561 |
int code = Integer.parseInt(authority[1]); |
|
562 |
crs_source_code = code; |
|
563 |
int numRow = dtm.getRowCount(); |
|
564 |
|
|
565 |
while (numRow != 0) { |
|
566 |
numRow = numRow - 1; |
|
567 |
dtm.removeRow(numRow); |
|
568 |
} |
|
569 |
if (PluginServices.getText(this,authority[0]).equals(PluginServices.getText(this, "EPSG"))) { |
|
570 |
callTransformationCompuesta(crs_source_code); |
|
571 |
|
|
572 |
int new_target = crs_target; |
|
573 |
int base_target = code; |
|
574 |
String sentence = "SELECT source_geogcrs_code, coord_ref_sys_kind " + |
|
575 |
"FROM epsg_coordinatereferencesystem " + |
|
576 |
"WHERE coord_ref_sys_code = "+ code; |
|
577 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
578 |
try { |
|
579 |
result.next(); |
|
580 |
String kind = result.getString("coord_ref_sys_kind"); |
|
581 |
if (kind.equals("projected")) |
|
582 |
base_target = result.getInt("source_geogcrs_code"); |
|
583 |
} catch (SQLException e1) { |
|
584 |
logger.info("Can't get values 'coord_ref_sys_kind/source_geogcrs_code' from resulset, sentence="+sentence+".",e1); |
|
585 |
} |
|
586 |
crs_target = base_target; |
|
587 |
|
|
588 |
crs_source_code = new_target; |
|
589 |
callInverseTransformation(crs_source_code); |
|
590 |
crs_target = new_target; |
|
591 |
crs_source_code = code; |
|
592 |
|
|
593 |
int numr = dtm.getRowCount(); |
|
594 |
if (numr > 0 ){ |
|
595 |
this.getJTable().setRowSelectionInterval(0,0); |
|
596 |
} |
|
597 |
} |
|
598 |
} |
|
599 |
|
|
600 |
/** |
|
601 |
* Busca las tranformaciones directas entre el CRS de la capa y el CRS de la |
|
602 |
* vista. |
|
603 |
* @param crsCode |
|
604 |
*/ |
|
605 |
private void callTransformationCompuesta(int crsCode){ |
|
606 |
int numRow = dtm.getRowCount(); |
|
607 |
|
|
608 |
while (numRow != 0) { |
|
609 |
numRow = numRow - 1; |
|
610 |
dtm.removeRow(numRow); |
|
611 |
} |
|
612 |
|
|
613 |
String sentence = "SELECT source_geogcrs_code " + |
|
614 |
"FROM epsg_coordinatereferencesystem " + |
|
615 |
"WHERE coord_ref_sys_code = "+ crsCode ; |
|
616 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
617 |
int source = 0; |
|
618 |
try { |
|
619 |
result.next(); |
|
620 |
source = result.getInt("source_geogcrs_code"); |
|
621 |
} catch (SQLException e1) { |
|
622 |
logger.info("Can't get value 'source_geogcrs_code' from resulset, sentence="+sentence+".",e1); |
|
623 |
} |
|
624 |
|
|
625 |
ResultSet result2 = null; |
|
626 |
ResultSet result3 = null; |
|
627 |
if (source != 0){ |
|
628 |
crsCode = source; |
|
629 |
} |
|
630 |
|
|
631 |
ArrayList codecs = new ArrayList(); |
|
632 |
codecs.add(String.valueOf(crsCode)); |
|
633 |
|
|
634 |
for (int j=0; j< codecs.size(); j++){ |
|
635 |
sentence = "SELECT coord_op_code, coord_op_name, coord_op_type, source_crs_code, target_crs_code, area_of_use_code, coord_op_method_code " + |
|
636 |
"FROM epsg_coordoperation " + |
|
637 |
"WHERE source_crs_code = " + codecs.get(j) + " OR target_crs_code = "+ codecs.get(j); |
|
638 |
|
|
639 |
result = Query.select(sentence,connect.getConnection()); |
|
640 |
|
|
641 |
try { |
|
642 |
while(result.next()) { |
|
643 |
Object[]data = new Object[6]; |
|
644 |
data[0] = String.valueOf(result.getInt("coord_op_code")); |
|
645 |
data[1] = result.getString("coord_op_name"); |
|
646 |
data[2] = result.getString("coord_op_type"); |
|
647 |
data[3] = String.valueOf(result.getInt("source_crs_code")); |
|
648 |
data[4] = String.valueOf(result.getInt("target_crs_code")); |
|
649 |
/*codecs.add(data[4]); |
|
650 |
codecs = deleteItems(codecs);*/ |
|
651 |
|
|
652 |
int aouc = Integer.parseInt(result.getString("area_of_use_code")); |
|
653 |
|
|
654 |
sentence = "SELECT area_of_use FROM epsg_area " + |
|
655 |
"WHERE area_code = "+ aouc ; |
|
656 |
|
|
657 |
result2 = Query.select(sentence,connect.getConnection()); |
|
658 |
while (result2.next()) |
|
659 |
data[5] = result2.getString("area_of_use"); |
|
660 |
|
|
661 |
String coord_op_method = result.getString("coord_op_method_code"); |
|
662 |
|
|
663 |
sentence = "SELECT reverse_op FROM epsg_coordoperationmethod "+ |
|
664 |
"WHERE coord_op_method_code LIKE " + coord_op_method; |
|
665 |
result3 = Query.select(sentence,connect.getConnection()); |
|
666 |
|
|
667 |
while(result3.next()){ |
|
668 |
if (Integer.parseInt(result3.getString("reverse_op")) == 1){ |
|
669 |
for (int i=0; i< transformations.length; i++){ |
|
670 |
if (coord_op_method.equals(transformations[i])){ |
|
671 |
dtm.addRow(data); |
|
672 |
} |
|
673 |
} |
|
674 |
} |
|
675 |
} |
|
676 |
} |
|
677 |
} |
|
678 |
catch (SQLException e1) { |
|
679 |
logger.info("Can't get values resulset.",e1); |
|
680 |
} |
|
681 |
} |
|
682 |
} |
|
683 |
|
|
684 |
/** |
|
685 |
* |
|
686 |
* @return |
|
687 |
*/ |
|
688 |
public int getSource(){ |
|
689 |
return crs_source_code; |
|
690 |
} |
|
691 |
|
|
692 |
public int getTarget(){ |
|
693 |
return real_target; |
|
694 |
} |
|
695 |
|
|
696 |
public void setAuthorityTarget(String aut_target) { |
|
697 |
authority_target = aut_target; |
|
698 |
} |
|
699 |
|
|
700 |
public String getAuthorityTarget() { |
|
701 |
return authority_target; |
|
702 |
} |
|
703 |
|
|
704 |
/** |
|
705 |
* cuando utilizamos crs+transformacion, cargamos los paneles para que |
|
706 |
* el usuario pueda consultar la transformacion utilizada... |
|
707 |
* @param details |
|
708 |
*/ |
|
709 |
public void fillData(String details) { |
|
710 |
RecentTrsPersistence trPersistence = new RecentTrsPersistence(); |
|
711 |
TrData crsTrDataArray[] = trPersistence.getArrayOfTrData(); |
|
712 |
|
|
713 |
for (int iRow = crsTrDataArray.length-1; iRow >= 0; iRow--) { |
|
714 |
if (details.equals(crsTrDataArray[iRow].getAuthority()+":"+crsTrDataArray[iRow].getCode()+" <--> "+crsTrDataArray[iRow].getDetails()) && crsTrDataArray[iRow].getAuthority().equals(PluginServices.getText(this, "EPSG"))) { |
|
715 |
String code = String.valueOf(crsTrDataArray[iRow].getCode()); |
|
716 |
|
|
717 |
for (int i=0; i< getJTable().getRowCount(); i++) { |
|
718 |
if (code.equals((String)getJTable().getValueAt(i, 0))) { |
|
719 |
//seleccionarlo |
|
720 |
this.getJTable().setRowSelectionInterval(i,i); |
|
721 |
break; |
|
722 |
} |
|
723 |
} |
|
724 |
break; |
|
725 |
} |
|
726 |
} |
|
727 |
} |
|
728 |
|
|
729 |
/** |
|
730 |
* metodo que resetea el formulario |
|
731 |
* @return |
|
732 |
*/ |
|
733 |
public void resetData() { |
|
734 |
if (dtm.getRowCount()>0) { |
|
735 |
this.getJTable().setRowSelectionInterval(0,0); |
|
736 |
} |
|
737 |
|
|
738 |
|
|
739 |
} |
|
740 |
|
|
741 |
public WindowInfo getWindowInfo() { |
|
742 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG); |
|
743 |
m_viewinfo.setTitle("Transformation EPSG"); |
|
744 |
return m_viewinfo; |
|
745 |
} |
|
746 |
|
|
747 |
} |
|
1 |
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ibez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha) |
|
34 |
* Campus Universitario s/n |
|
35 |
* 02071 Alabacete |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 967 599 200 |
|
39 |
*/ |
|
40 |
|
|
41 |
package org.gvsig.crs.gui.panels; |
|
42 |
|
|
43 |
import java.awt.BorderLayout; |
|
44 |
import java.awt.Component; |
|
45 |
import java.awt.Dimension; |
|
46 |
import java.sql.ResultSet; |
|
47 |
import java.sql.SQLException; |
|
48 |
import java.util.ArrayList; |
|
49 |
|
|
50 |
import javax.swing.BorderFactory; |
|
51 |
import javax.swing.JPanel; |
|
52 |
import javax.swing.JScrollPane; |
|
53 |
import javax.swing.JTable; |
|
54 |
import javax.swing.JTextArea; |
|
55 |
import javax.swing.ListSelectionModel; |
|
56 |
import javax.swing.table.DefaultTableModel; |
|
57 |
import javax.swing.table.TableColumn; |
|
58 |
|
|
59 |
import org.cresques.cts.IProjection; |
|
60 |
import org.gvsig.andami.PluginServices; |
|
61 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
62 |
import org.gvsig.app.gui.TableSorter; |
|
63 |
import org.gvsig.crs.CrsFactory; |
|
64 |
import org.gvsig.crs.ICrs; |
|
65 |
import org.gvsig.crs.persistence.RecentTrsPersistence; |
|
66 |
import org.gvsig.crs.persistence.TrData; |
|
67 |
|
|
68 |
|
|
69 |
import org.slf4j.Logger; |
|
70 |
import org.slf4j.LoggerFactory; |
|
71 |
|
|
72 |
import es.idr.teledeteccion.connection.EpsgConnection; |
|
73 |
import es.idr.teledeteccion.connection.Query; |
|
74 |
import org.gvsig.tools.ToolsLocator; |
|
75 |
|
|
76 |
/** |
|
77 |
* Clase para la creacin y el manejo del panel de transformacin |
|
78 |
* para el caso de la EPSG |
|
79 |
* |
|
80 |
* @author Jos Luis Gmez Martnez (jolugomar@gmail.com) |
|
81 |
* @author Luisa Marina Fernndez (luisam.fernandez@uclm.es) |
|
82 |
* |
|
83 |
*/ |
|
84 |
public class TransformationEpsgPanel extends JPanel { |
|
85 |
public static final Logger logger = LoggerFactory.getLogger(TransformationEpsgPanel.class); |
|
86 |
/** |
|
87 |
* |
|
88 |
*/ |
|
89 |
private static final long serialVersionUID = 1L; |
|
90 |
private IProjection firstProj; |
|
91 |
|
|
92 |
String[] transformations = {"9603", "9606", "9607", "9613", "9615", "9633"}; |
|
93 |
|
|
94 |
private int transformation_code = -1; |
|
95 |
private String[] values; |
|
96 |
private String params = "+towgs84="; |
|
97 |
|
|
98 |
private JTable transformationTable; |
|
99 |
private JScrollPane jScrollPane = null; |
|
100 |
public boolean inverseTranformation = false; |
|
101 |
|
|
102 |
public EpsgConnection connect = null; |
|
103 |
public int crs_target = -1; |
|
104 |
|
|
105 |
public DefaultTableModel dtm = null; |
|
106 |
|
|
107 |
private int crs_source_code; |
|
108 |
private String cadWKT = ""; |
|
109 |
private ListSelectionModel lsm2 = null; |
|
110 |
public int selectedRowTable = -1; |
|
111 |
boolean tra = false; |
|
112 |
int real_target; |
|
113 |
String authority_target = ""; |
|
114 |
|
|
115 |
private JTextArea info; |
|
116 |
public TableSorter sorter = null; |
|
117 |
|
|
118 |
public TransformationEpsgPanel(String aut_target) { |
|
119 |
connect = new EpsgConnection(); |
|
120 |
connect.setConnectionEPSG(); |
|
121 |
String[] authority_target = aut_target.split(":"); |
|
122 |
setAuthorityTarget(authority_target[0]); |
|
123 |
int target = Integer.parseInt(authority_target[1]); |
|
124 |
real_target = target; |
|
125 |
String sentence = "SELECT source_geogcrs_code, coord_ref_sys_kind " |
|
126 |
+ "FROM epsg_coordinatereferencesystem " |
|
127 |
+ "WHERE coord_ref_sys_code = " + target; |
|
128 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
129 |
try { |
|
130 |
result.next(); |
|
131 |
String kind = result.getString("coord_ref_sys_kind"); |
|
132 |
if (kind.equals("projected")) |
|
133 |
target = result.getInt("source_geogcrs_code"); |
|
134 |
} catch (SQLException e1) { |
|
135 |
logger.info("Can't get values from resulset, sentence="+sentence+".",e1); |
|
136 |
} |
|
137 |
crs_target = target; |
|
138 |
initialize(); |
|
139 |
} |
|
140 |
|
|
141 |
private void initialize(){ |
|
142 |
setLayout(new BorderLayout(1,50)); |
|
143 |
setBorder( |
|
144 |
BorderFactory.createCompoundBorder( |
|
145 |
BorderFactory.createCompoundBorder( |
|
146 |
BorderFactory.createTitledBorder( |
|
147 |
PluginServices.getText(this,"EPSG_transformation")), |
|
148 |
BorderFactory.createEmptyBorder(12,2,80,2)), |
|
149 |
getBorder())); |
|
150 |
add(getJScrollPane(),BorderLayout.CENTER); |
|
151 |
} |
|
152 |
|
|
153 |
private Component getInfo() { |
|
154 |
if (info == null){ |
|
155 |
info = new JTextArea(); |
|
156 |
info.setLineWrap(true); |
|
157 |
info.setWrapStyleWord(true); |
|
158 |
info.setPreferredSize(new Dimension(400, 240)); |
|
159 |
info.setEditable(false); |
|
160 |
info.append(getWKT()); |
|
161 |
} |
|
162 |
info.setText(getWKT()); |
|
163 |
return info; |
|
164 |
} |
|
165 |
|
|
166 |
public JTable getJTable() { |
|
167 |
if (transformationTable == null) { |
|
168 |
String[] columnNames= {PluginServices.getText(this,"code_transformation"), |
|
169 |
PluginServices.getText(this,"name_transformation"), |
|
170 |
PluginServices.getText(this,"type_transformation"), |
|
171 |
PluginServices.getText(this,"source_crs"), |
|
172 |
PluginServices.getText(this,"target_crs"), |
|
173 |
PluginServices.getText(this,"description_area")}; |
|
174 |
Object[][]data = {}; |
|
175 |
dtm = new DefaultTableModel(data, columnNames) |
|
176 |
{ |
|
177 |
private static final long serialVersionUID = 1L; |
|
178 |
public boolean isCellEditable(int row, int column) { |
|
179 |
return false; |
|
180 |
} |
|
181 |
/* |
|
182 |
* metodo necesario para cuando utilizamos tablas ordenadas |
|
183 |
* ya que sino al ordenar por algun campo no se queda con el orden |
|
184 |
* actual al seleccionar una fila (non-Javadoc) |
|
185 |
* @see javax.swing.table.TableModel#getColumnClass(int) |
|
186 |
*/ |
|
187 |
public Class getColumnClass(int column) |
|
188 |
{ |
|
189 |
return getValueAt(0, column).getClass(); |
|
190 |
} |
|
191 |
}; |
|
192 |
sorter = new TableSorter(dtm); |
|
193 |
|
|
194 |
transformationTable = new JTable(sorter); |
|
195 |
sorter.setTableHeader(transformationTable.getTableHeader()); |
|
196 |
transformationTable.setCellSelectionEnabled(false); |
|
197 |
transformationTable.setRowSelectionAllowed(true); |
|
198 |
transformationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
|
199 |
transformationTable.setColumnSelectionAllowed(false); |
|
200 |
transformationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
201 |
TableColumn column = null; |
|
202 |
for (int i = 0; i < columnNames.length; i++) { |
|
203 |
column = transformationTable.getColumnModel().getColumn(i); |
|
204 |
if (i == 0 || i == 3 || i == 4) { |
|
205 |
column.setPreferredWidth(40); |
|
206 |
}else if (i == 2) { |
|
207 |
column.setPreferredWidth(80); |
|
208 |
} |
|
209 |
else { |
|
210 |
column.setPreferredWidth(160); |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
return transformationTable; |
|
215 |
} |
|
216 |
|
|
217 |
private JScrollPane getJScrollPane() { |
|
218 |
if (jScrollPane == null) { |
|
219 |
jScrollPane = new JScrollPane(); |
|
220 |
jScrollPane.setPreferredSize(new Dimension(525,200)); |
|
221 |
jScrollPane.setBorder( |
|
222 |
BorderFactory.createCompoundBorder( |
|
223 |
BorderFactory.createCompoundBorder( |
|
224 |
BorderFactory.createTitledBorder( |
|
225 |
PluginServices.getText(this,"transformations")), |
|
226 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
|
227 |
jScrollPane.getBorder())); |
|
228 |
jScrollPane.setViewportView(getJTable()); |
|
229 |
} |
|
230 |
return jScrollPane; |
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* Busca las tranformaciones directas entre el CRS de la capa y el CRS de la |
|
235 |
* vista. |
|
236 |
* @param crsCode |
|
237 |
*/ |
|
238 |
private void callTransformation(int _crsCode){ |
|
239 |
|
|
240 |
int crsCode = _crsCode; |
|
241 |
String sentence = "SELECT source_geogcrs_code, coord_ref_sys_kind " |
|
242 |
+ "FROM epsg_coordinatereferencesystem " |
|
243 |
+ "WHERE coord_ref_sys_code = " + crsCode; |
|
244 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
245 |
int source = 0; |
|
246 |
try { |
|
247 |
result.next(); |
|
248 |
String kind = result.getString("coord_ref_sys_kind"); |
|
249 |
if (kind.equals("projected")) { |
|
250 |
source = result.getInt("source_geogcrs_code"); |
|
251 |
} else if (kind.equals("geographic 2D")) { |
|
252 |
source = crsCode; |
|
253 |
} else { |
|
254 |
// Se supone que por aqui no deberia de pasar, pero por si |
|
255 |
// acaso, le pongo un aviso en el log. |
|
256 |
logger.info("Unable to determine the reverse EPSG code (kind="+kind+",crsCode="+crsCode+")."); |
|
257 |
} |
|
258 |
} catch (SQLException e1) { |
|
259 |
logger.info("Can't get values from resulset, sentence="+sentence+".",e1); |
|
260 |
} |
|
261 |
|
|
262 |
ResultSet result2 = null; |
|
263 |
ResultSet result3 = null; |
|
264 |
if (source != 0){ |
|
265 |
crsCode = source; |
|
266 |
} |
|
267 |
|
|
268 |
ArrayList codecs = new ArrayList(); |
|
269 |
codecs.add(String.valueOf(crsCode)); |
|
270 |
|
|
271 |
for (int j=0; j< codecs.size(); j++){ |
|
272 |
sentence = "SELECT coord_op_code, coord_op_name, coord_op_type, source_crs_code, " |
|
273 |
+ "target_crs_code, area_of_use_code, coord_op_method_code " |
|
274 |
+ "FROM epsg_coordoperation WHERE source_crs_code = " |
|
275 |
+ codecs.get(j) + " AND target_crs_code = " + crs_target; |
|
276 |
|
|
277 |
result = Query.select(sentence,connect.getConnection()); |
|
278 |
|
|
279 |
try { |
|
280 |
while(result.next()) { |
|
281 |
Object[]data = new Object[6]; |
|
282 |
data[0] = String.valueOf(result.getInt("coord_op_code")); |
|
283 |
data[1] = result.getString("coord_op_name"); |
|
284 |
data[2] = result.getString("coord_op_type"); |
|
285 |
data[3] = String.valueOf(result.getInt("source_crs_code")); |
|
286 |
data[4] = String.valueOf(result.getInt("target_crs_code")); |
|
287 |
/*codecs.add(data[4]); |
|
288 |
codecs = deleteItems(codecs);*/ |
|
289 |
|
|
290 |
int aouc = Integer.parseInt(result.getString("area_of_use_code")); |
|
291 |
|
|
292 |
sentence = "SELECT area_of_use FROM epsg_area " |
|
293 |
+ "WHERE area_code = " + aouc; |
|
294 |
|
|
295 |
result2 = Query.select(sentence,connect.getConnection()); |
|
296 |
while (result2.next()) |
|
297 |
data[5] = result2.getString("area_of_use"); |
|
298 |
|
|
299 |
String coord_op_method = result.getString("coord_op_method_code"); |
|
300 |
|
|
301 |
sentence = "SELECT reverse_op FROM epsg_coordoperationmethod " |
|
302 |
+ "WHERE coord_op_method_code LIKE " + coord_op_method; |
|
303 |
result3 = Query.select(sentence,connect.getConnection()); |
|
304 |
|
|
305 |
while(result3.next()){ |
|
306 |
if (result3.getInt("reverse_op") == 1){ |
|
307 |
for (int i=0; i< transformations.length; i++){ |
|
308 |
if (coord_op_method.equals(transformations[i])){ |
|
309 |
dtm.addRow(data); |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
catch (SQLException e1) { |
|
317 |
logger.info("Can't get values from resulset.",e1); |
|
318 |
} |
|
319 |
} |
|
320 |
} |
|
321 |
|
|
322 |
/** |
|
323 |
* Mtodo auxiliar para eliminar valores repetidos dentro del ArrayList |
|
324 |
* de codecs. |
|
325 |
* @param codecs |
|
326 |
* @return |
|
327 |
*/ |
|
328 |
private ArrayList deleteItems(ArrayList codecs) { |
|
329 |
ArrayList cod = new ArrayList(); |
|
330 |
boolean equal = false; |
|
331 |
for (int i = 0; i< codecs.size(); i++){ |
|
332 |
String c = (String) codecs.get(i); |
|
333 |
for (int j = 0; j<cod.size(); j++){ |
|
334 |
if (cod.get(j).equals(c)){ |
|
335 |
equal = true; |
|
336 |
} |
|
337 |
} |
|
338 |
if (!equal){ |
|
339 |
cod.add(c); |
|
340 |
} |
|
341 |
equal = false; |
|
342 |
} |
|
343 |
return cod; |
|
344 |
} |
|
345 |
|
|
346 |
/** |
|
347 |
* Busca las tranformaciones inversas entre el CRS de la capa y el CRS de la |
|
348 |
* vista. Aquellas cuyo valor de reverse_op sean iguales a uno. |
|
349 |
* @param crsCode |
|
350 |
*/ |
|
351 |
private void callInverseTransformation(int _crsCode){ |
|
352 |
|
|
353 |
int crsCode = _crsCode; |
|
354 |
String sentence = "SELECT source_geogcrs_code, coord_ref_sys_kind " |
|
355 |
+ "FROM epsg_coordinatereferencesystem " |
|
356 |
+ "WHERE coord_ref_sys_code = " + crsCode; |
|
357 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
358 |
int source = 0; |
|
359 |
try { |
|
360 |
result.next(); |
|
361 |
String kind = result.getString("coord_ref_sys_kind"); |
|
362 |
if (kind.equals("projected")) { |
|
363 |
source = result.getInt("source_geogcrs_code"); |
|
364 |
} else if (kind.equals("geographic 2D")) { |
|
365 |
source = crsCode; |
|
366 |
} else { |
|
367 |
// Se supone que por aqui no deberia de pasar, pero por si |
|
368 |
// acaso, le pongo un aviso en el log. |
|
369 |
logger.info("Unable to determine the reverse EPSG code (kind="+kind+",crsCode="+crsCode+")."); |
|
370 |
} |
|
371 |
} catch (SQLException e1) { |
|
372 |
logger.info("Can't get value 'source_geogcrs_code' from resulset, sentence="+sentence+".",e1); |
|
373 |
} |
|
374 |
|
|
375 |
ResultSet result2 = null; |
|
376 |
ResultSet result3 = null; |
|
377 |
if (source != 0){ |
|
378 |
crsCode = source; |
|
379 |
} |
|
380 |
|
|
381 |
ArrayList codecs = new ArrayList(); |
|
382 |
codecs.add(String.valueOf(crsCode)); |
|
383 |
|
|
384 |
codecs = deleteItems(codecs); |
|
385 |
|
|
386 |
for (int j=0; j< codecs.size(); j++){ |
|
387 |
sentence = "SELECT coord_op_code, coord_op_name, coord_op_type, source_crs_code, " |
|
388 |
+ "target_crs_code, area_of_use_code, coord_op_method_code " |
|
389 |
+ "FROM epsg_coordoperation WHERE source_crs_code = " |
|
390 |
+ codecs.get(j) + " AND target_crs_code = " + crs_target; |
|
391 |
|
|
392 |
result = Query.select(sentence,connect.getConnection()); |
|
393 |
|
|
394 |
try { |
|
395 |
while(result.next()) { |
|
396 |
Object[]data = new Object[6]; |
|
397 |
data[0] = String.valueOf(result.getInt("coord_op_code")); |
|
398 |
data[1] = result.getString("coord_op_name"); |
|
399 |
data[2] = result.getString("coord_op_type"); |
|
400 |
data[4] = String.valueOf(result.getInt("source_crs_code")); |
|
401 |
data[3] = String.valueOf(result.getInt("target_crs_code")); |
|
402 |
/*codecs.add(data[4]); |
|
403 |
codecs = deleteItems(codecs);*/ |
|
404 |
|
|
405 |
int aouc = Integer.parseInt(result.getString("area_of_use_code")); |
|
406 |
|
|
407 |
sentence = "SELECT area_of_use FROM epsg_area " |
|
408 |
+ "WHERE area_code = " + aouc; |
|
409 |
|
|
410 |
result2 = Query.select(sentence,connect.getConnection()); |
|
411 |
while (result2.next()) |
|
412 |
data[5] = result2.getString("area_of_use"); |
|
413 |
|
|
414 |
String coord_op_method = result.getString("coord_op_method_code"); |
|
415 |
|
|
416 |
sentence = "SELECT reverse_op FROM epsg_coordoperationmethod " |
|
417 |
+ "WHERE coord_op_method_code LIKE " + coord_op_method; |
|
418 |
result3 = Query.select(sentence,connect.getConnection()); |
|
419 |
|
|
420 |
while(result3.next()){ |
|
421 |
if (Integer.parseInt(result3.getString("reverse_op")) == 1){ |
|
422 |
for (int i=0; i< transformations.length; i++){ |
|
423 |
if (coord_op_method.equals(transformations[i])){ |
|
424 |
dtm.addRow(data); |
|
425 |
} |
|
426 |
} |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 |
} |
|
431 |
catch (SQLException e1) { |
|
432 |
logger.info("Can't get values from resulset.",e1); |
|
433 |
|
|
434 |
} |
|
435 |
} |
|
436 |
} |
|
437 |
|
|
438 |
/** |
|
439 |
* |
|
440 |
* @param val |
|
441 |
*/ |
|
442 |
public void setValues(String[] val) { |
|
443 |
values = val; |
|
444 |
} |
|
445 |
|
|
446 |
/** |
|
447 |
* |
|
448 |
* @return |
|
449 |
*/ |
|
450 |
public String[] getValues() { |
|
451 |
return values; |
|
452 |
} |
|
453 |
|
|
454 |
/** |
|
455 |
* |
|
456 |
* @param t_cod |
|
457 |
*/ |
|
458 |
public void setTrasformation_code(int t_cod) { |
|
459 |
transformation_code = t_cod; |
|
460 |
} |
|
461 |
|
|
462 |
/** |
|
463 |
* |
|
464 |
* @return |
|
465 |
*/ |
|
466 |
public int getTransformation_code() { |
|
467 |
return transformation_code; |
|
468 |
} |
|
469 |
|
|
470 |
/** |
|
471 |
* |
|
472 |
* @return |
|
473 |
*/ |
|
474 |
public ICrs getProjection() { |
|
475 |
params += values[0]; |
|
476 |
for(int i = 1; i < values.length; i++) |
|
477 |
params +=","+values[i]; |
|
478 |
try { |
|
479 |
//ICrs crs = new CrsFactory().getCRS(crs_source_code,cadWKT,params); |
|
480 |
ICrs crs = new CrsFactory().getCRS("EPSG:"+crs_source_code); |
|
481 |
crs.setTransformationParams(params,null); |
|
482 |
return crs; |
|
483 |
} catch (org.gvsig.crs.CrsException e) { |
|
484 |
logger.info("Can't create EPSG CRS with code "+crs_source_code+" and transformation params '"+params+"'.",e); |
|
485 |
} |
|
486 |
return null; |
|
487 |
} |
|
488 |
|
|
489 |
/** |
|
490 |
* |
|
491 |
* @param proj |
|
492 |
*/ |
|
493 |
public void setProjection(IProjection proj) { |
|
494 |
firstProj = proj; |
|
495 |
} |
|
496 |
|
|
497 |
/** |
|
498 |
* |
|
499 |
* @param cad |
|
500 |
*/ |
|
501 |
public void setWKT(String cad){ |
|
502 |
cadWKT = cad; |
|
503 |
getInfo(); |
|
504 |
} |
|
505 |
|
|
506 |
/** |
|
507 |
* |
|
508 |
* @return |
|
509 |
*/ |
|
510 |
public String getWKT(){ |
|
511 |
return cadWKT; |
|
512 |
} |
|
513 |
|
|
514 |
/** |
|
515 |
* Indica el CRS que se utilizar en la capa y busca las transformaciones |
|
516 |
* directas e inversas que pueda tener |
|
517 |
* @param code |
|
518 |
*/ |
|
519 |
public void setSource(String fuente, int code){ |
|
520 |
connect = new EpsgConnection(); |
|
521 |
connect.setConnectionEPSG(); |
|
522 |
inverseTranformation = false; |
|
523 |
crs_source_code = code; |
|
524 |
int numRow = dtm.getRowCount(); |
|
525 |
|
|
526 |
while (numRow != 0) { |
|
527 |
numRow = numRow - 1; |
|
528 |
dtm.removeRow(numRow); |
|
529 |
} |
|
530 |
if (PluginServices.getText(this, fuente).equals(PluginServices.getText(this, "EPSG")) && |
|
531 |
PluginServices.getText(this, getAuthorityTarget()).equals(PluginServices.getText(this, "EPSG"))) { |
|
532 |
|
|
533 |
searchTransformationsForEpsgSource(code); |
|
534 |
} |
|
535 |
} |
|
536 |
|
|
537 |
/** |
|
538 |
* |
|
539 |
*/ |
|
540 |
private void searchTransformationsForEpsgSource(int src_code) { |
|
541 |
callTransformation(crs_source_code); |
|
542 |
|
|
543 |
int new_target = crs_target; |
|
544 |
int base_target = src_code; |
|
545 |
String sentence = "SELECT source_geogcrs_code, coord_ref_sys_kind " |
|
546 |
+ "FROM epsg_coordinatereferencesystem " |
|
547 |
+ "WHERE coord_ref_sys_code = " + src_code; |
|
548 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
549 |
try { |
|
550 |
result.next(); |
|
551 |
String kind = result.getString("coord_ref_sys_kind"); |
|
552 |
if (kind.equals("projected")) |
|
553 |
base_target = result.getInt("source_geogcrs_code"); |
|
554 |
} catch (SQLException e1) { |
|
555 |
logger.info("Can't get values 'coord_ref_sys_kind/source_geogcrs_code' from resulset, sentence="+sentence+".",e1); |
|
556 |
} |
|
557 |
crs_target = base_target; |
|
558 |
|
|
559 |
crs_source_code = new_target; |
|
560 |
callInverseTransformation(crs_source_code); |
|
561 |
|
|
562 |
crs_target = new_target; |
|
563 |
crs_source_code = src_code; |
|
564 |
|
|
565 |
int numr = dtm.getRowCount(); |
|
566 |
if (numr > 0 ){ |
|
567 |
this.getJTable().setRowSelectionInterval(0,0); |
|
568 |
} |
|
569 |
} |
|
570 |
|
|
571 |
/** |
|
572 |
* Indica el CRS que se utilizar en la capa y busca las transformaciones |
|
573 |
* directas e inversas que pueda tener para las transformaciones compuestas |
|
574 |
* @param code |
|
575 |
*/ |
|
576 |
public void setSourceCompuesta(String aut){ |
|
577 |
connect = new EpsgConnection(); |
|
578 |
connect.setConnectionEPSG(); |
|
579 |
inverseTranformation = false; |
|
580 |
String[] authority = aut.split(":"); |
|
581 |
int code = Integer.parseInt(authority[1]); |
|
582 |
crs_source_code = code; |
|
583 |
int numRow = dtm.getRowCount(); |
|
584 |
|
|
585 |
while (numRow != 0) { |
|
586 |
numRow = numRow - 1; |
|
587 |
dtm.removeRow(numRow); |
|
588 |
} |
|
589 |
if (PluginServices.getText(this,authority[0]).equals(PluginServices.getText(this, "EPSG"))) { |
|
590 |
callTransformationCompuesta(crs_source_code); |
|
591 |
|
|
592 |
int new_target = crs_target; |
|
593 |
int base_target = code; |
|
594 |
String sentence = "SELECT source_geogcrs_code, coord_ref_sys_kind " |
|
595 |
+ "FROM epsg_coordinatereferencesystem " |
|
596 |
+ "WHERE coord_ref_sys_code = " + code; |
|
597 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
598 |
try { |
|
599 |
result.next(); |
|
600 |
String kind = result.getString("coord_ref_sys_kind"); |
|
601 |
if (kind.equals("projected")) |
|
602 |
base_target = result.getInt("source_geogcrs_code"); |
|
603 |
} catch (SQLException e1) { |
|
604 |
logger.info("Can't get values 'coord_ref_sys_kind/source_geogcrs_code' from resulset, sentence="+sentence+".",e1); |
|
605 |
} |
|
606 |
crs_target = base_target; |
|
607 |
|
|
608 |
crs_source_code = new_target; |
|
609 |
callInverseTransformation(crs_source_code); |
|
610 |
crs_target = new_target; |
|
611 |
crs_source_code = code; |
|
612 |
|
|
613 |
int numr = dtm.getRowCount(); |
|
614 |
if (numr > 0 ){ |
|
615 |
this.getJTable().setRowSelectionInterval(0,0); |
|
616 |
} |
|
617 |
} |
|
618 |
} |
|
619 |
|
|
620 |
/** |
|
621 |
* Busca las tranformaciones directas entre el CRS de la capa y el CRS de la |
|
622 |
* vista. |
|
623 |
* @param crsCode |
|
624 |
*/ |
|
625 |
private void callTransformationCompuesta(int crsCode){ |
|
626 |
int numRow = dtm.getRowCount(); |
|
627 |
|
|
628 |
while (numRow != 0) { |
|
629 |
numRow = numRow - 1; |
|
630 |
dtm.removeRow(numRow); |
|
631 |
} |
|
632 |
|
|
633 |
String sentence = "SELECT source_geogcrs_code FROM epsg_coordinatereferencesystem " |
|
634 |
+ "WHERE coord_ref_sys_code = " + crsCode; |
|
635 |
ResultSet result = Query.select(sentence,connect.getConnection()); |
|
636 |
int source = 0; |
|
637 |
try { |
|
638 |
result.next(); |
|
639 |
source = result.getInt("source_geogcrs_code"); |
|
640 |
} catch (SQLException e1) { |
|
641 |
logger.info("Can't get value 'source_geogcrs_code' from resulset, sentence="+sentence+".",e1); |
|
642 |
} |
|
643 |
|
|
644 |
ResultSet result2 = null; |
|
645 |
ResultSet result3 = null; |
|
646 |
if (source != 0){ |
|
647 |
crsCode = source; |
|
648 |
} |
|
649 |
|
|
650 |
ArrayList codecs = new ArrayList(); |
|
651 |
codecs.add(String.valueOf(crsCode)); |
|
652 |
|
|
653 |
for (int j=0; j< codecs.size(); j++){ |
|
654 |
sentence = "SELECT coord_op_code, coord_op_name, coord_op_type, source_crs_code, " |
|
655 |
+ "target_crs_code, area_of_use_code, coord_op_method_code " |
|
656 |
+ "FROM epsg_coordoperation WHERE source_crs_code = " |
|
657 |
+ codecs.get(j) + " OR target_crs_code = " + codecs.get(j); |
|
658 |
|
|
659 |
result = Query.select(sentence,connect.getConnection()); |
|
660 |
|
|
661 |
try { |
|
662 |
while(result.next()) { |
|
663 |
Object[]data = new Object[6]; |
|
664 |
data[0] = String.valueOf(result.getInt("coord_op_code")); |
|
665 |
data[1] = result.getString("coord_op_name"); |
|
666 |
data[2] = result.getString("coord_op_type"); |
|
667 |
data[3] = String.valueOf(result.getInt("source_crs_code")); |
|
668 |
data[4] = String.valueOf(result.getInt("target_crs_code")); |
|
669 |
/*codecs.add(data[4]); |
|
670 |
codecs = deleteItems(codecs);*/ |
|
671 |
|
|
672 |
int aouc = Integer.parseInt(result.getString("area_of_use_code")); |
|
673 |
|
|
674 |
sentence = "SELECT area_of_use FROM epsg_area " |
|
675 |
+ "WHERE area_code = " + aouc; |
|
676 |
|
|
677 |
result2 = Query.select(sentence,connect.getConnection()); |
|
678 |
while (result2.next()) |
|
679 |
data[5] = result2.getString("area_of_use"); |
|
680 |
|
|
681 |
String coord_op_method = result.getString("coord_op_method_code"); |
|
682 |
|
|
683 |
sentence = "SELECT reverse_op FROM epsg_coordoperationmethod " |
|
684 |
+ "WHERE coord_op_method_code LIKE " + coord_op_method; |
|
685 |
result3 = Query.select(sentence,connect.getConnection()); |
|
686 |
|
|
687 |
while(result3.next()){ |
|
688 |
if (result3.getInt("reverse_op") == 1){ |
|
689 |
for (int i=0; i< transformations.length; i++){ |
|
690 |
if (coord_op_method.equals(transformations[i])){ |
|
691 |
dtm.addRow(data); |
|
692 |
} |
|
693 |
} |
|
694 |
} |
|
695 |
} |
|
696 |
} |
|
697 |
} |
|
698 |
catch (SQLException e1) { |
|
699 |
logger.info("Can't get values resulset.",e1); |
|
700 |
} |
|
701 |
} |
|
702 |
} |
|
703 |
|
|
704 |
/** |
|
705 |
* |
|
706 |
* @return |
|
707 |
*/ |
|
708 |
public int getSource(){ |
|
709 |
return crs_source_code; |
|
710 |
} |
|
711 |
|
|
712 |
public int getTarget(){ |
|
713 |
return real_target; |
|
714 |
} |
|
715 |
|
|
716 |
public void setAuthorityTarget(String aut_target) { |
|
717 |
authority_target = aut_target; |
|
718 |
} |
|
719 |
|
|
720 |
public String getAuthorityTarget() { |
|
721 |
return authority_target; |
|
722 |
} |
|
723 |
|
|
724 |
/** |
|
725 |
* cuando utilizamos crs+transformacion, cargamos los paneles para que |
|
726 |
* el usuario pueda consultar la transformacion utilizada... |
|
727 |
* @param details |
|
728 |
*/ |
|
729 |
public void fillData(String details) { |
|
730 |
RecentTrsPersistence trPersistence = new RecentTrsPersistence(); |
|
731 |
TrData crsTrDataArray[] = trPersistence.getArrayOfTrData(); |
|
732 |
|
|
733 |
for (int iRow = crsTrDataArray.length-1; iRow >= 0; iRow--) { |
|
734 |
if (details.equals(crsTrDataArray[iRow].getAuthority()+":"+crsTrDataArray[iRow].getCode()+" <--> "+crsTrDataArray[iRow].getDetails()) && crsTrDataArray[iRow].getAuthority().equals(PluginServices.getText(this, "EPSG"))) { |
|
735 |
String code = String.valueOf(crsTrDataArray[iRow].getCode()); |
|
736 |
|
|
737 |
for (int i=0; i< getJTable().getRowCount(); i++) { |
|
738 |
if (code.equals((String)getJTable().getValueAt(i, 0))) { |
|
739 |
//seleccionarlo |
|
740 |
this.getJTable().setRowSelectionInterval(i,i); |
|
741 |
break; |
|
742 |
} |
|
743 |
} |
|
744 |
break; |
|
745 |
} |
|
746 |
} |
|
747 |
} |
|
748 |
|
|
749 |
/** |
Also available in: Unified diff