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