svn-gvsig-desktop / tags / v1_0_2_Build_905 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / convexhull / ConvexHullGeoprocessController.java @ 10767
History | View | Annotate | Download (6.75 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 10767 2007-03-15 11:13:28Z $
|
47 |
* $Log$
|
48 |
* 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 |
* *** empty log message ***
|
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.cit.gvsig.geoprocess.impl.convexhull.gui.GeoProcessingConvexHullPanel2; |
106 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
107 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
108 |
|
109 |
public class ConvexHullGeoprocessController extends |
110 |
AbstractGeoprocessController { |
111 |
|
112 |
|
113 |
private ConvexHullPanelIF geoProcessingConvexHullPanel;
|
114 |
private ConvexHullGeoprocess convexHull;
|
115 |
public void setView(IGeoprocessPanel viewPanel) { |
116 |
this.geoProcessingConvexHullPanel =
|
117 |
(ConvexHullPanelIF) viewPanel; |
118 |
} |
119 |
public IGeoprocess getGeoprocess() {
|
120 |
return convexHull;
|
121 |
} |
122 |
|
123 |
public boolean launchGeoprocess() { |
124 |
FLyrVect inputLayer = geoProcessingConvexHullPanel.getInputLayer(); |
125 |
FLayers layers = geoProcessingConvexHullPanel.getFLayers(); |
126 |
File outputFile = null; |
127 |
try {
|
128 |
outputFile = geoProcessingConvexHullPanel.getOutputFile(); |
129 |
} catch (FileNotFoundException e3) { |
130 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
131 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
132 |
geoProcessingConvexHullPanel.error(errorDescription, error); |
133 |
return false; |
134 |
} |
135 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
136 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
137 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
138 |
geoProcessingConvexHullPanel.error(errorDescription, error); |
139 |
return false; |
140 |
} |
141 |
if (outputFile.exists()) {
|
142 |
if (!geoProcessingConvexHullPanel.askForOverwriteOutputFile(outputFile)) {
|
143 |
return false; |
144 |
} |
145 |
} |
146 |
ConvexHullGeoprocess convexHull = new ConvexHullGeoprocess();
|
147 |
convexHull.setFirstOperand(inputLayer); |
148 |
|
149 |
SHPLayerDefinition definition = (SHPLayerDefinition) convexHull |
150 |
.createLayerDefinition(); |
151 |
definition.setFile(outputFile); |
152 |
ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
153 |
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 |
geoProcessingConvexHullPanel.error(errorDescription, error); |
160 |
return false; |
161 |
} |
162 |
convexHull.setResultLayerProperties(writer, schemaManager); |
163 |
HashMap params = new HashMap(); |
164 |
boolean onlySelected = geoProcessingConvexHullPanel
|
165 |
.isConvexHullOnlySelected(); |
166 |
params.put("layer_selection", new Boolean(onlySelected)); |
167 |
try {
|
168 |
convexHull.setParameters(params); |
169 |
convexHull.checkPreconditions(); |
170 |
IMonitorableTask task1 = convexHull.createTask(); |
171 |
if(task1 == null){ |
172 |
return false; |
173 |
|
174 |
} |
175 |
AddResultLayerTask task2 = new AddResultLayerTask(convexHull);
|
176 |
task2.setLayers(layers); |
177 |
MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
178 |
task2); |
179 |
if (globalTask.preprocess())
|
180 |
PluginServices.cancelableBackgroundExecution(globalTask); |
181 |
|
182 |
} catch (GeoprocessException e) {
|
183 |
String error = PluginServices.getText(this, "Error_ejecucion"); |
184 |
String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
185 |
errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
186 |
geoProcessingConvexHullPanel.error(errorDescription, error); |
187 |
return false; |
188 |
} |
189 |
return true; |
190 |
} |
191 |
public int getWidth() { |
192 |
return 700; |
193 |
} |
194 |
|
195 |
public int getHeight() { |
196 |
return 200; |
197 |
} |
198 |
} |
199 |
|