root / trunk / extensions / extGeoProcessing / src / com / iver / gvsig / geoprocessing / gui / GeoProcessingPanel.java @ 4447
History | View | Annotate | Download (39.2 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 = |
832 |
(SHPLayerDefinition) join.createLayerDefinition(); |
833 |
definition.setFile(outputFile); |
834 |
writer.setFile(definition.getFile()); |
835 |
writer.initialize(definition); |
836 |
writer = getShpWriter(definition); |
837 |
if (writer == null) |
838 |
return;
|
839 |
IMonitorableTask task1 = join.createTask(); |
840 |
if(task1 == null){ |
841 |
//mensaje de error
|
842 |
return;
|
843 |
} |
844 |
IMonitorableTask task2 = new AddResultLayerTask(join);
|
845 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
846 |
task2); |
847 |
if (globalTask.preprocess())
|
848 |
PluginServices.cancelableBackgroundExecution(globalTask); |
849 |
} catch (GeoprocessException e) {
|
850 |
// TODO Auto-generated catch block
|
851 |
e.printStackTrace(); |
852 |
} catch (IOException e) { |
853 |
// TODO Auto-generated catch block
|
854 |
e.printStackTrace(); |
855 |
} catch (DriverException e) {
|
856 |
// TODO Auto-generated catch block
|
857 |
e.printStackTrace(); |
858 |
} |
859 |
|
860 |
} |
861 |
|
862 |
/**
|
863 |
* Shows an alert dialog
|
864 |
*
|
865 |
* @param message
|
866 |
* body of message dialog
|
867 |
* @param title
|
868 |
* title of mesage dialog
|
869 |
*
|
870 |
* TODO Mirar si es mejor utilizar el componente generico de ANDAMI
|
871 |
* (notification dialog)
|
872 |
*/
|
873 |
private void error(String message, String title) { |
874 |
JOptionPane.showMessageDialog(this, message, title, |
875 |
JOptionPane.ERROR_MESSAGE);
|
876 |
} |
877 |
|
878 |
public void doClip() { |
879 |
FLyrVect inputLayer = geoProcessingClipPanel.getFirstLayer(); |
880 |
FLyrVect clippingLayer = geoProcessingClipPanel.getSecondLayer(); |
881 |
File outputFile = geoProcessingClipPanel.getOutputFile();
|
882 |
ClipGeoprocess clip = new ClipGeoprocess(inputLayer);
|
883 |
clip.setSecondOperand(clippingLayer); |
884 |
SHPLayerDefinition definition = (SHPLayerDefinition) clip |
885 |
.createLayerDefinition(); |
886 |
definition.setFile(outputFile); |
887 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
888 |
ShpWriter writer = getShpWriter(definition); |
889 |
if (writer == null){ |
890 |
//TODO MOSTRAR MENSAJE DE ERROR
|
891 |
return;
|
892 |
} |
893 |
|
894 |
clip.setResultLayerProperties(writer, schemaManager); |
895 |
HashMap params = new HashMap(); |
896 |
boolean onlySelectedFirst = geoProcessingClipPanel
|
897 |
.onlyFirstLayerSelected(); |
898 |
boolean onlySelectedSecond = geoProcessingClipPanel
|
899 |
.onlySecondLayerSelected(); |
900 |
Boolean first = new Boolean(onlySelectedFirst); |
901 |
params.put("firstlayerselection", first);
|
902 |
|
903 |
Boolean second = new Boolean(onlySelectedSecond); |
904 |
params.put("secondlayerselection", second);
|
905 |
|
906 |
try {
|
907 |
clip.setParameters(params); |
908 |
clip.checkPreconditions(); |
909 |
IMonitorableTask task1 = clip.createTask(); |
910 |
IMonitorableTask task2 = new AddResultLayerTask(clip);
|
911 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
912 |
task2); |
913 |
if (globalTask.preprocess())
|
914 |
PluginServices.cancelableBackgroundExecution(globalTask); |
915 |
} catch (GeoprocessException e) {
|
916 |
// TODO Mostrar dialogo de error
|
917 |
e.printStackTrace(); |
918 |
return;
|
919 |
} |
920 |
} |
921 |
|
922 |
// Spatial join con Intersect
|
923 |
public void doIntersect() { |
924 |
FLyrVect inputLayer = geoProcessingIntersectPanel.getFirstLayer(); |
925 |
FLyrVect overlayLayer = geoProcessingIntersectPanel.getSecondLayer(); |
926 |
File outputFile = geoProcessingIntersectPanel.getOutputFile();
|
927 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
928 |
// TODO Poner dialogo recordando que seleccione un fichero
|
929 |
return;
|
930 |
} |
931 |
|
932 |
IntersectionGeoprocess intersection = new IntersectionGeoprocess(
|
933 |
inputLayer); |
934 |
intersection.setSecondOperand(overlayLayer); |
935 |
/*
|
936 |
* TODO Ahora mismo ShpWriter crea el esquema en el constructor, por lo
|
937 |
* que no estoy llamando a SchemaManager.createOrAlter. Lo suyo es que
|
938 |
* ShpWriter implemente SchemaManager REVISAR
|
939 |
*/
|
940 |
SHPLayerDefinition definition = (SHPLayerDefinition) intersection |
941 |
.createLayerDefinition(); |
942 |
definition.setFile(outputFile); |
943 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
944 |
ShpWriter writer = getShpWriter(definition); |
945 |
if (writer == null) |
946 |
return;
|
947 |
|
948 |
intersection.setResultLayerProperties(writer, schemaManager); |
949 |
HashMap params = new HashMap(); |
950 |
boolean onlySelectedFirst = geoProcessingUnionPanel
|
951 |
.onlyFirstLayerSelected(); |
952 |
boolean onlySelectedSecond = geoProcessingUnionPanel
|
953 |
.onlySecondLayerSelected(); |
954 |
Boolean first = new Boolean(onlySelectedFirst); |
955 |
params.put("firstlayerselection", first);
|
956 |
|
957 |
Boolean second = new Boolean(onlySelectedSecond); |
958 |
params.put("secondlayerselection", second);
|
959 |
|
960 |
try {
|
961 |
intersection.setParameters(params); |
962 |
intersection.checkPreconditions(); |
963 |
IMonitorableTask task1 = intersection.createTask(); |
964 |
if(task1 == null){ |
965 |
//mensaje de error
|
966 |
return;
|
967 |
} |
968 |
IMonitorableTask task2 = new AddResultLayerTask(intersection);
|
969 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
970 |
task2); |
971 |
if (globalTask.preprocess())
|
972 |
PluginServices.cancelableBackgroundExecution(globalTask); |
973 |
} catch (GeoprocessException e) {
|
974 |
// TODO Mostrar dialogo de error
|
975 |
e.printStackTrace(); |
976 |
return;
|
977 |
} |
978 |
} |
979 |
|
980 |
public void doUnion() { |
981 |
FLyrVect inputLayer = geoProcessingUnionPanel.getFirstLayer(); |
982 |
FLyrVect overlayLayer = geoProcessingUnionPanel.getSecondLayer(); |
983 |
File outputFile = geoProcessingUnionPanel.getOutputFile();
|
984 |
UnionGeoprocess union = new UnionGeoprocess(inputLayer);
|
985 |
union.setSecondOperand(overlayLayer); |
986 |
SHPLayerDefinition definition = (SHPLayerDefinition) union |
987 |
.createLayerDefinition(); |
988 |
definition.setFile(outputFile); |
989 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
990 |
ShpWriter writer = getShpWriter(definition); |
991 |
if (writer == null) |
992 |
return;
|
993 |
|
994 |
union.setResultLayerProperties(writer, schemaManager); |
995 |
HashMap params = new HashMap(); |
996 |
boolean onlySelectedFirst = geoProcessingUnionPanel
|
997 |
.onlyFirstLayerSelected(); |
998 |
boolean onlySelectedSecond = geoProcessingUnionPanel
|
999 |
.onlySecondLayerSelected(); |
1000 |
Boolean first = new Boolean(onlySelectedFirst); |
1001 |
params.put("firstlayerselection", first);
|
1002 |
|
1003 |
Boolean second = new Boolean(onlySelectedSecond); |
1004 |
params.put("secondlayerselection", second);
|
1005 |
|
1006 |
try {
|
1007 |
union.setParameters(params); |
1008 |
union.checkPreconditions(); |
1009 |
IMonitorableTask task1 = union.createTask(); |
1010 |
if(task1 == null){ |
1011 |
//mensaje de error
|
1012 |
return;
|
1013 |
} |
1014 |
IMonitorableTask task2 = new AddResultLayerTask(union);
|
1015 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
1016 |
task2); |
1017 |
if (globalTask.preprocess())
|
1018 |
PluginServices.cancelableBackgroundExecution(globalTask); |
1019 |
} catch (GeoprocessException e) {
|
1020 |
// TODO Mostrar dialogo de error
|
1021 |
e.printStackTrace(); |
1022 |
return;
|
1023 |
} |
1024 |
} |
1025 |
|
1026 |
|
1027 |
public void doConvexHull() { |
1028 |
FLyrVect inputLayer = geoProcessingConvexHullPanel.getInputLayer(); |
1029 |
File outputFile = geoProcessingConvexHullPanel.getOutputFile();
|
1030 |
ConvexHullGeoprocess convexHull = new ConvexHullGeoprocess();
|
1031 |
convexHull.setFirstOperand(inputLayer); |
1032 |
|
1033 |
SHPLayerDefinition definition = (SHPLayerDefinition) convexHull |
1034 |
.createLayerDefinition(); |
1035 |
definition.setFile(outputFile); |
1036 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
1037 |
ShpWriter writer = getShpWriter(definition); |
1038 |
if (writer == null) |
1039 |
return;
|
1040 |
|
1041 |
convexHull.setResultLayerProperties(writer, schemaManager); |
1042 |
HashMap params = new HashMap(); |
1043 |
boolean onlySelected = geoProcessingConvexHullPanel
|
1044 |
.isConvexHullOnlySelected(); |
1045 |
params.put("layer_selection", new Boolean(onlySelected)); |
1046 |
try {
|
1047 |
convexHull.setParameters(params); |
1048 |
IMonitorableTask task1 = convexHull.createTask(); |
1049 |
if(task1 == null){ |
1050 |
//TODO Mostrar mensaje de error
|
1051 |
//Hacemos que createTask lance excepcion ??
|
1052 |
return;
|
1053 |
|
1054 |
} |
1055 |
IMonitorableTask task2 = new AddResultLayerTask(convexHull);
|
1056 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
1057 |
task2); |
1058 |
if (globalTask.preprocess())
|
1059 |
PluginServices.cancelableBackgroundExecution(globalTask); |
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
} catch (GeoprocessException e) {
|
1067 |
// TODO Mostrar dialogo de error
|
1068 |
e.printStackTrace(); |
1069 |
return;
|
1070 |
} |
1071 |
} |
1072 |
|
1073 |
public void doDifference() { |
1074 |
FLyrVect inputLayer = geoProcessingDifferencePanel.getFirstLayer(); |
1075 |
FLyrVect overlayLayer = geoProcessingDifferencePanel.getSecondLayer(); |
1076 |
File outputFile = geoProcessingDifferencePanel.getOutputFile();
|
1077 |
DifferenceGeoprocess diff = new DifferenceGeoprocess(inputLayer);
|
1078 |
diff.setSecondOperand(overlayLayer); |
1079 |
SHPLayerDefinition definition = (SHPLayerDefinition) diff |
1080 |
.createLayerDefinition(); |
1081 |
definition.setFile(outputFile); |
1082 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
1083 |
ShpWriter writer = null;
|
1084 |
try {
|
1085 |
writer = new ShpWriter();
|
1086 |
writer.setFile(outputFile); |
1087 |
writer.initialize(definition); |
1088 |
} catch (IOException e) { |
1089 |
// TODO PONER MENSAJE DE ERROR INTERNACIONALIZADO
|
1090 |
e.printStackTrace(); |
1091 |
return;
|
1092 |
} catch (DriverException e) {
|
1093 |
// TODO Mostrar dialogo informando del error
|
1094 |
e.printStackTrace(); |
1095 |
return;
|
1096 |
} |
1097 |
diff.setResultLayerProperties(writer, schemaManager); |
1098 |
HashMap params = new HashMap(); |
1099 |
boolean onlySelectedFirst = geoProcessingDifferencePanel
|
1100 |
.onlyFirstLayerSelected(); |
1101 |
boolean onlySelectedSecond = geoProcessingDifferencePanel
|
1102 |
.onlySecondLayerSelected(); |
1103 |
Boolean first = new Boolean(onlySelectedFirst); |
1104 |
params.put("firstlayerselection", first);
|
1105 |
|
1106 |
Boolean second = new Boolean(onlySelectedSecond); |
1107 |
params.put("secondlayerselection", second);
|
1108 |
|
1109 |
try {
|
1110 |
diff.setParameters(params); |
1111 |
diff.checkPreconditions(); |
1112 |
|
1113 |
IMonitorableTask task1 = diff.createTask(); |
1114 |
if(task1 == null){ |
1115 |
//TODO Mostrar mensaje de error
|
1116 |
//Hacemos que createTask lance excepcion ??
|
1117 |
return;
|
1118 |
|
1119 |
} |
1120 |
IMonitorableTask task2 = new AddResultLayerTask(diff);
|
1121 |
MonitorableDecorator globalTask = new MonitorableDecorator(task1,
|
1122 |
task2); |
1123 |
if (globalTask.preprocess())
|
1124 |
PluginServices.cancelableBackgroundExecution(globalTask); |
1125 |
|
1126 |
} catch (GeoprocessException e) {
|
1127 |
// TODO Mostrar dialogo de error
|
1128 |
e.printStackTrace(); |
1129 |
return;
|
1130 |
} |
1131 |
} |
1132 |
|
1133 |
/**
|
1134 |
* Implementation of IMonitorableTask that add result layer
|
1135 |
* of a geoprocess to the TOC in a background thread
|
1136 |
* @author azabala
|
1137 |
*
|
1138 |
*/
|
1139 |
class AddResultLayerTask implements IMonitorableTask { |
1140 |
int initialStep = 1; |
1141 |
|
1142 |
int currentStep = 5; |
1143 |
|
1144 |
int lastStep = 10; |
1145 |
|
1146 |
boolean finished = false; |
1147 |
|
1148 |
IGeoprocess geoprocess; |
1149 |
|
1150 |
public AddResultLayerTask(IGeoprocess geoprocess) {
|
1151 |
this.geoprocess = geoprocess;
|
1152 |
} |
1153 |
|
1154 |
public int getInitialStep() { |
1155 |
return initialStep;
|
1156 |
} |
1157 |
|
1158 |
public int getFinishStep() { |
1159 |
return lastStep;
|
1160 |
} |
1161 |
|
1162 |
public int getCurrentStep() { |
1163 |
if (!finished)
|
1164 |
return 5; |
1165 |
else
|
1166 |
return lastStep;
|
1167 |
} |
1168 |
|
1169 |
public String getStatusMessage() { |
1170 |
return "Loading layer..."; |
1171 |
} |
1172 |
|
1173 |
public String getNote() { |
1174 |
return ""; |
1175 |
} |
1176 |
|
1177 |
public boolean isDefined() { |
1178 |
return true; |
1179 |
} |
1180 |
|
1181 |
public void cancel() { |
1182 |
finished = true;
|
1183 |
} |
1184 |
|
1185 |
public void run() throws GeoprocessException { |
1186 |
try {
|
1187 |
layers.addLayer(geoprocess.getResult()); |
1188 |
} catch (CancelationException e) {
|
1189 |
throw new GeoprocessException( |
1190 |
"Error al a?adir el resultado de un geoproceso a flayers");
|
1191 |
} finally {
|
1192 |
finished = true;
|
1193 |
} |
1194 |
} |
1195 |
|
1196 |
public boolean isCanceled() { |
1197 |
return false; |
1198 |
} |
1199 |
|
1200 |
public boolean isFinished() { |
1201 |
return finished;
|
1202 |
} |
1203 |
} |
1204 |
|
1205 |
} // @jve:decl-index=0:visual-constraint="10,10"
|