root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / convexhull / ConvexHullGeoprocessController.java @ 8235
History | View | Annotate | Download (6.44 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 | 8235 | caballero | * Revision 1.5 2006-10-23 10:28:55 caballero
|
49 | * ancho y alto del panel
|
||
50 | *
|
||
51 | * Revision 1.4 2006/08/11 16:20:24 azabala
|
||
52 | 6748 | azabala | * *** empty log message ***
|
53 | *
|
||
54 | * Revision 1.3 2006/07/21 09:10:34 azabala
|
||
55 | 6489 | azabala | * fixed bug 608: user doesnt enter any result file to the geoprocess panel
|
56 | *
|
||
57 | * Revision 1.2 2006/06/29 07:33:57 fjp
|
||
58 | 6093 | fjp | * Cambios ISchemaManager y IFieldManager por terminar
|
59 | *
|
||
60 | * Revision 1.1 2006/06/20 18:20:45 azabala
|
||
61 | 5918 | azabala | * first version in cvs
|
62 | *
|
||
63 | * Revision 1.3 2006/06/12 19:15:38 azabala
|
||
64 | * cambios para poder trabajar en geoprocessing con capas MULTI (dxf, jdbc, etc)
|
||
65 | *
|
||
66 | * Revision 1.2 2006/05/25 08:21:48 jmvivo
|
||
67 | * A?adida peticion de confirmacion para sobreescribir el fichero de salida, si este ya existiera
|
||
68 | *
|
||
69 | * Revision 1.1 2006/05/24 21:13:52 azabala
|
||
70 | * primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
||
71 | *
|
||
72 | * Revision 1.2 2006/05/08 15:35:23 azabala
|
||
73 | * refactoring of ITask api
|
||
74 | *
|
||
75 | * Revision 1.1 2006/04/11 17:55:51 azabala
|
||
76 | * primera version en cvs
|
||
77 | *
|
||
78 | *
|
||
79 | */
|
||
80 | package com.iver.cit.gvsig.geoprocess.impl.convexhull; |
||
81 | |||
82 | import java.io.File; |
||
83 | 6489 | azabala | import java.io.FileNotFoundException; |
84 | 5918 | azabala | import java.util.HashMap; |
85 | |||
86 | import com.iver.andami.PluginServices; |
||
87 | import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
||
88 | import com.iver.cit.gvsig.fmap.edition.IWriter; |
||
89 | import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
||
90 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
91 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
92 | import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController; |
||
93 | import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
||
94 | import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
||
95 | import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask; |
||
96 | import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
||
97 | import com.iver.cit.gvsig.geoprocess.impl.convexhull.fmap.ConvexHullGeoprocess; |
||
98 | 6748 | azabala | import com.iver.cit.gvsig.geoprocess.impl.convexhull.gui.ConvexHullPanelIF; |
99 | import com.iver.cit.gvsig.geoprocess.impl.convexhull.gui.GeoProcessingConvexHullPanel2; |
||
100 | 5918 | azabala | import com.iver.utiles.swing.threads.IMonitorableTask; |
101 | import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
||
102 | |||
103 | public class ConvexHullGeoprocessController extends |
||
104 | AbstractGeoprocessController { |
||
105 | |||
106 | 8235 | caballero | |
107 | 6748 | azabala | private ConvexHullPanelIF geoProcessingConvexHullPanel;
|
108 | 5918 | azabala | private ConvexHullGeoprocess convexHull;
|
109 | public void setView(IGeoprocessPanel viewPanel) { |
||
110 | 8235 | caballero | this.geoProcessingConvexHullPanel =
|
111 | 6748 | azabala | (ConvexHullPanelIF) viewPanel; |
112 | 5918 | azabala | } |
113 | public IGeoprocess getGeoprocess() {
|
||
114 | return convexHull;
|
||
115 | } |
||
116 | |||
117 | public boolean launchGeoprocess() { |
||
118 | FLyrVect inputLayer = geoProcessingConvexHullPanel.getInputLayer(); |
||
119 | FLayers layers = geoProcessingConvexHullPanel.getFLayers(); |
||
120 | 6489 | azabala | File outputFile = null; |
121 | try {
|
||
122 | outputFile = geoProcessingConvexHullPanel.getOutputFile(); |
||
123 | } catch (FileNotFoundException e3) { |
||
124 | String error = PluginServices.getText(this, "Error_entrada_datos"); |
||
125 | String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
||
126 | geoProcessingConvexHullPanel.error(errorDescription, error); |
||
127 | return false; |
||
128 | } |
||
129 | 5918 | azabala | if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
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.exists()) {
|
||
136 | if (!geoProcessingConvexHullPanel.askForOverwriteOutputFile(outputFile)) {
|
||
137 | return false; |
||
138 | } |
||
139 | } |
||
140 | ConvexHullGeoprocess convexHull = new ConvexHullGeoprocess();
|
||
141 | convexHull.setFirstOperand(inputLayer); |
||
142 | |||
143 | SHPLayerDefinition definition = (SHPLayerDefinition) convexHull |
||
144 | .createLayerDefinition(); |
||
145 | definition.setFile(outputFile); |
||
146 | 6093 | fjp | ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
147 | 5918 | azabala | IWriter writer = null;
|
148 | try {
|
||
149 | writer = getShpWriter(definition); |
||
150 | } catch (Exception e1) { |
||
151 | String error = PluginServices.getText(this, "Error_escritura_resultados"); |
||
152 | String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
||
153 | geoProcessingConvexHullPanel.error(errorDescription, error); |
||
154 | return false; |
||
155 | 8235 | caballero | } |
156 | 5918 | azabala | convexHull.setResultLayerProperties(writer, schemaManager); |
157 | HashMap params = new HashMap(); |
||
158 | boolean onlySelected = geoProcessingConvexHullPanel
|
||
159 | .isConvexHullOnlySelected(); |
||
160 | params.put("layer_selection", new Boolean(onlySelected)); |
||
161 | try {
|
||
162 | convexHull.setParameters(params); |
||
163 | convexHull.checkPreconditions(); |
||
164 | IMonitorableTask task1 = convexHull.createTask(); |
||
165 | if(task1 == null){ |
||
166 | return false; |
||
167 | 8235 | caballero | |
168 | 5918 | azabala | } |
169 | AddResultLayerTask task2 = new AddResultLayerTask(convexHull);
|
||
170 | task2.setLayers(layers); |
||
171 | MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
||
172 | task2); |
||
173 | if (globalTask.preprocess())
|
||
174 | PluginServices.cancelableBackgroundExecution(globalTask); |
||
175 | 8235 | caballero | |
176 | 5918 | azabala | } catch (GeoprocessException e) {
|
177 | String error = PluginServices.getText(this, "Error_ejecucion"); |
||
178 | String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
||
179 | geoProcessingConvexHullPanel.error(errorDescription, error); |
||
180 | return false; |
||
181 | } |
||
182 | return true; |
||
183 | } |
||
184 | 8235 | caballero | public int getWidth() { |
185 | return 700; |
||
186 | } |
||
187 | 5918 | azabala | |
188 | 8235 | caballero | public int getHeight() { |
189 | return 200; |
||
190 | } |
||
191 | 5918 | azabala | } |