root / trunk / extensions / extGeoProcessing / src / com / iver / gvsig / geoprocessing / gui / GeoProcessingPanel.java @ 4437
History | View | Annotate | Download (39.4 KB)
1 |
/*
|
---|---|
2 |
* Created on 01-jul-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.gvsig.geoprocessing.gui; |
45 |
|
46 |
import java.awt.BorderLayout; |
47 |
import java.awt.Component; |
48 |
import java.io.File; |
49 |
import java.io.IOException; |
50 |
import java.util.HashMap; |
51 |
import java.util.Map; |
52 |
|
53 |
import javax.swing.JButton; |
54 |
import javax.swing.JComboBox; |
55 |
import javax.swing.JDialog; |
56 |
import javax.swing.JOptionPane; |
57 |
import javax.swing.JPanel; |
58 |
|
59 |
import org.cresques.cts.IProjection; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.andami.ui.mdiManager.View; |
63 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
64 |
import com.iver.cit.gvsig.fmap.DriverException; |
65 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
66 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
67 |
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
68 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
69 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
71 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
72 |
import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingBufferPanel; |
73 |
import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingConvexHullPanel; |
74 |
import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingDissolvePanel; |
75 |
import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingMergePanel; |
76 |
import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingOperationSelectorPanel; |
77 |
import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingOverlayPanel; |
78 |
import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingSpatialjoinPanel; |
79 |
import com.iver.gvsig.geoprocessing.impl.buffer.BufferGeoprocess; |
80 |
import com.iver.gvsig.geoprocessing.impl.clip.ClipGeoprocess; |
81 |
import com.iver.gvsig.geoprocessing.impl.convexhull.ConvexHullGeoprocess; |
82 |
import com.iver.gvsig.geoprocessing.impl.difference.DifferenceGeoprocess; |
83 |
import com.iver.gvsig.geoprocessing.impl.dissolve.DissolveGeoprocess; |
84 |
import com.iver.gvsig.geoprocessing.impl.intersection.IntersectionGeoprocess; |
85 |
import com.iver.gvsig.geoprocessing.impl.spatialjoin.SpatialJoinGeoprocess; |
86 |
import com.iver.gvsig.geoprocessing.impl.union.UnionGeoprocess; |
87 |
import com.iver.gvsig.geoprocessing.model.GeoprocessException; |
88 |
import com.iver.gvsig.geoprocessing.model.IGeoprocess; |
89 |
import com.iver.utiles.swing.Crono; |
90 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
91 |
import com.iver.utiles.swing.threads.MonitorableDecorator; |
92 |
|
93 |
/**
|
94 |
* Container component panel of the Geoprocessing Wizard. It contains all
|
95 |
* spetialized panels to do geoprocessing. It is an Andami's View (it is added
|
96 |
* to ANDAMI like a JInternalFrame)
|
97 |
*
|
98 |
* @author jmorell, azabala
|
99 |
*/
|
100 |
public class GeoProcessingPanel extends JPanel implements View, |
101 |
GeoProcessingWizardIF, GeoProcessingIF { |
102 |
|
103 |
/*
|
104 |
* AZABALA Inicialmente queria usar el API Wizard de la libreria IVER
|
105 |
* UTILES. No obstante, ese API es para construir Wizards est?ticos, donde
|
106 |
* todas las fases/pantallas son las mismas: 1->2->3->...->FIN.
|
107 |
*
|
108 |
* El componente de GeoprocessingWizard est? pensado para que la pantalla 2
|
109 |
* sea distinta, en funci?n de la selecci?n que haya hecho el usuario en la
|
110 |
* pantalla 1.
|
111 |
*
|
112 |
* A falta de construir un API gen?rica de Wizards (que contemple
|
113 |
* bifurcaciones) conservamos la concepci?n original.
|
114 |
*/
|
115 |
|
116 |
private static final long serialVersionUID = 1L; |
117 |
|
118 |
private ViewInfo viewInfo = null; |
119 |
|
120 |
private GeoProcessingOperationSelectorPanel geoProcessingOperationSelectorPanel = null; |
121 |
|
122 |
private GeoProcessingBufferPanel geoProcessingBufferPanel = null; |
123 |
|
124 |
// FIXME podriamos reutilizar el mismo panel para todos los
|
125 |
// geoprocesos
|
126 |
private GeoProcessingOverlayPanel geoProcessingClipPanel = null; |
127 |
|
128 |
private GeoProcessingDissolvePanel geoProcessingDissolvePanel = null; |
129 |
|
130 |
private GeoProcessingMergePanel geoProcessingMergePanel = null; |
131 |
|
132 |
private GeoProcessingOverlayPanel geoProcessingIntersectPanel = null; |
133 |
|
134 |
private GeoProcessingOverlayPanel geoProcessingUnionPanel = null; |
135 |
|
136 |
private GeoProcessingOverlayPanel geoProcessingDifferencePanel = null; |
137 |
|
138 |
private GeoProcessingSpatialjoinPanel geoProcessingSpatialjoinPanel = null; |
139 |
|
140 |
private GeoProcessingConvexHullPanel geoProcessingConvexHullPanel = null; |
141 |
|
142 |
private JPanel buttonsPanel = null; |
143 |
|
144 |
private JButton closeButton = null; |
145 |
|
146 |
private JButton previousButton = null; |
147 |
|
148 |
private JButton nextButton = null; |
149 |
|
150 |
private JDialog crono = null; // @jve:decl-index=0:visual-constraint="431,15" |
151 |
|
152 |
private Crono cronoComponent;
|
153 |
|
154 |
private FLayers layers = null; |
155 |
|
156 |
/**
|
157 |
* FIXME No se esta utilizando. Revisar si es necesario
|
158 |
*/
|
159 |
private IProjection proj;
|
160 |
|
161 |
/**
|
162 |
* This constructor initializes the set of layers
|
163 |
*/
|
164 |
public GeoProcessingPanel(FLayers layers, IProjection proj) {
|
165 |
super();
|
166 |
this.layers = layers;
|
167 |
this.proj = proj;
|
168 |
initialize(); |
169 |
} |
170 |
|
171 |
// Methods that models public behabiour of wizard component
|
172 |
/**
|
173 |
* It closes geoprocessing wizard dialog
|
174 |
*/
|
175 |
public void closeDialog() { |
176 |
if (PluginServices.getMainFrame() == null) { |
177 |
// TODO Azabala: ni idea de porque 4 llamadas a getParent()
|
178 |
((JDialog) (getParent().getParent().getParent().getParent()))
|
179 |
.dispose(); |
180 |
} else {
|
181 |
PluginServices.getMDIManager().closeView(GeoProcessingPanel.this); |
182 |
} |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Shows previous wizard step
|
187 |
*/
|
188 |
public void previousStep() { |
189 |
showOptionSelectionPanel(); |
190 |
previousButton.setEnabled(false);
|
191 |
nextButton.setText(PluginServices.getText(this, "Siguiente")); |
192 |
|
193 |
} |
194 |
|
195 |
private void showBufferPanel() { |
196 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
197 |
getGeoProcessingBufferPanel().setVisible(true);
|
198 |
getGeoProcessingClipPanel().setVisible(false);
|
199 |
getGeoProcessingDissolvePanel().setVisible(false);
|
200 |
getGeoProcessingMergePanel().setVisible(false);
|
201 |
getGeoProcessingIntersectPanel().setVisible(false);
|
202 |
getGeoProcessingUnionPanel().setVisible(false);
|
203 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
204 |
getGeoProcessingDifferencePanel().setVisible(false);
|
205 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
206 |
} |
207 |
|
208 |
private void showClipPanel() { |
209 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
210 |
getGeoProcessingBufferPanel().setVisible(false);
|
211 |
getGeoProcessingClipPanel().setVisible(true);
|
212 |
getGeoProcessingDissolvePanel().setVisible(false);
|
213 |
getGeoProcessingMergePanel().setVisible(false);
|
214 |
getGeoProcessingIntersectPanel().setVisible(false);
|
215 |
getGeoProcessingUnionPanel().setVisible(false);
|
216 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
217 |
getGeoProcessingDifferencePanel().setVisible(false);
|
218 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
219 |
} |
220 |
|
221 |
private void showDissolvePanel() { |
222 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
223 |
getGeoProcessingBufferPanel().setVisible(false);
|
224 |
getGeoProcessingClipPanel().setVisible(false);
|
225 |
getGeoProcessingDissolvePanel().setVisible(true);
|
226 |
getGeoProcessingMergePanel().setVisible(false);
|
227 |
getGeoProcessingIntersectPanel().setVisible(false);
|
228 |
getGeoProcessingUnionPanel().setVisible(false);
|
229 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
230 |
getGeoProcessingDifferencePanel().setVisible(false);
|
231 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
232 |
} |
233 |
|
234 |
private void showMergePanel() { |
235 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
236 |
getGeoProcessingBufferPanel().setVisible(false);
|
237 |
getGeoProcessingClipPanel().setVisible(false);
|
238 |
getGeoProcessingDissolvePanel().setVisible(false);
|
239 |
getGeoProcessingMergePanel().setVisible(true);
|
240 |
getGeoProcessingIntersectPanel().setVisible(false);
|
241 |
getGeoProcessingUnionPanel().setVisible(false);
|
242 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
243 |
getGeoProcessingDifferencePanel().setVisible(false);
|
244 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
245 |
} |
246 |
|
247 |
private void showIntersectPanel() { |
248 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
249 |
getGeoProcessingBufferPanel().setVisible(false);
|
250 |
getGeoProcessingClipPanel().setVisible(false);
|
251 |
getGeoProcessingDissolvePanel().setVisible(false);
|
252 |
getGeoProcessingMergePanel().setVisible(false);
|
253 |
getGeoProcessingIntersectPanel().setVisible(true);
|
254 |
getGeoProcessingUnionPanel().setVisible(false);
|
255 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
256 |
getGeoProcessingDifferencePanel().setVisible(false);
|
257 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
258 |
} |
259 |
|
260 |
private void showUnionPanel() { |
261 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
262 |
getGeoProcessingBufferPanel().setVisible(false);
|
263 |
getGeoProcessingClipPanel().setVisible(false);
|
264 |
getGeoProcessingDissolvePanel().setVisible(false);
|
265 |
getGeoProcessingMergePanel().setVisible(false);
|
266 |
getGeoProcessingIntersectPanel().setVisible(false);
|
267 |
getGeoProcessingUnionPanel().setVisible(true);
|
268 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
269 |
getGeoProcessingDifferencePanel().setVisible(false);
|
270 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
271 |
} |
272 |
|
273 |
private void showSpatialJoinPanel() { |
274 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
275 |
getGeoProcessingBufferPanel().setVisible(false);
|
276 |
getGeoProcessingClipPanel().setVisible(false);
|
277 |
getGeoProcessingDissolvePanel().setVisible(false);
|
278 |
getGeoProcessingMergePanel().setVisible(false);
|
279 |
getGeoProcessingIntersectPanel().setVisible(false);
|
280 |
getGeoProcessingUnionPanel().setVisible(false);
|
281 |
getGeoProcessingSpatialjoinPanel().setVisible(true);
|
282 |
getGeoProcessingDifferencePanel().setVisible(false);
|
283 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
284 |
} |
285 |
|
286 |
private void showDifferencePanel() { |
287 |
getGeoProcessingDifferencePanel().setVisible(true);
|
288 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
289 |
getGeoProcessingBufferPanel().setVisible(false);
|
290 |
getGeoProcessingClipPanel().setVisible(false);
|
291 |
getGeoProcessingDissolvePanel().setVisible(false);
|
292 |
getGeoProcessingMergePanel().setVisible(false);
|
293 |
getGeoProcessingIntersectPanel().setVisible(false);
|
294 |
getGeoProcessingUnionPanel().setVisible(false);
|
295 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
296 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
297 |
} |
298 |
|
299 |
private void showOptionSelectionPanel() { |
300 |
getGeoProcessingOperationSelectorPanel().setVisible(true);
|
301 |
getGeoProcessingBufferPanel().setVisible(false);
|
302 |
getGeoProcessingClipPanel().setVisible(false);
|
303 |
getGeoProcessingDissolvePanel().setVisible(false);
|
304 |
getGeoProcessingMergePanel().setVisible(false);
|
305 |
getGeoProcessingIntersectPanel().setVisible(false);
|
306 |
getGeoProcessingUnionPanel().setVisible(false);
|
307 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
308 |
getGeoProcessingDifferencePanel().setVisible(false);
|
309 |
getGeoProcessingConvexHullPanel().setVisible(false);
|
310 |
} |
311 |
|
312 |
public void nextStep() { |
313 |
// 2? FASE DEL ASISTENTE
|
314 |
/*
|
315 |
* TODO No me gusta como esta planteado, a base de muchos if-else
|
316 |
* anidados. REVISAR
|
317 |
*/
|
318 |
if (nextButton.getText().equals(
|
319 |
PluginServices.getText(this, "Siguiente"))) { |
320 |
if (geoProcessingOperationSelectorPanel.isBufferSelected()) {// BUFFER |
321 |
showBufferPanel(); |
322 |
} else if (geoProcessingOperationSelectorPanel.isClipSelected()) {// CLIP |
323 |
showClipPanel(); |
324 |
} else if (geoProcessingOperationSelectorPanel.isDissolveSelected()) { |
325 |
showDissolvePanel(); |
326 |
} else if (geoProcessingOperationSelectorPanel.isMergeSelected()) { |
327 |
showMergePanel(); |
328 |
} else if (geoProcessingOperationSelectorPanel |
329 |
.isIntersectSelected()) { |
330 |
showIntersectPanel(); |
331 |
} else if (geoProcessingOperationSelectorPanel.isUnionSelected()) { |
332 |
showUnionPanel(); |
333 |
} else if (geoProcessingOperationSelectorPanel |
334 |
.isSpatialJoinSelected()) { |
335 |
showSpatialJoinPanel(); |
336 |
} else if (geoProcessingOperationSelectorPanel |
337 |
.isDifferenceSelected()) { |
338 |
showDifferencePanel(); |
339 |
} else if (geoProcessingOperationSelectorPanel |
340 |
.isConvexHullSelected()) { |
341 |
showConvexHullPanel(); |
342 |
} else {
|
343 |
previousStep(); |
344 |
return;
|
345 |
} |
346 |
previousButton.setEnabled(true);
|
347 |
nextButton.setText(PluginServices.getText(this, "Terminar")); |
348 |
|
349 |
} else if (nextButton.getText().equals( |
350 |
PluginServices.getText(this, "Terminar"))) { |
351 |
if (geoProcessingOperationSelectorPanel.isBufferSelected()) {
|
352 |
doBuffer(); |
353 |
} else if (geoProcessingOperationSelectorPanel.isClipSelected()) { |
354 |
doClip(); |
355 |
} else if (geoProcessingOperationSelectorPanel.isDissolveSelected()) { |
356 |
doDissolve(); |
357 |
} else if (geoProcessingOperationSelectorPanel.isMergeSelected()) { |
358 |
doMerge(); |
359 |
} else if (geoProcessingOperationSelectorPanel |
360 |
.isIntersectSelected()) { |
361 |
doIntersect(); |
362 |
} else if (geoProcessingOperationSelectorPanel.isUnionSelected()) { |
363 |
doUnion(); |
364 |
} else if (geoProcessingOperationSelectorPanel |
365 |
.isSpatialJoinSelected()) { |
366 |
doSpatialJoin(); |
367 |
} else if (geoProcessingOperationSelectorPanel |
368 |
.isConvexHullSelected()) { |
369 |
doConvexHull(); |
370 |
} else if (geoProcessingOperationSelectorPanel |
371 |
.isDifferenceSelected()) { |
372 |
doDifference(); |
373 |
} |
374 |
closeDialog(); |
375 |
} |
376 |
} |
377 |
|
378 |
private void showConvexHullPanel() { |
379 |
getGeoProcessingOperationSelectorPanel().setVisible(false);
|
380 |
getGeoProcessingBufferPanel().setVisible(false);
|
381 |
getGeoProcessingClipPanel().setVisible(false);
|
382 |
getGeoProcessingDissolvePanel().setVisible(false);
|
383 |
getGeoProcessingMergePanel().setVisible(false);
|
384 |
getGeoProcessingIntersectPanel().setVisible(false);
|
385 |
getGeoProcessingUnionPanel().setVisible(false);
|
386 |
getGeoProcessingSpatialjoinPanel().setVisible(false);
|
387 |
getGeoProcessingDifferencePanel().setVisible(false);
|
388 |
getGeoProcessingConvexHullPanel().setVisible(true);
|
389 |
} |
390 |
|
391 |
private Component getGeoProcessingConvexHullPanel() { |
392 |
if (geoProcessingConvexHullPanel == null) { |
393 |
geoProcessingConvexHullPanel = new GeoProcessingConvexHullPanel(
|
394 |
layers); |
395 |
geoProcessingConvexHullPanel |
396 |
.setName("geoProcessingConvexHullPanel");
|
397 |
geoProcessingConvexHullPanel |
398 |
.setPreferredSize(new java.awt.Dimension(300, 300)); |
399 |
} |
400 |
return geoProcessingConvexHullPanel;
|
401 |
} |
402 |
|
403 |
/**
|
404 |
* This method initializes this
|
405 |
*
|
406 |
* @return void
|
407 |
*/
|
408 |
private void initialize() { |
409 |
this.setLayout(new BorderLayout()); |
410 |
this.setSize(416, 317); |
411 |
this.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
|
412 |
this.add(getGeoProcessingOperationSelectorPanel(),
|
413 |
java.awt.BorderLayout.NORTH); |
414 |
this.add(getGeoProcessingBufferPanel(), java.awt.BorderLayout.NORTH);
|
415 |
this.add(getGeoProcessingClipPanel(), java.awt.BorderLayout.NORTH);
|
416 |
this.add(getGeoProcessingDissolvePanel(), java.awt.BorderLayout.NORTH);
|
417 |
this.add(getGeoProcessingMergePanel(), java.awt.BorderLayout.NORTH);
|
418 |
this.add(getGeoProcessingDifferencePanel(), BorderLayout.NORTH); |
419 |
this.add(getGeoProcessingIntersectPanel(), java.awt.BorderLayout.NORTH);
|
420 |
this.add(getGeoProcessingUnionPanel(), java.awt.BorderLayout.NORTH);
|
421 |
this.add(getGeoProcessingSpatialjoinPanel(),
|
422 |
java.awt.BorderLayout.NORTH); |
423 |
this.add(getGeoProcessingConvexHullPanel(), BorderLayout.NORTH); |
424 |
geoProcessingOperationSelectorPanel.setVisible(true);
|
425 |
geoProcessingBufferPanel.setVisible(false);
|
426 |
geoProcessingClipPanel.setVisible(false);
|
427 |
geoProcessingDissolvePanel.setVisible(false);
|
428 |
geoProcessingMergePanel.setVisible(false);
|
429 |
geoProcessingIntersectPanel.setVisible(false);
|
430 |
geoProcessingUnionPanel.setVisible(false);
|
431 |
geoProcessingSpatialjoinPanel.setVisible(false);
|
432 |
geoProcessingDifferencePanel.setVisible(false);
|
433 |
geoProcessingConvexHullPanel.setVisible(false);
|
434 |
|
435 |
// esto va contra la legibilidad del codigo
|
436 |
previousButton.setEnabled(false);
|
437 |
} |
438 |
|
439 |
private Component getGeoProcessingDifferencePanel() { |
440 |
if (geoProcessingDifferencePanel == null) { |
441 |
String titleText = PluginServices.getText(this, |
442 |
"Diferencia_Introduccion_de_datos");
|
443 |
geoProcessingDifferencePanel = new GeoProcessingOverlayPanel(
|
444 |
layers, titleText); |
445 |
geoProcessingDifferencePanel |
446 |
.setName("geoProcessingDifferencePanel");
|
447 |
} |
448 |
return geoProcessingDifferencePanel;
|
449 |
} |
450 |
|
451 |
public ViewInfo getViewInfo() {
|
452 |
if (viewInfo == null) { |
453 |
viewInfo = new ViewInfo(ViewInfo.MODALDIALOG);
|
454 |
viewInfo.setTitle(PluginServices.getText(this,
|
455 |
"Herramientas_de_analisis"));
|
456 |
} |
457 |
return viewInfo;
|
458 |
} |
459 |
|
460 |
/**
|
461 |
* This method initializes geoProcessingOperationSelectorPanel
|
462 |
*
|
463 |
* @return javax.swing.JPanel
|
464 |
*/
|
465 |
private JPanel getGeoProcessingOperationSelectorPanel() { |
466 |
if (geoProcessingOperationSelectorPanel == null) { |
467 |
geoProcessingOperationSelectorPanel = new GeoProcessingOperationSelectorPanel();
|
468 |
geoProcessingOperationSelectorPanel |
469 |
.setName("geoProcessingOperationSelectorPanel");
|
470 |
} |
471 |
return geoProcessingOperationSelectorPanel;
|
472 |
} |
473 |
|
474 |
/**
|
475 |
* This method initializes geoProcessingBufferPanel
|
476 |
*
|
477 |
* @return javax.swing.JPanel
|
478 |
*/
|
479 |
private JPanel getGeoProcessingBufferPanel() { |
480 |
if (geoProcessingBufferPanel == null) { |
481 |
geoProcessingBufferPanel = new GeoProcessingBufferPanel(layers);
|
482 |
geoProcessingBufferPanel.setName("geoProcessingBufferPanel");
|
483 |
} |
484 |
return geoProcessingBufferPanel;
|
485 |
} |
486 |
|
487 |
/**
|
488 |
* This method initializes geoProcessingClipPanel
|
489 |
*
|
490 |
* @return javax.swing.JPanel
|
491 |
*/
|
492 |
private JPanel getGeoProcessingClipPanel() { |
493 |
if (geoProcessingClipPanel == null) { |
494 |
String titleText = PluginServices.getText(this, |
495 |
"Recortar._Introduccion_de_datos")
|
496 |
+ ":";
|
497 |
geoProcessingClipPanel = new GeoProcessingOverlayPanel(layers,
|
498 |
titleText); |
499 |
geoProcessingClipPanel.setName("geoProcessingClipPanel");
|
500 |
// Si no le meto esta l?nea, no se visualiza el men?. Ver que puede
|
501 |
// estar pasando ...
|
502 |
geoProcessingClipPanel.setPreferredSize(new java.awt.Dimension(300, |
503 |
300));
|
504 |
} |
505 |
return geoProcessingClipPanel;
|
506 |
} |
507 |
|
508 |
/**
|
509 |
* This method initializes geoProcessingDissolvePanel
|
510 |
*
|
511 |
* @return javax.swing.JPanel
|
512 |
*/
|
513 |
private JPanel getGeoProcessingDissolvePanel() { |
514 |
if (geoProcessingDissolvePanel == null) { |
515 |
geoProcessingDissolvePanel = new GeoProcessingDissolvePanel(layers);
|
516 |
geoProcessingDissolvePanel.setName("geoProcessingDissolvePanel");
|
517 |
} |
518 |
return geoProcessingDissolvePanel;
|
519 |
} |
520 |
|
521 |
/**
|
522 |
* This method initializes geoProcessingMergePanel
|
523 |
*
|
524 |
* @return javax.swing.JPanel
|
525 |
*/
|
526 |
private JPanel getGeoProcessingMergePanel() { |
527 |
if (geoProcessingMergePanel == null) { |
528 |
geoProcessingMergePanel = new GeoProcessingMergePanel(layers);
|
529 |
geoProcessingMergePanel.setName("geoProcessingMergePanel");
|
530 |
} |
531 |
return geoProcessingMergePanel;
|
532 |
} |
533 |
|
534 |
/**
|
535 |
* This method initializes geoProcessingIntersectPanel
|
536 |
*
|
537 |
* @return javax.swing.JPanel
|
538 |
*/
|
539 |
private JPanel getGeoProcessingIntersectPanel() { |
540 |
if (geoProcessingIntersectPanel == null) { |
541 |
String titleText = PluginServices.getText(this, |
542 |
"Interseccion._Introduccion_de_datos");
|
543 |
geoProcessingIntersectPanel = new GeoProcessingOverlayPanel(layers,
|
544 |
titleText); |
545 |
geoProcessingIntersectPanel.setName("geoProcessingIntersectPanel");
|
546 |
} |
547 |
return geoProcessingIntersectPanel;
|
548 |
} |
549 |
|
550 |
/**
|
551 |
* This method initializes geoProcessingUnionPanel
|
552 |
*
|
553 |
* @return javax.swing.JPanel
|
554 |
*/
|
555 |
private JPanel getGeoProcessingUnionPanel() { |
556 |
if (geoProcessingUnionPanel == null) { |
557 |
String titleText = PluginServices.getText(this, |
558 |
"Union._Introduccion_de_datos");
|
559 |
geoProcessingUnionPanel = new GeoProcessingOverlayPanel(layers,
|
560 |
titleText); |
561 |
geoProcessingUnionPanel.setName("geoProcessingUnionPanel");
|
562 |
} |
563 |
return geoProcessingUnionPanel;
|
564 |
} |
565 |
|
566 |
/**
|
567 |
* This method initializes geoProcessingSpatialjoinPanel
|
568 |
*
|
569 |
* @return javax.swing.JPanel
|
570 |
*/
|
571 |
private JPanel getGeoProcessingSpatialjoinPanel() { |
572 |
if (geoProcessingSpatialjoinPanel == null) { |
573 |
geoProcessingSpatialjoinPanel = new GeoProcessingSpatialjoinPanel(
|
574 |
layers); |
575 |
geoProcessingSpatialjoinPanel |
576 |
.setName("geoProcessingSpatialjoinPanel");
|
577 |
// Si no le meto esta l?nea, no se visualiza el men?. Ver que puede
|
578 |
// estar pasando ...
|
579 |
geoProcessingSpatialjoinPanel |
580 |
.setPreferredSize(new java.awt.Dimension(300, 300)); |
581 |
} |
582 |
return geoProcessingSpatialjoinPanel;
|
583 |
} |
584 |
|
585 |
/**
|
586 |
* This method initializes buttonsPanel
|
587 |
*
|
588 |
* @return javax.swing.JPanel
|
589 |
*/
|
590 |
private JPanel getButtonsPanel() { |
591 |
if (buttonsPanel == null) { |
592 |
buttonsPanel = new JPanel(); |
593 |
buttonsPanel.setName("buttonsPanel");
|
594 |
buttonsPanel |
595 |
.setBorder(javax.swing.BorderFactory |
596 |
.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED)); |
597 |
// esto tambi?n lo cambiaria...JButton, JButton1, JButton2 no
|
598 |
// dan claridad al codigo
|
599 |
buttonsPanel.add(getCloseButton(), null);
|
600 |
buttonsPanel.add(getPreviousButton(), null);
|
601 |
buttonsPanel.add(getNextButton(), null);
|
602 |
} |
603 |
return buttonsPanel;
|
604 |
} |
605 |
|
606 |
/**
|
607 |
* This method initializes closeButton
|
608 |
*
|
609 |
* @return javax.swing.JButton
|
610 |
*/
|
611 |
private JButton getCloseButton() { |
612 |
if (closeButton == null) { |
613 |
closeButton = new JButton(); |
614 |
closeButton.setText(PluginServices.getText(this, "Cerrar")); |
615 |
closeButton.addActionListener(new java.awt.event.ActionListener() {
|
616 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
617 |
closeDialog(); |
618 |
} |
619 |
}); |
620 |
} |
621 |
return closeButton;
|
622 |
} |
623 |
|
624 |
/**
|
625 |
* This method initializes previousButton
|
626 |
*
|
627 |
* @return javax.swing.JButton
|
628 |
*/
|
629 |
private JButton getPreviousButton() { |
630 |
if (previousButton == null) { |
631 |
previousButton = new JButton(); |
632 |
previousButton.setText(PluginServices.getText(this, "Anterior")); |
633 |
previousButton |
634 |
.addActionListener(new java.awt.event.ActionListener() {
|
635 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
636 |
previousStep(); |
637 |
} |
638 |
}); |
639 |
} |
640 |
return previousButton;
|
641 |
} |
642 |
|
643 |
/**
|
644 |
* This method initializes nextButton
|
645 |
*
|
646 |
* @return javax.swing.JButton
|
647 |
*/
|
648 |
private JButton getNextButton() { |
649 |
if (nextButton == null) { |
650 |
nextButton = new JButton(); |
651 |
nextButton.setText(PluginServices.getText(this, "Siguiente")); |
652 |
nextButton.addActionListener(new java.awt.event.ActionListener() {
|
653 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
654 |
nextStep(); |
655 |
} |
656 |
}); |
657 |
} |
658 |
return nextButton;
|
659 |
} |
660 |
|
661 |
public void doBuffer() { |
662 |
FLyrVect inputLayer = geoProcessingBufferPanel.getInputLayer(); |
663 |
File outputFile = geoProcessingBufferPanel.getOutputFile();
|
664 |
final BufferGeoprocess buffer = new BufferGeoprocess(inputLayer); |
665 |
// TODO Hay que desacoplar el SchemaManager y el
|
666 |
// LayerDefinition del formato Shp, as? como del
|
667 |
// uso de ficheros
|
668 |
SHPLayerDefinition definition = (SHPLayerDefinition) buffer |
669 |
.createLayerDefinition(); |
670 |
definition.setFile(outputFile); |
671 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
672 |
ShpWriter writer = getShpWriter(definition); |
673 |
buffer.setResultLayerProperties(writer, schemaManager); |
674 |
HashMap params = new HashMap(); |
675 |
boolean onlySelected = geoProcessingBufferPanel.isBufferOnlySelected();
|
676 |
params.put("layer_selection", new Boolean(onlySelected)); |
677 |
boolean dissolveBuffer = geoProcessingBufferPanel
|
678 |
.isDissolveBuffersSelected(); |
679 |
params.put("dissolve_buffers", new Boolean(dissolveBuffer)); |
680 |
byte strategy = 0; |
681 |
if (geoProcessingBufferPanel.isConstantDistanceSelected()) {
|
682 |
strategy = BufferGeoprocess.CONSTANT_DISTANCE_STRATEGY; |
683 |
double bufferDistance = -1; |
684 |
try {
|
685 |
bufferDistance = geoProcessingBufferPanel.getConstantDistance(); |
686 |
} catch (GeoprocessException e) {
|
687 |
// TODO Mostrar dialogo de distancia no numerica
|
688 |
e.printStackTrace(); |
689 |
return;
|
690 |
} |
691 |
params.put("buffer_distance", new Double(bufferDistance)); |
692 |
} else if (geoProcessingBufferPanel.isAttributeDistanceSelected()) { |
693 |
strategy = BufferGeoprocess.ATTRIBUTE_DISTANCE_STRATEGY; |
694 |
String attributeName = null; |
695 |
try {
|
696 |
attributeName = geoProcessingBufferPanel |
697 |
.getAttributeDistanceField(); |
698 |
} catch (GeoprocessException e) {
|
699 |
// TODO mostrar dialogo de atributo no numerico
|
700 |
e.printStackTrace(); |
701 |
return;
|
702 |
} |
703 |
params.put("attr_name", attributeName);
|
704 |
} |
705 |
params.put("strategy_flag", new Byte(strategy)); |
706 |
try {
|
707 |
buffer.setParameters(params); |
708 |
// buffer.process();
|
709 |
IMonitorableTask task1 = buffer.createTask(); |
710 |
IMonitorableTask task2 = new AddResultLayerTask(buffer);
|
711 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
712 |
task2); |
713 |
if (globalTask.preprocess())
|
714 |
PluginServices.cancelableBackgroundExecution(globalTask); |
715 |
} catch (GeoprocessException e) {
|
716 |
// TODO Mostrar dialogo de error
|
717 |
e.printStackTrace(); |
718 |
return;
|
719 |
} |
720 |
} |
721 |
|
722 |
private ShpWriter getShpWriter(SHPLayerDefinition definition) {
|
723 |
ShpWriter writer = null;
|
724 |
try {
|
725 |
writer = new ShpWriter();
|
726 |
writer.setFile(definition.getFile()); |
727 |
writer.initialize(definition); |
728 |
} catch (IOException e) { |
729 |
// TODO Mostrar dialogo informando del error
|
730 |
e.printStackTrace(); |
731 |
} catch (DriverException e) {
|
732 |
// TODO Mostrar dialogo informando del error
|
733 |
e.printStackTrace(); |
734 |
} |
735 |
return writer;
|
736 |
} |
737 |
|
738 |
public void doMerge() { |
739 |
|
740 |
} |
741 |
|
742 |
public void doDissolve() { |
743 |
FLyrVect inputLayer = geoProcessingDissolvePanel.getInputLayer(); |
744 |
File outputFile = geoProcessingDissolvePanel.getOutputFile();
|
745 |
String dissolveField = geoProcessingDissolvePanel
|
746 |
.getDissolveFieldName(); |
747 |
boolean onlySelection = geoProcessingDissolvePanel
|
748 |
.isDissolveOnlySelected(); |
749 |
DissolveGeoprocess dissolve = new DissolveGeoprocess(inputLayer,
|
750 |
dissolveField); |
751 |
|
752 |
// Antes de crear el esquema vemos la seleccion del usuario
|
753 |
Map fields_functions = geoProcessingDissolvePanel.getFieldFunctionMap();
|
754 |
dissolve.setFieldsFunctions(fields_functions); |
755 |
|
756 |
SHPLayerDefinition definition = (SHPLayerDefinition) dissolve |
757 |
.createLayerDefinition(); |
758 |
definition.setFile(outputFile); |
759 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
760 |
|
761 |
ShpWriter writer = null;
|
762 |
try {
|
763 |
schemaManager.createOrAlterSchema(definition); |
764 |
writer = new ShpWriter();
|
765 |
writer.setFile(outputFile); |
766 |
writer.initialize(definition); |
767 |
} catch (IOException e) { |
768 |
// TODO Mostrar dialogo informando del error
|
769 |
e.printStackTrace(); |
770 |
return;
|
771 |
} catch (DriverException e) {
|
772 |
// TODO Mostrar dialogo informando del error
|
773 |
e.printStackTrace(); |
774 |
return;
|
775 |
} catch (EditionException e) {
|
776 |
// TODO Auto-generated catch block
|
777 |
e.printStackTrace(); |
778 |
return;
|
779 |
} |
780 |
dissolve.setResultLayerProperties(writer, schemaManager); |
781 |
HashMap params = new HashMap(); |
782 |
params.put("layer_selection", new Boolean(onlySelection)); |
783 |
try {
|
784 |
dissolve.setParameters(params); |
785 |
IMonitorableTask task1 = dissolve.createTask(); |
786 |
IMonitorableTask task2 = new AddResultLayerTask(dissolve);
|
787 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
788 |
task2); |
789 |
if (globalTask.preprocess())
|
790 |
PluginServices.cancelableBackgroundExecution(globalTask); |
791 |
} catch (GeoprocessException e) {
|
792 |
// TODO Mostrar dialogo de error
|
793 |
e.printStackTrace(); |
794 |
return;
|
795 |
} |
796 |
} |
797 |
|
798 |
public void doSpatialJoin() { |
799 |
// this open a modal dialog and sets sumarize functions
|
800 |
if (!geoProcessingSpatialjoinPanel.isNearestSelected())
|
801 |
geoProcessingSpatialjoinPanel.openSumarizeFunction(); |
802 |
FLyrVect inputLayer = geoProcessingSpatialjoinPanel.getFirstLayer(); |
803 |
FLyrVect secondLayer = geoProcessingSpatialjoinPanel.getSecondLayer(); |
804 |
|
805 |
File outputFile = geoProcessingSpatialjoinPanel.getOutputFile();
|
806 |
boolean onlyFirstSelection = geoProcessingSpatialjoinPanel
|
807 |
.onlyFirstLayerSelected(); |
808 |
boolean onlySecondSelection = geoProcessingSpatialjoinPanel
|
809 |
.onlySecondLayerSelected(); |
810 |
boolean nearest = geoProcessingSpatialjoinPanel.isNearestSelected();
|
811 |
Map sumarizeFunctions = geoProcessingSpatialjoinPanel
|
812 |
.getSumarizeFunctions(); |
813 |
|
814 |
SpatialJoinGeoprocess join = new SpatialJoinGeoprocess(inputLayer);
|
815 |
join.setSecondOperand(secondLayer); |
816 |
join.setFields_sumFunctions(sumarizeFunctions); |
817 |
HashMap params = new HashMap(); |
818 |
Boolean first = new Boolean(onlyFirstSelection); |
819 |
params.put("firstlayerselection", first);
|
820 |
|
821 |
Boolean second = new Boolean(onlySecondSelection); |
822 |
params.put("secondlayerselection", second);
|
823 |
|
824 |
Boolean nearSel = new Boolean(nearest); |
825 |
params.put("nearest", nearSel);
|
826 |
try {
|
827 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
828 |
ShpWriter writer = new ShpWriter();
|
829 |
join.setResultLayerProperties(writer, schemaManager); |
830 |
join.setParameters(params); |
831 |
SHPLayerDefinition definition = (SHPLayerDefinition) join |
832 |
.createLayerDefinition(); |
833 |
definition.setFile(outputFile); |
834 |
writer = getShpWriter(definition); |
835 |
if (writer == null) |
836 |
return;
|
837 |
join.process(); |
838 |
layers.addLayer(join.getResult()); |
839 |
} catch (GeoprocessException e) {
|
840 |
// TODO Auto-generated catch block
|
841 |
e.printStackTrace(); |
842 |
} |
843 |
|
844 |
} |
845 |
|
846 |
/**
|
847 |
* Shows an alert dialog
|
848 |
*
|
849 |
* @param message
|
850 |
* body of message dialog
|
851 |
* @param title
|
852 |
* title of mesage dialog
|
853 |
*
|
854 |
* TODO Mirar si es mejor utilizar el componente generico de ANDAMI
|
855 |
* (notification dialog)
|
856 |
*/
|
857 |
private void error(String message, String title) { |
858 |
JOptionPane.showMessageDialog(this, message, title, |
859 |
JOptionPane.ERROR_MESSAGE);
|
860 |
} |
861 |
|
862 |
public void doClip() { |
863 |
FLyrVect inputLayer = geoProcessingClipPanel.getFirstLayer(); |
864 |
FLyrVect clippingLayer = geoProcessingClipPanel.getSecondLayer(); |
865 |
File outputFile = geoProcessingClipPanel.getOutputFile();
|
866 |
ClipGeoprocess clip = new ClipGeoprocess(inputLayer);
|
867 |
clip.setSecondOperand(clippingLayer); |
868 |
SHPLayerDefinition definition = (SHPLayerDefinition) clip |
869 |
.createLayerDefinition(); |
870 |
definition.setFile(outputFile); |
871 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
872 |
ShpWriter writer = getShpWriter(definition); |
873 |
if (writer == null) |
874 |
return;
|
875 |
|
876 |
clip.setResultLayerProperties(writer, schemaManager); |
877 |
HashMap params = new HashMap(); |
878 |
boolean onlySelectedFirst = geoProcessingClipPanel
|
879 |
.onlyFirstLayerSelected(); |
880 |
boolean onlySelectedSecond = geoProcessingClipPanel
|
881 |
.onlySecondLayerSelected(); |
882 |
Boolean first = new Boolean(onlySelectedFirst); |
883 |
params.put("firstlayerselection", first);
|
884 |
|
885 |
Boolean second = new Boolean(onlySelectedSecond); |
886 |
params.put("secondlayerselection", second);
|
887 |
|
888 |
try {
|
889 |
clip.setParameters(params); |
890 |
clip.checkPreconditions(); |
891 |
IMonitorableTask task1 = clip.createTask(); |
892 |
IMonitorableTask task2 = new AddResultLayerTask(clip);
|
893 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
894 |
task2); |
895 |
if (globalTask.preprocess())
|
896 |
PluginServices.cancelableBackgroundExecution(globalTask); |
897 |
} catch (GeoprocessException e) {
|
898 |
// TODO Mostrar dialogo de error
|
899 |
e.printStackTrace(); |
900 |
return;
|
901 |
} |
902 |
} |
903 |
|
904 |
// Spatial join con Intersect
|
905 |
public void doIntersect() { |
906 |
FLyrVect inputLayer = geoProcessingIntersectPanel.getFirstLayer(); |
907 |
FLyrVect overlayLayer = geoProcessingIntersectPanel.getSecondLayer(); |
908 |
File outputFile = geoProcessingIntersectPanel.getOutputFile();
|
909 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
910 |
// TODO Poner dialogo recordando que seleccione un fichero
|
911 |
return;
|
912 |
} |
913 |
|
914 |
IntersectionGeoprocess intersection = new IntersectionGeoprocess(
|
915 |
inputLayer); |
916 |
intersection.setSecondOperand(overlayLayer); |
917 |
/*
|
918 |
* TODO Ahora mismo ShpWriter crea el esquema en el constructor, por lo
|
919 |
* que no estoy llamando a SchemaManager.createOrAlter. Lo suyo es que
|
920 |
* ShpWriter implemente SchemaManager REVISAR
|
921 |
*/
|
922 |
SHPLayerDefinition definition = (SHPLayerDefinition) intersection |
923 |
.createLayerDefinition(); |
924 |
definition.setFile(outputFile); |
925 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
926 |
ShpWriter writer = getShpWriter(definition); |
927 |
if (writer == null) |
928 |
return;
|
929 |
|
930 |
intersection.setResultLayerProperties(writer, schemaManager); |
931 |
HashMap params = new HashMap(); |
932 |
boolean onlySelectedFirst = geoProcessingUnionPanel
|
933 |
.onlyFirstLayerSelected(); |
934 |
boolean onlySelectedSecond = geoProcessingUnionPanel
|
935 |
.onlySecondLayerSelected(); |
936 |
Boolean first = new Boolean(onlySelectedFirst); |
937 |
params.put("firstlayerselection", first);
|
938 |
|
939 |
Boolean second = new Boolean(onlySelectedSecond); |
940 |
params.put("secondlayerselection", second);
|
941 |
|
942 |
try {
|
943 |
intersection.setParameters(params); |
944 |
intersection.checkPreconditions(); |
945 |
IMonitorableTask task1 = intersection.createTask(); |
946 |
if(task1 == null){ |
947 |
//mensaje de error
|
948 |
return;
|
949 |
} |
950 |
IMonitorableTask task2 = new AddResultLayerTask(intersection);
|
951 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
952 |
task2); |
953 |
if (globalTask.preprocess())
|
954 |
PluginServices.cancelableBackgroundExecution(globalTask); |
955 |
} catch (GeoprocessException e) {
|
956 |
// TODO Mostrar dialogo de error
|
957 |
e.printStackTrace(); |
958 |
return;
|
959 |
} |
960 |
} |
961 |
|
962 |
public void doUnion() { |
963 |
Crono crono = new Crono();
|
964 |
JDialog cronoDialog = new JDialog(); |
965 |
cronoDialog.getContentPane().setLayout(new BorderLayout()); |
966 |
cronoDialog.getContentPane().add(crono, BorderLayout.CENTER);
|
967 |
cronoDialog.pack(); |
968 |
cronoDialog.setVisible(true);
|
969 |
crono.start(); |
970 |
/*
|
971 |
* METER TODO ESTO EN UN THREAD APARTE GESTIONADO POR EL SWINGWORKER
|
972 |
*/
|
973 |
FLyrVect inputLayer = geoProcessingUnionPanel.getFirstLayer(); |
974 |
FLyrVect overlayLayer = geoProcessingUnionPanel.getSecondLayer(); |
975 |
File outputFile = geoProcessingUnionPanel.getOutputFile();
|
976 |
UnionGeoprocess union = new UnionGeoprocess(inputLayer);
|
977 |
union.setSecondOperand(overlayLayer); |
978 |
/*
|
979 |
* TODO Ahora mismo ShpWriter crea el esquema en el constructor, por lo
|
980 |
* que no estoy llamando a SchemaManager.createOrAlter. Lo suyo es que
|
981 |
* ShpWriter implemente SchemaManager REVISAR
|
982 |
*/
|
983 |
SHPLayerDefinition definition = (SHPLayerDefinition) union |
984 |
.createLayerDefinition(); |
985 |
definition.setFile(outputFile); |
986 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
987 |
ShpWriter writer = getShpWriter(definition); |
988 |
if (writer == null) |
989 |
return;
|
990 |
|
991 |
union.setResultLayerProperties(writer, schemaManager); |
992 |
HashMap params = new HashMap(); |
993 |
boolean onlySelectedFirst = geoProcessingUnionPanel
|
994 |
.onlyFirstLayerSelected(); |
995 |
boolean onlySelectedSecond = geoProcessingUnionPanel
|
996 |
.onlySecondLayerSelected(); |
997 |
Boolean first = new Boolean(onlySelectedFirst); |
998 |
params.put("firstlayerselection", first);
|
999 |
|
1000 |
Boolean second = new Boolean(onlySelectedSecond); |
1001 |
params.put("secondlayerselection", second);
|
1002 |
|
1003 |
try {
|
1004 |
union.setParameters(params); |
1005 |
union.checkPreconditions(); |
1006 |
union.process(); |
1007 |
layers.addLayer(union.getResult()); |
1008 |
} catch (GeoprocessException e) {
|
1009 |
// TODO Mostrar dialogo de error
|
1010 |
e.printStackTrace(); |
1011 |
return;
|
1012 |
} |
1013 |
crono.stop(); |
1014 |
|
1015 |
} |
1016 |
|
1017 |
private int getQuadrantSegments() { |
1018 |
return (Integer.valueOf((String) ((JComboBox) geoProcessingBufferPanel |
1019 |
.getComponent(11)).getSelectedItem())).intValue();
|
1020 |
} |
1021 |
|
1022 |
private String insertRepeatedFieldChar(String inputString) { |
1023 |
char[] chars = inputString.toCharArray(); |
1024 |
String outputString;
|
1025 |
if (chars.length < 10) { |
1026 |
outputString = inputString + "_";
|
1027 |
} else {
|
1028 |
chars[9] = "_".charAt(0); |
1029 |
outputString = new String(chars); |
1030 |
} |
1031 |
return outputString;
|
1032 |
} |
1033 |
|
1034 |
public void doConvexHull() { |
1035 |
FLyrVect inputLayer = geoProcessingConvexHullPanel.getInputLayer(); |
1036 |
File outputFile = geoProcessingConvexHullPanel.getOutputFile();
|
1037 |
ConvexHullGeoprocess convexHull = new ConvexHullGeoprocess();
|
1038 |
convexHull.setFirstOperand(inputLayer); |
1039 |
|
1040 |
SHPLayerDefinition definition = (SHPLayerDefinition) convexHull |
1041 |
.createLayerDefinition(); |
1042 |
definition.setFile(outputFile); |
1043 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
1044 |
ShpWriter writer = getShpWriter(definition); |
1045 |
if (writer == null) |
1046 |
return;
|
1047 |
|
1048 |
convexHull.setResultLayerProperties(writer, schemaManager); |
1049 |
HashMap params = new HashMap(); |
1050 |
boolean onlySelected = geoProcessingConvexHullPanel
|
1051 |
.isConvexHullOnlySelected(); |
1052 |
params.put("layer_selection", new Boolean(onlySelected)); |
1053 |
try {
|
1054 |
convexHull.setParameters(params); |
1055 |
IMonitorableTask task1 = convexHull.createTask(); |
1056 |
if(task1 == null){ |
1057 |
//TODO Mostrar mensaje de error
|
1058 |
//Hacemos que createTask lance excepcion ??
|
1059 |
return;
|
1060 |
|
1061 |
} |
1062 |
IMonitorableTask task2 = new AddResultLayerTask(convexHull);
|
1063 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
1064 |
task2); |
1065 |
if (globalTask.preprocess())
|
1066 |
PluginServices.cancelableBackgroundExecution(globalTask); |
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
} catch (GeoprocessException e) {
|
1074 |
// TODO Mostrar dialogo de error
|
1075 |
e.printStackTrace(); |
1076 |
return;
|
1077 |
} |
1078 |
} |
1079 |
|
1080 |
public void doDifference() { |
1081 |
FLyrVect inputLayer = geoProcessingDifferencePanel.getFirstLayer(); |
1082 |
FLyrVect overlayLayer = geoProcessingDifferencePanel.getSecondLayer(); |
1083 |
File outputFile = geoProcessingDifferencePanel.getOutputFile();
|
1084 |
DifferenceGeoprocess diff = new DifferenceGeoprocess(inputLayer);
|
1085 |
diff.setSecondOperand(overlayLayer); |
1086 |
SHPLayerDefinition definition = (SHPLayerDefinition) diff |
1087 |
.createLayerDefinition(); |
1088 |
definition.setFile(outputFile); |
1089 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
1090 |
ShpWriter writer = null;
|
1091 |
try {
|
1092 |
writer = new ShpWriter();
|
1093 |
writer.initialize(outputFile, definition); |
1094 |
} catch (IOException e) { |
1095 |
// TODO PONER MENSAJE DE ERROR INTERNACIONALIZADO
|
1096 |
e.printStackTrace(); |
1097 |
return;
|
1098 |
} catch (DriverException e) {
|
1099 |
// TODO Mostrar dialogo informando del error
|
1100 |
e.printStackTrace(); |
1101 |
return;
|
1102 |
} |
1103 |
diff.setResultLayerProperties(writer, schemaManager); |
1104 |
HashMap params = new HashMap(); |
1105 |
boolean onlySelectedFirst = geoProcessingDifferencePanel
|
1106 |
.onlyFirstLayerSelected(); |
1107 |
boolean onlySelectedSecond = geoProcessingDifferencePanel
|
1108 |
.onlySecondLayerSelected(); |
1109 |
Boolean first = new Boolean(onlySelectedFirst); |
1110 |
params.put("firstlayerselection", first);
|
1111 |
|
1112 |
Boolean second = new Boolean(onlySelectedSecond); |
1113 |
params.put("secondlayerselection", second);
|
1114 |
|
1115 |
try {
|
1116 |
diff.setParameters(params); |
1117 |
diff.checkPreconditions(); |
1118 |
|
1119 |
IMonitorableTask task1 = diff.createTask(); |
1120 |
if(task1 == null){ |
1121 |
//TODO Mostrar mensaje de error
|
1122 |
//Hacemos que createTask lance excepcion ??
|
1123 |
return;
|
1124 |
|
1125 |
} |
1126 |
IMonitorableTask task2 = new AddResultLayerTask(diff);
|
1127 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
1128 |
task2); |
1129 |
if (globalTask.preprocess())
|
1130 |
PluginServices.cancelableBackgroundExecution(globalTask); |
1131 |
|
1132 |
} catch (GeoprocessException e) {
|
1133 |
// TODO Mostrar dialogo de error
|
1134 |
e.printStackTrace(); |
1135 |
return;
|
1136 |
} |
1137 |
} |
1138 |
|
1139 |
/**
|
1140 |
* Implementation of IMonitorableTask that add result layer
|
1141 |
* of a geoprocess to the TOC in a background thread
|
1142 |
* @author azabala
|
1143 |
*
|
1144 |
*/
|
1145 |
class AddResultLayerTask implements IMonitorableTask { |
1146 |
int initialStep = 1; |
1147 |
|
1148 |
int currentStep = 5; |
1149 |
|
1150 |
int lastStep = 10; |
1151 |
|
1152 |
boolean finished = false; |
1153 |
|
1154 |
IGeoprocess geoprocess; |
1155 |
|
1156 |
public AddResultLayerTask(IGeoprocess geoprocess) {
|
1157 |
this.geoprocess = geoprocess;
|
1158 |
} |
1159 |
|
1160 |
public int getInitialStep() { |
1161 |
return initialStep;
|
1162 |
} |
1163 |
|
1164 |
public int getFinishStep() { |
1165 |
return lastStep;
|
1166 |
} |
1167 |
|
1168 |
public int getCurrentStep() { |
1169 |
if (!finished)
|
1170 |
return 5; |
1171 |
else
|
1172 |
return lastStep;
|
1173 |
} |
1174 |
|
1175 |
public String getStatusMessage() { |
1176 |
return "Loading layer..."; |
1177 |
} |
1178 |
|
1179 |
public String getNote() { |
1180 |
return ""; |
1181 |
} |
1182 |
|
1183 |
public boolean isDefined() { |
1184 |
return true; |
1185 |
} |
1186 |
|
1187 |
public void cancel() { |
1188 |
finished = true;
|
1189 |
} |
1190 |
|
1191 |
public void run() throws GeoprocessException { |
1192 |
try {
|
1193 |
layers.addLayer(geoprocess.getResult()); |
1194 |
} catch (CancelationException e) {
|
1195 |
throw new GeoprocessException( |
1196 |
"Error al a?adir el resultado de un geoproceso a flayers");
|
1197 |
} finally {
|
1198 |
finished = true;
|
1199 |
} |
1200 |
} |
1201 |
|
1202 |
public boolean isCanceled() { |
1203 |
return false; |
1204 |
} |
1205 |
|
1206 |
public boolean isFinished() { |
1207 |
return finished;
|
1208 |
} |
1209 |
} |
1210 |
|
1211 |
} // @jve:decl-index=0:visual-constraint="10,10"
|