Statistics
| Revision:

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

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

    
82
import java.io.File;
83
import java.io.FileNotFoundException;
84
import java.util.HashMap;
85

    
86
import com.iver.andami.PluginServices;
87
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
88
import com.iver.cit.gvsig.fmap.edition.IWriter;
89
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
90
import com.iver.cit.gvsig.fmap.layers.FLayers;
91
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
92
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
93
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
94
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
95
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
96
import com.iver.cit.gvsig.geoprocess.core.gui.GeoProcessingOverlayPanel;
97
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel;
98
import com.iver.cit.gvsig.geoprocess.impl.difference.fmap.DifferenceGeoprocess;
99
import com.iver.utiles.swing.threads.IMonitorableTask;
100
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
101

    
102
public class DifferenceGeoprocessController extends
103
                AbstractGeoprocessController {
104

    
105
        
106
        private GeoProcessingOverlayPanel geoProcessingDifferencePanel;
107
        private DifferenceGeoprocess difference;
108
        public void setView(IGeoprocessPanel viewPanel) {
109
                geoProcessingDifferencePanel = 
110
                        (GeoProcessingOverlayPanel) viewPanel;
111
        }
112

    
113
        public IGeoprocess getGeoprocess() {
114
                return difference;
115
        }
116

    
117
        public boolean launchGeoprocess() {
118
                FLyrVect inputLayer = geoProcessingDifferencePanel.getInputLayer();
119
                FLayers layers = geoProcessingDifferencePanel.getFLayers();
120
                FLyrVect overlayLayer = geoProcessingDifferencePanel.getSecondLayer();
121
                File outputFile = null;
122
                try {
123
                        outputFile = geoProcessingDifferencePanel.getOutputFile();
124
                } catch (FileNotFoundException e3) {
125
                        String error = PluginServices.getText(this, "Error_entrada_datos");
126
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
127
                        geoProcessingDifferencePanel.error(errorDescription, error);
128
                        return false;
129
                }
130
                if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
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
                if (outputFile.exists()) {
137
                        if (!geoProcessingDifferencePanel.askForOverwriteOutputFile(outputFile)) {
138
                                return false;
139
                        }
140
                }
141
                DifferenceGeoprocess diff = new DifferenceGeoprocess(inputLayer);
142
                diff.setSecondOperand(overlayLayer);
143
                SHPLayerDefinition definition = (SHPLayerDefinition) diff
144
                                .createLayerDefinition();
145
                definition.setFile(outputFile);
146
                ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
147
                IWriter writer = null;
148
                try {
149
                        writer = getShpWriter(definition);
150
                } catch (Exception e1) {
151
                        String error = PluginServices.getText(this, "Error_escritura_resultados");
152
                        String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados");
153
                        geoProcessingDifferencePanel.error(errorDescription, error);
154
                        return false;
155
                } 
156
                diff.setResultLayerProperties(writer, schemaManager);
157
                HashMap params = new HashMap();
158
                boolean onlySelectedFirst = geoProcessingDifferencePanel
159
                                .onlyFirstLayerSelected();
160
                boolean onlySelectedSecond = geoProcessingDifferencePanel
161
                                .onlySecondLayerSelected();
162
                Boolean first = new Boolean(onlySelectedFirst);
163
                params.put("firstlayerselection", first);
164

    
165
                Boolean second = new Boolean(onlySelectedSecond);
166
                params.put("secondlayerselection", second);
167

    
168
                try {
169
                        diff.setParameters(params);
170
                        diff.checkPreconditions();
171
                        
172
                        IMonitorableTask task1 = diff.createTask();
173
                        if(task1 == null){
174
                                return false;
175
                                
176
                        }
177
                        AddResultLayerTask task2 = new AddResultLayerTask(diff);
178
                        task2.setLayers(layers);
179
                        MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
180
                                        task2);
181
                        if(!overlayLayer.isSpatiallyIndexed()){
182
                                final IMonitorableTask sptIdxTask = 
183
                                        geoProcessingDifferencePanel.askForSpatialIndexCreation(overlayLayer);
184
                                if(sptIdxTask != null){
185
                                        PluginServices.backgroundExecution(
186
                                                        new Runnable(){
187
                                                public void run() {
188
                                                        PluginServices.
189
                                                        cancelableBackgroundExecution(sptIdxTask);        
190
                                                }}
191
                                        );
192
                                }        
193
                        }//if
194
                        if (globalTask.preprocess())
195
                                PluginServices.cancelableBackgroundExecution(globalTask);
196
                        
197
                } catch (GeoprocessException e) {
198
                        String error = PluginServices.getText(this, "Error_ejecucion");
199
                        String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso");
200
                        geoProcessingDifferencePanel.error(errorDescription, error);
201
                        return false;
202
                }
203
                return true;
204
        }
205

    
206
}
207