root / tags / v1_0_2_Build_916 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / buffer / BufferGeoprocessController.java @ 12327
History | View | Annotate | Download (9.56 KB)
1 |
/*
|
---|---|
2 |
* Created on 10-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: BufferGeoprocessController.java 12327 2007-06-25 12:40:50Z $
|
47 |
* $Log$
|
48 |
* 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 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.5 2006/10/23 10:27:38 caballero
|
55 |
* ancho y alto del panel
|
56 |
*
|
57 |
* Revision 1.4 2006/08/11 16:13:08 azabala
|
58 |
* refactoring to make logic independent from UI
|
59 |
*
|
60 |
* Revision 1.3 2006/07/21 09:10:34 azabala
|
61 |
* 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 |
* Cambios ISchemaManager y IFieldManager por terminar
|
65 |
*
|
66 |
* Revision 1.1 2006/06/20 18:20:45 azabala
|
67 |
* first version in cvs
|
68 |
*
|
69 |
* Revision 1.4 2006/06/12 19:15:38 azabala
|
70 |
* cambios para poder trabajar en geoprocessing con capas MULTI (dxf, jdbc, etc)
|
71 |
*
|
72 |
* Revision 1.3 2006/06/02 18:20:04 azabala
|
73 |
* cuando el buffer es con dissolve se crea indice espacial para optimizar
|
74 |
*
|
75 |
* Revision 1.2 2006/05/25 08:21:48 jmvivo
|
76 |
* A?adida peticion de confirmacion para sobreescribir el fichero de salida, si este ya existiera
|
77 |
*
|
78 |
* Revision 1.1 2006/05/24 21:15:07 azabala
|
79 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
80 |
*
|
81 |
* Revision 1.3 2006/05/08 15:34:59 azabala
|
82 |
* refactoring of ITask api
|
83 |
*
|
84 |
* Revision 1.2 2006/05/01 19:20:14 azabala
|
85 |
* revisi?n general del buffer (a?adidos anillos concentricos, buffers interiores y exteriores, etc)
|
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.buffer; |
93 |
|
94 |
import java.io.File; |
95 |
import java.io.FileNotFoundException; |
96 |
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 |
import com.iver.cit.gvsig.geoprocess.impl.buffer.fmap.BufferGeoprocess; |
110 |
import com.iver.cit.gvsig.geoprocess.impl.buffer.fmap.BufferVisitor; |
111 |
import com.iver.cit.gvsig.geoprocess.impl.buffer.gui.BufferPanelIF; |
112 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
113 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
114 |
/**
|
115 |
* Controller class for a Buffer Geoprocess
|
116 |
* @author azabala
|
117 |
*
|
118 |
*/
|
119 |
public class BufferGeoprocessController extends |
120 |
AbstractGeoprocessController { |
121 |
/**
|
122 |
* UI class to read user entries.
|
123 |
* By using UI interfaces, we are allowing geoprocessing
|
124 |
* work with GUI and Command Line UI.
|
125 |
*/
|
126 |
private BufferPanelIF bufferPanel;
|
127 |
/**
|
128 |
* Geoprocess we are going to launch with
|
129 |
* launchGeoprocess() method
|
130 |
*/
|
131 |
private BufferGeoprocess buffer;
|
132 |
|
133 |
/**
|
134 |
* Default constructor
|
135 |
*
|
136 |
*/
|
137 |
public BufferGeoprocessController(){}
|
138 |
|
139 |
/**
|
140 |
* Sets GUI panel to read user entries
|
141 |
*/
|
142 |
public void setView(IGeoprocessPanel viewPanel) { |
143 |
this.bufferPanel = (BufferPanelIF) viewPanel;
|
144 |
} |
145 |
|
146 |
public IGeoprocess getGeoprocess() {
|
147 |
return buffer;
|
148 |
} |
149 |
|
150 |
public boolean launchGeoprocess() { |
151 |
FLyrVect inputLayer = bufferPanel.getInputLayer(); |
152 |
FLayers layers = bufferPanel.getFLayers(); |
153 |
File outputFile = null; |
154 |
try {
|
155 |
outputFile = bufferPanel.getOutputFile(); |
156 |
} catch (FileNotFoundException e3) { |
157 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
158 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
159 |
bufferPanel.error(errorDescription, error); |
160 |
return false; |
161 |
} |
162 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
163 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
164 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
165 |
bufferPanel.error(errorDescription, error); |
166 |
return false; |
167 |
} |
168 |
if (outputFile.exists()) {
|
169 |
if (!bufferPanel.askForOverwriteOutputFile(outputFile)) {
|
170 |
return false; |
171 |
} |
172 |
} |
173 |
buffer = new BufferGeoprocess(inputLayer);
|
174 |
HashMap params = new HashMap(); |
175 |
boolean onlySelected = bufferPanel.isBufferOnlySelected();
|
176 |
params.put("layer_selection", new Boolean(onlySelected)); |
177 |
boolean dissolveBuffer = bufferPanel
|
178 |
.isDissolveBuffersSelected(); |
179 |
params.put("dissolve_buffers", new Boolean(dissolveBuffer)); |
180 |
byte strategy = 0; |
181 |
if (bufferPanel.isConstantDistanceSelected()) {
|
182 |
strategy = BufferGeoprocess.CONSTANT_DISTANCE_STRATEGY; |
183 |
double bufferDistance = -1; |
184 |
try {
|
185 |
bufferDistance = bufferPanel.getConstantDistance(); |
186 |
} catch (GeoprocessException e) {
|
187 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
188 |
String errorDescription = PluginServices.getText(this, "Error_distancia_buffer"); |
189 |
errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
190 |
bufferPanel.error(errorDescription, error); |
191 |
return false; |
192 |
} |
193 |
params.put("buffer_distance", new Double(bufferDistance)); |
194 |
} else if (bufferPanel.isAttributeDistanceSelected()) { |
195 |
strategy = BufferGeoprocess.ATTRIBUTE_DISTANCE_STRATEGY; |
196 |
String attributeName = null; |
197 |
try {
|
198 |
attributeName = bufferPanel |
199 |
.getAttributeDistanceField(); |
200 |
} catch (GeoprocessException e) {
|
201 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
202 |
String errorDescription = PluginServices.getText(this, "Error_atributo_no_numerico"); |
203 |
errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
204 |
bufferPanel.error(errorDescription, error); |
205 |
return false; |
206 |
} |
207 |
params.put("attr_name", attributeName);
|
208 |
} |
209 |
params.put("strategy_flag", new Byte(strategy)); |
210 |
|
211 |
//number of radial buffers
|
212 |
int numberOfRadials = bufferPanel.getNumberOfRadialBuffers();
|
213 |
params.put("numRings", new Integer(numberOfRadials)); |
214 |
|
215 |
//type of polygon buffer
|
216 |
String typePolygonBuffer = bufferPanel.getTypePolygonBuffer();
|
217 |
byte typePolBuffer = BufferVisitor.BUFFER_OUTSIDE_POLY;
|
218 |
if(typePolygonBuffer.equals(BufferPanelIF.BUFFER_INSIDE)){
|
219 |
typePolBuffer = BufferVisitor.BUFFER_INSIDE_POLY; |
220 |
}else if(typePolygonBuffer.equals(BufferPanelIF.BUFFER_INSIDE_OUTSIDE)){ |
221 |
typePolBuffer = BufferVisitor.BUFFER_INSIDE_OUTSIDE_POLY; |
222 |
} |
223 |
params.put("typePolBuffer", new Byte(typePolBuffer)); |
224 |
|
225 |
//round cap or square cap
|
226 |
byte cap = BufferVisitor.CAP_ROUND;
|
227 |
boolean squareCap = bufferPanel.isSquareCap();
|
228 |
if(squareCap)
|
229 |
cap = BufferVisitor.CAP_SQUARE; |
230 |
params.put("cap", new Byte(cap)); |
231 |
try {
|
232 |
buffer.setParameters(params); |
233 |
} catch (GeoprocessException e2) {
|
234 |
String error = PluginServices.getText(this, "Error_ejecucion"); |
235 |
String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
236 |
bufferPanel.error(errorDescription, error); |
237 |
return false; |
238 |
} |
239 |
|
240 |
SHPLayerDefinition definition = (SHPLayerDefinition) buffer |
241 |
.createLayerDefinition(); |
242 |
definition.setFile(outputFile); |
243 |
ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
244 |
IWriter writer = null;
|
245 |
try {
|
246 |
writer = getShpWriter(definition); |
247 |
} catch (Exception e1) { |
248 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
249 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
250 |
bufferPanel.error(errorDescription, error); |
251 |
return false; |
252 |
} |
253 |
buffer.setResultLayerProperties(writer, schemaManager); |
254 |
|
255 |
try {
|
256 |
buffer.checkPreconditions(); |
257 |
IMonitorableTask task1 = buffer.createTask(); |
258 |
AddResultLayerTask task2 = new AddResultLayerTask(buffer);
|
259 |
task2.setLayers(layers); |
260 |
MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
261 |
task2); |
262 |
if (globalTask.preprocess())
|
263 |
PluginServices.cancelableBackgroundExecution(globalTask); |
264 |
return true; |
265 |
} catch (GeoprocessException e) {
|
266 |
String error = PluginServices.getText(this, "Error_ejecucion"); |
267 |
String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
268 |
errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
269 |
bufferPanel.error(errorDescription, error); |
270 |
return false; |
271 |
} |
272 |
|
273 |
} |
274 |
public int getWidth() { |
275 |
return 700; |
276 |
} |
277 |
|
278 |
public int getHeight() { |
279 |
return 375; |
280 |
} |
281 |
} |
282 |
|