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