Statistics
| Revision:

root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / difference / DifferenceGeoprocessController.java @ 8235

History | View | Annotate | Download (7.2 KB)

1 5918 azabala
/*
2
 * Created on 11-abr-2006
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
/* CVS MESSAGES:
45
*
46
* $Id$
47
* $Log$
48 8235 caballero
* Revision 1.5  2006-10-23 10:29:03  caballero
49
* ancho y alto del panel
50
*
51
* Revision 1.4  2006/08/11 16:20:24  azabala
52 6748 azabala
* *** empty log message ***
53
*
54
* Revision 1.3  2006/07/21 09:10:34  azabala
55 6489 azabala
* fixed bug 608: user doesnt enter any result file to the geoprocess panel
56
*
57
* Revision 1.2  2006/06/29 07:33:57  fjp
58 6093 fjp
* Cambios ISchemaManager y IFieldManager por terminar
59
*
60
* Revision 1.1  2006/06/20 18:20:45  azabala
61 5918 azabala
* first version in cvs
62
*
63
* Revision 1.5  2006/06/12 19:15:38  azabala
64
* cambios para poder trabajar en geoprocessing con capas MULTI (dxf, jdbc, etc)
65
*
66
* Revision 1.4  2006/06/08 18:23:56  azabala
67
* cambios para considerar las capas DB como espacialmente indexadas (aunque la referencia de ISpatialIndex sea null)
68
*
69
* Revision 1.3  2006/06/02 18:21:28  azabala
70
* *** empty log message ***
71
*
72
* Revision 1.2  2006/05/25 08:21:48  jmvivo
73
* A?adida peticion de confirmacion para sobreescribir el fichero de salida, si este ya existiera
74
*
75
* Revision 1.1  2006/05/24 21:11:50  azabala
76
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
77
*
78
* Revision 1.2  2006/05/08 15:35:32  azabala
79
* *** empty log message ***
80
*
81
* Revision 1.1  2006/04/11 17:55:51  azabala
82
* primera version en cvs
83
*
84
*
85
*/
86
package com.iver.cit.gvsig.geoprocess.impl.difference;
87
88
import java.io.File;
89 6489 azabala
import java.io.FileNotFoundException;
90 5918 azabala
import java.util.HashMap;
91
92
import com.iver.andami.PluginServices;
93
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
94
import com.iver.cit.gvsig.fmap.edition.IWriter;
95
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
96
import com.iver.cit.gvsig.fmap.layers.FLayers;
97
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
98
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
99
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
100
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
101
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
102
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel;
103 6748 azabala
import com.iver.cit.gvsig.geoprocess.core.gui.OverlayPanelIF;
104 5918 azabala
import com.iver.cit.gvsig.geoprocess.impl.difference.fmap.DifferenceGeoprocess;
105
import com.iver.utiles.swing.threads.IMonitorableTask;
106
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
107
108
public class DifferenceGeoprocessController extends
109
                AbstractGeoprocessController {
110
111 8235 caballero
112 6748 azabala
        private OverlayPanelIF geoProcessingDifferencePanel;
113 5918 azabala
        private DifferenceGeoprocess difference;
114
        public void setView(IGeoprocessPanel viewPanel) {
115 8235 caballero
                geoProcessingDifferencePanel =
116 6748 azabala
                        (OverlayPanelIF) viewPanel;
117 5918 azabala
        }
118
119
        public IGeoprocess getGeoprocess() {
120
                return difference;
121
        }
122
123
        public boolean launchGeoprocess() {
124
                FLyrVect inputLayer = geoProcessingDifferencePanel.getInputLayer();
125
                FLayers layers = geoProcessingDifferencePanel.getFLayers();
126
                FLyrVect overlayLayer = geoProcessingDifferencePanel.getSecondLayer();
127 6489 azabala
                File outputFile = null;
128
                try {
129
                        outputFile = geoProcessingDifferencePanel.getOutputFile();
130
                } catch (FileNotFoundException e3) {
131
                        String error = PluginServices.getText(this, "Error_entrada_datos");
132
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
133
                        geoProcessingDifferencePanel.error(errorDescription, error);
134
                        return false;
135
                }
136 5918 azabala
                if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
137
                        String error = PluginServices.getText(this, "Error_entrada_datos");
138
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
139
                        geoProcessingDifferencePanel.error(errorDescription, error);
140
                        return false;
141
                }
142
                if (outputFile.exists()) {
143
                        if (!geoProcessingDifferencePanel.askForOverwriteOutputFile(outputFile)) {
144
                                return false;
145
                        }
146
                }
147
                DifferenceGeoprocess diff = new DifferenceGeoprocess(inputLayer);
148
                diff.setSecondOperand(overlayLayer);
149
                SHPLayerDefinition definition = (SHPLayerDefinition) diff
150
                                .createLayerDefinition();
151
                definition.setFile(outputFile);
152 6093 fjp
                ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
153 5918 azabala
                IWriter writer = null;
154
                try {
155
                        writer = getShpWriter(definition);
156
                } catch (Exception e1) {
157
                        String error = PluginServices.getText(this, "Error_escritura_resultados");
158
                        String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados");
159
                        geoProcessingDifferencePanel.error(errorDescription, error);
160
                        return false;
161 8235 caballero
                }
162 5918 azabala
                diff.setResultLayerProperties(writer, schemaManager);
163
                HashMap params = new HashMap();
164
                boolean onlySelectedFirst = geoProcessingDifferencePanel
165
                                .onlyFirstLayerSelected();
166
                boolean onlySelectedSecond = geoProcessingDifferencePanel
167
                                .onlySecondLayerSelected();
168
                Boolean first = new Boolean(onlySelectedFirst);
169
                params.put("firstlayerselection", first);
170
171
                Boolean second = new Boolean(onlySelectedSecond);
172
                params.put("secondlayerselection", second);
173
174
                try {
175
                        diff.setParameters(params);
176
                        diff.checkPreconditions();
177 8235 caballero
178 5918 azabala
                        IMonitorableTask task1 = diff.createTask();
179
                        if(task1 == null){
180
                                return false;
181 8235 caballero
182 5918 azabala
                        }
183
                        AddResultLayerTask task2 = new AddResultLayerTask(diff);
184
                        task2.setLayers(layers);
185
                        MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
186
                                        task2);
187
                        if(!overlayLayer.isSpatiallyIndexed()){
188 8235 caballero
                                final IMonitorableTask sptIdxTask =
189 5918 azabala
                                        geoProcessingDifferencePanel.askForSpatialIndexCreation(overlayLayer);
190
                                if(sptIdxTask != null){
191
                                        PluginServices.backgroundExecution(
192
                                                        new Runnable(){
193
                                                public void run() {
194
                                                        PluginServices.
195 8235 caballero
                                                        cancelableBackgroundExecution(sptIdxTask);
196 5918 azabala
                                                }}
197
                                        );
198 8235 caballero
                                }
199 5918 azabala
                        }//if
200
                        if (globalTask.preprocess())
201
                                PluginServices.cancelableBackgroundExecution(globalTask);
202 8235 caballero
203 5918 azabala
                } catch (GeoprocessException e) {
204
                        String error = PluginServices.getText(this, "Error_ejecucion");
205
                        String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso");
206
                        geoProcessingDifferencePanel.error(errorDescription, error);
207
                        return false;
208
                }
209
                return true;
210
        }
211 8235 caballero
        public int getWidth() {
212
                return 700;
213
        }
214 5918 azabala
215 8235 caballero
        public int getHeight() {
216
                return 300;
217
        }
218 5918 azabala
}