root / tags / v1_0_2_Build_903 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / dissolve / DissolveGeoprocessController.java @ 10704
History | View | Annotate | Download (7.88 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: DissolveGeoprocessController.java 10704 2007-03-12 12:06:33Z $
|
47 |
* $Log$
|
48 |
* Revision 1.5.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.5.2.1 2006/11/15 00:08:17 jjdelcerro
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.7 2006/10/23 10:29:18 caballero
|
55 |
* ancho y alto del panel
|
56 |
*
|
57 |
* Revision 1.6 2006/10/20 14:29:46 azabala
|
58 |
* removed unused imports
|
59 |
*
|
60 |
* Revision 1.5 2006/08/11 16:20:24 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
* Revision 1.4 2006/07/24 15:00:27 azabala
|
64 |
* fixed bug in IWriter creation.
|
65 |
*
|
66 |
* Revision 1.3 2006/07/21 09:10:34 azabala
|
67 |
* fixed bug 608: user doesnt enter any result file to the geoprocess panel
|
68 |
*
|
69 |
* Revision 1.2 2006/06/29 07:33:57 fjp
|
70 |
* Cambios ISchemaManager y IFieldManager por terminar
|
71 |
*
|
72 |
* Revision 1.1 2006/06/20 18:20:45 azabala
|
73 |
* first version in cvs
|
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:11:14 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.dissolve; |
93 |
|
94 |
import java.io.File; |
95 |
import java.io.FileNotFoundException; |
96 |
import java.util.HashMap; |
97 |
import java.util.Map; |
98 |
|
99 |
import com.iver.andami.PluginServices; |
100 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
101 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
102 |
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
103 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
104 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
105 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController; |
106 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
107 |
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
108 |
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask; |
109 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
110 |
import com.iver.cit.gvsig.geoprocess.impl.dissolve.fmap.DissolveGeoprocess; |
111 |
import com.iver.cit.gvsig.geoprocess.impl.dissolve.gui.DissolvePanelIF; |
112 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
113 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
114 |
|
115 |
public class DissolveGeoprocessController extends AbstractGeoprocessController { |
116 |
private DissolvePanelIF geoProcessingDissolvePanel;
|
117 |
private DissolveGeoprocess dissolve;
|
118 |
|
119 |
public void setView(IGeoprocessPanel viewPanel) { |
120 |
this.geoProcessingDissolvePanel =
|
121 |
(DissolvePanelIF) viewPanel; |
122 |
} |
123 |
|
124 |
public IGeoprocess getGeoprocess() {
|
125 |
return dissolve;
|
126 |
} |
127 |
|
128 |
public boolean launchGeoprocess() { |
129 |
FLyrVect inputLayer = geoProcessingDissolvePanel.getInputLayer(); |
130 |
FLayers layers = geoProcessingDissolvePanel.getFLayers(); |
131 |
File outputFile = null; |
132 |
try {
|
133 |
outputFile = geoProcessingDissolvePanel.getOutputFile(); |
134 |
} catch (FileNotFoundException e3) { |
135 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
136 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
137 |
geoProcessingDissolvePanel.error(errorDescription, error); |
138 |
return false; |
139 |
} |
140 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
141 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
142 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
143 |
geoProcessingDissolvePanel.error(errorDescription, error); |
144 |
return false; |
145 |
} |
146 |
if (outputFile.exists()) {
|
147 |
if (!geoProcessingDissolvePanel.askForOverwriteOutputFile(outputFile)) {
|
148 |
return false; |
149 |
} |
150 |
} |
151 |
String dissolveField = geoProcessingDissolvePanel
|
152 |
.getDissolveFieldName(); |
153 |
boolean onlySelection = geoProcessingDissolvePanel
|
154 |
.isDissolveOnlySelected(); |
155 |
boolean onlyAdjacents = geoProcessingDissolvePanel.onlyAdjacentSelected();
|
156 |
DissolveGeoprocess dissolve = new DissolveGeoprocess(inputLayer,
|
157 |
dissolveField); |
158 |
|
159 |
// Antes de crear el esquema vemos la seleccion del usuario
|
160 |
Map fields_functions = geoProcessingDissolvePanel.getFieldFunctionMap();
|
161 |
dissolve.setFieldsFunctions(fields_functions); |
162 |
|
163 |
HashMap params = new HashMap(); |
164 |
params.put("layer_selection", new Boolean(onlySelection)); |
165 |
params.put("only_adjacents", new Boolean(onlyAdjacents)); |
166 |
try {
|
167 |
dissolve.setParameters(params); |
168 |
} catch (GeoprocessException e1) {
|
169 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
170 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
171 |
geoProcessingDissolvePanel.error(errorDescription, error); |
172 |
return false; |
173 |
} |
174 |
|
175 |
SHPLayerDefinition definition = (SHPLayerDefinition) dissolve |
176 |
.createLayerDefinition(); |
177 |
definition.setFile(outputFile); |
178 |
ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
179 |
|
180 |
|
181 |
IWriter writer = null;
|
182 |
try {
|
183 |
writer = getShpWriter(definition); |
184 |
} catch (Exception e1) { |
185 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
186 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
187 |
geoProcessingDissolvePanel.error(errorDescription, error); |
188 |
return false; |
189 |
} |
190 |
|
191 |
dissolve.setResultLayerProperties(writer, schemaManager); |
192 |
|
193 |
try {
|
194 |
|
195 |
dissolve.checkPreconditions(); |
196 |
IMonitorableTask task1 = dissolve.createTask(); |
197 |
AddResultLayerTask task2 = new AddResultLayerTask(dissolve);
|
198 |
task2.setLayers(layers); |
199 |
MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
200 |
task2); |
201 |
//if dissolving is spatial based, checks spatial
|
202 |
//index existency
|
203 |
if(geoProcessingDissolvePanel.onlyAdjacentSelected()){
|
204 |
if(inputLayer.getISpatialIndex() == null){ |
205 |
final IMonitorableTask sptIdxTask =
|
206 |
geoProcessingDissolvePanel.askForSpatialIndexCreation(inputLayer); |
207 |
if(sptIdxTask != null){ |
208 |
PluginServices.backgroundExecution( |
209 |
new Runnable(){ |
210 |
public void run() { |
211 |
PluginServices. |
212 |
cancelableBackgroundExecution(sptIdxTask); |
213 |
}} |
214 |
); |
215 |
} |
216 |
}//if
|
217 |
} |
218 |
if (globalTask.preprocess())
|
219 |
PluginServices.cancelableBackgroundExecution(globalTask); |
220 |
} catch (GeoprocessException e) {
|
221 |
String error = PluginServices.getText(this, "Error_ejecucion"); |
222 |
String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
223 |
errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
224 |
geoProcessingDissolvePanel.error(errorDescription, error); |
225 |
return false; |
226 |
} |
227 |
return true; |
228 |
} |
229 |
public int getWidth() { |
230 |
return 700; |
231 |
} |
232 |
|
233 |
public int getHeight() { |
234 |
return 500; |
235 |
} |
236 |
} |
237 |
|