svn-gvsig-desktop / tags / v1_1_Build_1008 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / difference / DifferenceGeoprocessController.java @ 12520
History | View | Annotate | Download (7.51 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 | 6748 | azabala | * *** empty log message ***
|
53 | *
|
||
54 | 8765 | jjdelcerro | * Revision 1.5 2006/10/23 10:29:03 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 | 6748 | 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:23:56 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:11:50 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.difference; |
||
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 | 6748 | azabala | import com.iver.cit.gvsig.geoprocess.core.gui.OverlayPanelIF; |
110 | 5918 | azabala | import com.iver.cit.gvsig.geoprocess.impl.difference.fmap.DifferenceGeoprocess; |
111 | import com.iver.utiles.swing.threads.IMonitorableTask; |
||
112 | import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
||
113 | |||
114 | public class DifferenceGeoprocessController extends |
||
115 | AbstractGeoprocessController { |
||
116 | |||
117 | 8765 | jjdelcerro | |
118 | 6748 | azabala | private OverlayPanelIF geoProcessingDifferencePanel;
|
119 | 5918 | azabala | private DifferenceGeoprocess difference;
|
120 | public void setView(IGeoprocessPanel viewPanel) { |
||
121 | 8765 | jjdelcerro | geoProcessingDifferencePanel = |
122 | 6748 | azabala | (OverlayPanelIF) viewPanel; |
123 | 5918 | azabala | } |
124 | |||
125 | public IGeoprocess getGeoprocess() {
|
||
126 | return difference;
|
||
127 | } |
||
128 | |||
129 | public boolean launchGeoprocess() { |
||
130 | FLyrVect inputLayer = geoProcessingDifferencePanel.getInputLayer(); |
||
131 | FLayers layers = geoProcessingDifferencePanel.getFLayers(); |
||
132 | FLyrVect overlayLayer = geoProcessingDifferencePanel.getSecondLayer(); |
||
133 | 6489 | azabala | File outputFile = null; |
134 | try {
|
||
135 | outputFile = geoProcessingDifferencePanel.getOutputFile(); |
||
136 | } catch (FileNotFoundException e3) { |
||
137 | String error = PluginServices.getText(this, "Error_entrada_datos"); |
||
138 | String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
||
139 | geoProcessingDifferencePanel.error(errorDescription, error); |
||
140 | return false; |
||
141 | } |
||
142 | 5918 | azabala | if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
143 | String error = PluginServices.getText(this, "Error_entrada_datos"); |
||
144 | String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
||
145 | geoProcessingDifferencePanel.error(errorDescription, error); |
||
146 | return false; |
||
147 | } |
||
148 | if (outputFile.exists()) {
|
||
149 | if (!geoProcessingDifferencePanel.askForOverwriteOutputFile(outputFile)) {
|
||
150 | return false; |
||
151 | } |
||
152 | } |
||
153 | DifferenceGeoprocess diff = new DifferenceGeoprocess(inputLayer);
|
||
154 | diff.setSecondOperand(overlayLayer); |
||
155 | SHPLayerDefinition definition = (SHPLayerDefinition) diff |
||
156 | .createLayerDefinition(); |
||
157 | definition.setFile(outputFile); |
||
158 | 6093 | fjp | ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
159 | 5918 | azabala | IWriter writer = null;
|
160 | try {
|
||
161 | writer = getShpWriter(definition); |
||
162 | } catch (Exception e1) { |
||
163 | String error = PluginServices.getText(this, "Error_escritura_resultados"); |
||
164 | String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
||
165 | geoProcessingDifferencePanel.error(errorDescription, error); |
||
166 | return false; |
||
167 | 8765 | jjdelcerro | } |
168 | 5918 | azabala | diff.setResultLayerProperties(writer, schemaManager); |
169 | HashMap params = new HashMap(); |
||
170 | boolean onlySelectedFirst = geoProcessingDifferencePanel
|
||
171 | .onlyFirstLayerSelected(); |
||
172 | boolean onlySelectedSecond = geoProcessingDifferencePanel
|
||
173 | .onlySecondLayerSelected(); |
||
174 | Boolean first = new Boolean(onlySelectedFirst); |
||
175 | params.put("firstlayerselection", first);
|
||
176 | |||
177 | Boolean second = new Boolean(onlySelectedSecond); |
||
178 | params.put("secondlayerselection", second);
|
||
179 | |||
180 | try {
|
||
181 | diff.setParameters(params); |
||
182 | diff.checkPreconditions(); |
||
183 | 8765 | jjdelcerro | |
184 | 5918 | azabala | IMonitorableTask task1 = diff.createTask(); |
185 | if(task1 == null){ |
||
186 | return false; |
||
187 | 8765 | jjdelcerro | |
188 | 5918 | azabala | } |
189 | AddResultLayerTask task2 = new AddResultLayerTask(diff);
|
||
190 | task2.setLayers(layers); |
||
191 | MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
||
192 | task2); |
||
193 | if(!overlayLayer.isSpatiallyIndexed()){
|
||
194 | 8765 | jjdelcerro | final IMonitorableTask sptIdxTask =
|
195 | 5918 | azabala | geoProcessingDifferencePanel.askForSpatialIndexCreation(overlayLayer); |
196 | if(sptIdxTask != null){ |
||
197 | PluginServices.backgroundExecution( |
||
198 | new Runnable(){ |
||
199 | public void run() { |
||
200 | PluginServices. |
||
201 | 8765 | jjdelcerro | cancelableBackgroundExecution(sptIdxTask); |
202 | 5918 | azabala | }} |
203 | ); |
||
204 | 8765 | jjdelcerro | } |
205 | 5918 | azabala | }//if
|
206 | if (globalTask.preprocess())
|
||
207 | PluginServices.cancelableBackgroundExecution(globalTask); |
||
208 | 8765 | jjdelcerro | |
209 | 5918 | azabala | } catch (GeoprocessException e) {
|
210 | String error = PluginServices.getText(this, "Error_ejecucion"); |
||
211 | String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
||
212 | 9100 | jmvivo | errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
213 | 5918 | azabala | geoProcessingDifferencePanel.error(errorDescription, error); |
214 | return false; |
||
215 | } |
||
216 | return true; |
||
217 | } |
||
218 | 8765 | jjdelcerro | public int getWidth() { |
219 | return 700; |
||
220 | } |
||
221 | 5918 | azabala | |
222 | 8765 | jjdelcerro | public int getHeight() { |
223 | return 300; |
||
224 | } |
||
225 | 5918 | azabala | } |