Statistics
| Revision:

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

History | View | Annotate | Download (7.44 KB)

1
/*
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: DifferenceGeoprocessController.java 21232 2008-06-05 14:03:49Z azabala $
47
* $Log$
48
* Revision 1.6  2006-11-29 13:11:23  jmvivo
49
* Se ha a?adido mas informaci?n al mensaje de error para los GeoprocessException: e.getMessage()
50
*
51
* Revision 1.5  2006/10/23 10:29:03  caballero
52
* ancho y alto del panel
53
*
54
* Revision 1.4  2006/08/11 16:20:24  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.3  2006/07/21 09:10:34  azabala
58
* fixed bug 608: user doesnt enter any result file to the geoprocess panel
59
*
60
* Revision 1.2  2006/06/29 07:33:57  fjp
61
* Cambios ISchemaManager y IFieldManager por terminar
62
*
63
* Revision 1.1  2006/06/20 18:20:45  azabala
64
* first version in cvs
65
*
66
* Revision 1.5  2006/06/12 19:15:38  azabala
67
* cambios para poder trabajar en geoprocessing con capas MULTI (dxf, jdbc, etc)
68
*
69
* Revision 1.4  2006/06/08 18:23:56  azabala
70
* cambios para considerar las capas DB como espacialmente indexadas (aunque la referencia de ISpatialIndex sea null)
71
*
72
* Revision 1.3  2006/06/02 18:21:28  azabala
73
* *** empty log message ***
74
*
75
* Revision 1.2  2006/05/25 08:21:48  jmvivo
76
* A?adida peticion de confirmacion para sobreescribir el fichero de salida, si este ya existiera
77
*
78
* Revision 1.1  2006/05/24 21:11:50  azabala
79
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
80
*
81
* Revision 1.2  2006/05/08 15:35:32  azabala
82
* *** empty log message ***
83
*
84
* Revision 1.1  2006/04/11 17:55:51  azabala
85
* primera version en cvs
86
*
87
*
88
*/
89
package com.iver.cit.gvsig.geoprocess.impl.difference;
90

    
91
import java.io.File;
92
import java.io.FileNotFoundException;
93
import java.util.HashMap;
94

    
95
import com.iver.andami.PluginServices;
96
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
97
import com.iver.cit.gvsig.fmap.edition.IWriter;
98
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
99
import com.iver.cit.gvsig.fmap.layers.FLayers;
100
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
101
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
102
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
103
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
104
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
105
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessUserEntries;
106
import com.iver.cit.gvsig.geoprocess.core.gui.OverlayPanelIF;
107
import com.iver.cit.gvsig.geoprocess.impl.difference.fmap.DifferenceGeoprocess;
108
import com.iver.utiles.swing.threads.IMonitorableTask;
109
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
110

    
111
public class DifferenceGeoprocessController extends
112
                AbstractGeoprocessController {
113

    
114

    
115
        private OverlayPanelIF geoProcessingDifferencePanel;
116
        private DifferenceGeoprocess difference;
117
        public void setView(IGeoprocessUserEntries viewPanel) {
118
                geoProcessingDifferencePanel =
119
                        (OverlayPanelIF) viewPanel;
120
        }
121

    
122
        public IGeoprocess getGeoprocess() {
123
                return difference;
124
        }
125

    
126
        public boolean launchGeoprocess() {
127
                FLyrVect inputLayer = geoProcessingDifferencePanel.getInputLayer();
128
                FLayers layers = geoProcessingDifferencePanel.getFLayers();
129
                FLyrVect overlayLayer = geoProcessingDifferencePanel.getSecondLayer();
130
                File outputFile = null;
131
                try {
132
                        outputFile = geoProcessingDifferencePanel.getOutputFile();
133
                } catch (FileNotFoundException e3) {
134
                        String error = PluginServices.getText(this, "Error_entrada_datos");
135
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
136
                        geoProcessingDifferencePanel.error(errorDescription, error);
137
                        return false;
138
                }
139
                if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
140
                        String error = PluginServices.getText(this, "Error_entrada_datos");
141
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
142
                        geoProcessingDifferencePanel.error(errorDescription, error);
143
                        return false;
144
                }
145
                if (outputFile.exists()) {
146
                        if (!geoProcessingDifferencePanel.askForOverwriteOutputFile(outputFile)) {
147
                                return false;
148
                        }
149
                }
150
                DifferenceGeoprocess diff = new DifferenceGeoprocess(inputLayer);
151
                diff.setSecondOperand(overlayLayer);
152
                SHPLayerDefinition definition = (SHPLayerDefinition) diff
153
                                .createLayerDefinition();
154
                definition.setFile(outputFile);
155
                ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
156
                IWriter writer = null;
157
                try {
158
                        writer = getShpWriter(definition);
159
                } catch (Exception e1) {
160
                        String error = PluginServices.getText(this, "Error_escritura_resultados");
161
                        String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados");
162
                        geoProcessingDifferencePanel.error(errorDescription, error);
163
                        return false;
164
                }
165
                diff.setResultLayerProperties(writer, schemaManager);
166
                HashMap params = new HashMap();
167
                boolean onlySelectedFirst = geoProcessingDifferencePanel
168
                                .onlyFirstLayerSelected();
169
                boolean onlySelectedSecond = geoProcessingDifferencePanel
170
                                .onlySecondLayerSelected();
171
                Boolean first = new Boolean(onlySelectedFirst);
172
                params.put("firstlayerselection", first);
173

    
174
                Boolean second = new Boolean(onlySelectedSecond);
175
                params.put("secondlayerselection", second);
176

    
177
                try {
178
                        diff.setParameters(params);
179
                        diff.checkPreconditions();
180

    
181
                        IMonitorableTask task1 = diff.createTask();
182
                        if(task1 == null){
183
                                return false;
184

    
185
                        }
186
                        AddResultLayerTask task2 = new AddResultLayerTask(diff);
187
                        task2.setLayers(layers);
188
                        MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
189
                                        task2);
190
                        if(!overlayLayer.isSpatiallyIndexed()){
191
                                final IMonitorableTask sptIdxTask =
192
                                        geoProcessingDifferencePanel.askForSpatialIndexCreation(overlayLayer);
193
                                if(sptIdxTask != null){
194
                                        PluginServices.backgroundExecution(
195
                                                        new Runnable(){
196
                                                public void run() {
197
                                                        PluginServices.
198
                                                        cancelableBackgroundExecution(sptIdxTask);
199
                                                }}
200
                                        );
201
                                }
202
                        }//if
203
                        if (globalTask.preprocess())
204
                                PluginServices.cancelableBackgroundExecution(globalTask);
205

    
206
                } catch (GeoprocessException e) {
207
                        String error = PluginServices.getText(this, "Error_ejecucion");
208
                        String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso");
209
                        errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>";
210
                        geoProcessingDifferencePanel.error(errorDescription, error);
211
                        return false;
212
                }
213
                return true;
214
        }
215
        public int getWidth() {
216
                return 700;
217
        }
218

    
219
        public int getHeight() {
220
                return 300;
221
        }
222
}
223