Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_914 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / intersection / IntersectionGeoprocessController.java @ 12200

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