root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / dissolve / DissolveGeoprocessController.java @ 8214
History | View | Annotate | Download (7.43 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 | 8214 | azabala | * Revision 1.6 2006-10-20 14:29:46 azabala
|
49 | * removed unused imports
|
||
50 | *
|
||
51 | * Revision 1.5 2006/08/11 16:20:24 azabala
|
||
52 | 6748 | azabala | * *** empty log message ***
|
53 | *
|
||
54 | * Revision 1.4 2006/07/24 15:00:27 azabala
|
||
55 | 6511 | azabala | * fixed bug in IWriter creation.
|
56 | *
|
||
57 | * Revision 1.3 2006/07/21 09:10:34 azabala
|
||
58 | 6489 | azabala | * fixed bug 608: user doesnt enter any result file to the geoprocess panel
|
59 | *
|
||
60 | * Revision 1.2 2006/06/29 07:33:57 fjp
|
||
61 | 6093 | fjp | * Cambios ISchemaManager y IFieldManager por terminar
|
62 | *
|
||
63 | * Revision 1.1 2006/06/20 18:20:45 azabala
|
||
64 | 5918 | azabala | * first version in cvs
|
65 | *
|
||
66 | * Revision 1.3 2006/06/02 18:21:28 azabala
|
||
67 | * *** empty log message ***
|
||
68 | *
|
||
69 | * Revision 1.2 2006/05/25 08:21:48 jmvivo
|
||
70 | * A?adida peticion de confirmacion para sobreescribir el fichero de salida, si este ya existiera
|
||
71 | *
|
||
72 | * Revision 1.1 2006/05/24 21:11:14 azabala
|
||
73 | * primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
||
74 | *
|
||
75 | * Revision 1.2 2006/05/08 15:35:32 azabala
|
||
76 | * *** empty log message ***
|
||
77 | *
|
||
78 | * Revision 1.1 2006/04/11 17:55:51 azabala
|
||
79 | * primera version en cvs
|
||
80 | *
|
||
81 | *
|
||
82 | */
|
||
83 | package com.iver.cit.gvsig.geoprocess.impl.dissolve; |
||
84 | |||
85 | import java.io.File; |
||
86 | 6489 | azabala | import java.io.FileNotFoundException; |
87 | 5918 | azabala | import java.util.HashMap; |
88 | import java.util.Map; |
||
89 | |||
90 | import com.iver.andami.PluginServices; |
||
91 | import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
||
92 | 6511 | azabala | import com.iver.cit.gvsig.fmap.edition.IWriter; |
93 | 5918 | azabala | import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
94 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
95 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
96 | import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController; |
||
97 | import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
||
98 | import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
||
99 | import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask; |
||
100 | import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
||
101 | import com.iver.cit.gvsig.geoprocess.impl.dissolve.fmap.DissolveGeoprocess; |
||
102 | 6748 | azabala | import com.iver.cit.gvsig.geoprocess.impl.dissolve.gui.DissolvePanelIF; |
103 | 5918 | azabala | import com.iver.utiles.swing.threads.IMonitorableTask; |
104 | import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
||
105 | |||
106 | public class DissolveGeoprocessController extends AbstractGeoprocessController { |
||
107 | 6748 | azabala | private DissolvePanelIF geoProcessingDissolvePanel;
|
108 | 5918 | azabala | private DissolveGeoprocess dissolve;
|
109 | |||
110 | public void setView(IGeoprocessPanel viewPanel) { |
||
111 | this.geoProcessingDissolvePanel =
|
||
112 | 6748 | azabala | (DissolvePanelIF) viewPanel; |
113 | 5918 | azabala | } |
114 | |||
115 | public IGeoprocess getGeoprocess() {
|
||
116 | return dissolve;
|
||
117 | } |
||
118 | |||
119 | public boolean launchGeoprocess() { |
||
120 | FLyrVect inputLayer = geoProcessingDissolvePanel.getInputLayer(); |
||
121 | FLayers layers = geoProcessingDissolvePanel.getFLayers(); |
||
122 | 6489 | azabala | File outputFile = null; |
123 | try {
|
||
124 | outputFile = geoProcessingDissolvePanel.getOutputFile(); |
||
125 | } catch (FileNotFoundException e3) { |
||
126 | String error = PluginServices.getText(this, "Error_entrada_datos"); |
||
127 | String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
||
128 | geoProcessingDissolvePanel.error(errorDescription, error); |
||
129 | return false; |
||
130 | } |
||
131 | 5918 | azabala | if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
132 | String error = PluginServices.getText(this, "Error_entrada_datos"); |
||
133 | String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
||
134 | geoProcessingDissolvePanel.error(errorDescription, error); |
||
135 | return false; |
||
136 | } |
||
137 | if (outputFile.exists()) {
|
||
138 | if (!geoProcessingDissolvePanel.askForOverwriteOutputFile(outputFile)) {
|
||
139 | return false; |
||
140 | } |
||
141 | } |
||
142 | String dissolveField = geoProcessingDissolvePanel
|
||
143 | .getDissolveFieldName(); |
||
144 | boolean onlySelection = geoProcessingDissolvePanel
|
||
145 | .isDissolveOnlySelected(); |
||
146 | boolean onlyAdjacents = geoProcessingDissolvePanel.onlyAdjacentSelected();
|
||
147 | DissolveGeoprocess dissolve = new DissolveGeoprocess(inputLayer,
|
||
148 | dissolveField); |
||
149 | |||
150 | // Antes de crear el esquema vemos la seleccion del usuario
|
||
151 | Map fields_functions = geoProcessingDissolvePanel.getFieldFunctionMap();
|
||
152 | dissolve.setFieldsFunctions(fields_functions); |
||
153 | |||
154 | HashMap params = new HashMap(); |
||
155 | params.put("layer_selection", new Boolean(onlySelection)); |
||
156 | params.put("only_adjacents", new Boolean(onlyAdjacents)); |
||
157 | try {
|
||
158 | dissolve.setParameters(params); |
||
159 | } catch (GeoprocessException e1) {
|
||
160 | String error = PluginServices.getText(this, "Error_escritura_resultados"); |
||
161 | String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
||
162 | geoProcessingDissolvePanel.error(errorDescription, error); |
||
163 | return false; |
||
164 | } |
||
165 | |||
166 | SHPLayerDefinition definition = (SHPLayerDefinition) dissolve |
||
167 | .createLayerDefinition(); |
||
168 | definition.setFile(outputFile); |
||
169 | 6093 | fjp | ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
170 | 5918 | azabala | |
171 | 6511 | azabala | |
172 | IWriter writer = null;
|
||
173 | 5918 | azabala | try {
|
174 | 6511 | azabala | writer = getShpWriter(definition); |
175 | } catch (Exception e1) { |
||
176 | 5918 | azabala | String error = PluginServices.getText(this, "Error_escritura_resultados"); |
177 | String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
||
178 | geoProcessingDissolvePanel.error(errorDescription, error); |
||
179 | return false; |
||
180 | } |
||
181 | 6511 | azabala | |
182 | 5918 | azabala | dissolve.setResultLayerProperties(writer, schemaManager); |
183 | |||
184 | try {
|
||
185 | |||
186 | dissolve.checkPreconditions(); |
||
187 | IMonitorableTask task1 = dissolve.createTask(); |
||
188 | AddResultLayerTask task2 = new AddResultLayerTask(dissolve);
|
||
189 | task2.setLayers(layers); |
||
190 | MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
||
191 | task2); |
||
192 | //if dissolving is spatial based, checks spatial
|
||
193 | //index existency
|
||
194 | if(geoProcessingDissolvePanel.onlyAdjacentSelected()){
|
||
195 | if(inputLayer.getISpatialIndex() == null){ |
||
196 | final IMonitorableTask sptIdxTask =
|
||
197 | geoProcessingDissolvePanel.askForSpatialIndexCreation(inputLayer); |
||
198 | if(sptIdxTask != null){ |
||
199 | PluginServices.backgroundExecution( |
||
200 | new Runnable(){ |
||
201 | public void run() { |
||
202 | PluginServices. |
||
203 | cancelableBackgroundExecution(sptIdxTask); |
||
204 | }} |
||
205 | ); |
||
206 | } |
||
207 | }//if
|
||
208 | } |
||
209 | if (globalTask.preprocess())
|
||
210 | PluginServices.cancelableBackgroundExecution(globalTask); |
||
211 | } catch (GeoprocessException e) {
|
||
212 | String error = PluginServices.getText(this, "Error_ejecucion"); |
||
213 | String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
||
214 | geoProcessingDissolvePanel.error(errorDescription, error); |
||
215 | return false; |
||
216 | } |
||
217 | return true; |
||
218 | } |
||
219 | |||
220 | } |