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