Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / convexhull / ConvexHullGeoprocessController.java @ 10626

History | View | Annotate | Download (6.64 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: ConvexHullGeoprocessController.java 10626 2007-03-06 16:55:54Z caballero $
47
* $Log$
48
* Revision 1.7  2007-03-06 16:47:58  caballero
49
* Exceptions
50
*
51
* Revision 1.6  2006/11/29 13:11:23  jmvivo
52
* Se ha a?adido mas informaci?n al mensaje de error para los GeoprocessException: e.getMessage()
53
*
54
* Revision 1.5  2006/10/23 10:28:55  caballero
55
* ancho y alto del panel
56
*
57
* Revision 1.4  2006/08/11 16:20:24  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.3  2006/07/21 09:10:34  azabala
61
* 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
* Cambios ISchemaManager y IFieldManager por terminar
65
*
66
* Revision 1.1  2006/06/20 18:20:45  azabala
67
* first version in cvs
68
*
69
* Revision 1.3  2006/06/12 19:15:38  azabala
70
* cambios para poder trabajar en geoprocessing con capas MULTI (dxf, jdbc, etc)
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:13:52  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:23  azabala
79
* refactoring of ITask api
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.convexhull;
87

    
88
import java.io.File;
89
import java.io.FileNotFoundException;
90
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
import com.iver.cit.gvsig.geoprocess.impl.convexhull.fmap.ConvexHullGeoprocess;
104
import com.iver.cit.gvsig.geoprocess.impl.convexhull.gui.ConvexHullPanelIF;
105
import com.iver.utiles.swing.threads.IMonitorableTask;
106
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
107

    
108
public class ConvexHullGeoprocessController extends
109
                AbstractGeoprocessController {
110

    
111

    
112
        private ConvexHullPanelIF geoProcessingConvexHullPanel;
113
        private ConvexHullGeoprocess convexHull;
114
        public void setView(IGeoprocessPanel viewPanel) {
115
                this.geoProcessingConvexHullPanel =
116
                        (ConvexHullPanelIF) viewPanel;
117
        }
118
        public IGeoprocess getGeoprocess() {
119
                return convexHull;
120
        }
121

    
122
        public boolean launchGeoprocess() {
123
                FLyrVect inputLayer = geoProcessingConvexHullPanel.getInputLayer();
124
                FLayers layers = geoProcessingConvexHullPanel.getFLayers();
125
                File outputFile = null;
126
                try {
127
                        outputFile = geoProcessingConvexHullPanel.getOutputFile();
128
                } catch (FileNotFoundException e3) {
129
                        String error = PluginServices.getText(this, "Error_entrada_datos");
130
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
131
                        geoProcessingConvexHullPanel.error(errorDescription, error);
132
                        return false;
133
                }
134
                if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
135
                        String error = PluginServices.getText(this, "Error_entrada_datos");
136
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
137
                        geoProcessingConvexHullPanel.error(errorDescription, error);
138
                        return false;
139
                }
140
                if (outputFile.exists()) {
141
                        if (!geoProcessingConvexHullPanel.askForOverwriteOutputFile(outputFile)) {
142
                                return false;
143
                        }
144
                }
145
                ConvexHullGeoprocess convexHull = new ConvexHullGeoprocess();
146
                convexHull.setFirstOperand(inputLayer);
147

    
148
                SHPLayerDefinition definition = (SHPLayerDefinition) convexHull
149
                                .createLayerDefinition();
150
                definition.setFile(outputFile);
151
                ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
152
                IWriter writer = null;
153
                try {
154
                        writer = getShpWriter(definition);
155
                } catch (Exception e1) {
156
                        String error = PluginServices.getText(this, "Error_escritura_resultados");
157
                        String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados");
158
                        geoProcessingConvexHullPanel.error(errorDescription, error);
159
                        return false;
160
                }
161
                convexHull.setResultLayerProperties(writer, schemaManager);
162
                HashMap params = new HashMap();
163
                boolean onlySelected = geoProcessingConvexHullPanel
164
                                .isConvexHullOnlySelected();
165
                params.put("layer_selection", new Boolean(onlySelected));
166
                try {
167
                        convexHull.setParameters(params);
168
                        convexHull.checkPreconditions();
169
                        IMonitorableTask task1 = convexHull.createTask();
170
                        if(task1 == null){
171
                                return false;
172

    
173
                        }
174
                        AddResultLayerTask task2 = new AddResultLayerTask(convexHull);
175
                        task2.setLayers(layers);
176
                        MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
177
                                        task2);
178
                        if (globalTask.preprocess())
179
                                PluginServices.cancelableBackgroundExecution(globalTask);
180

    
181
                } catch (GeoprocessException e) {
182
                        String error = PluginServices.getText(this, "Error_ejecucion");
183
                        String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso");
184
                        errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>";
185
                        geoProcessingConvexHullPanel.error(errorDescription, error);
186
                        return false;
187
                }
188
                return true;
189
        }
190
        public int getWidth() {
191
                return 700;
192
        }
193

    
194
        public int getHeight() {
195
                return 200;
196
        }
197
}
198