svn-gvsig-desktop / tags / v1_0_RELEASE / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / buffer / BufferGeoprocessController.java @ 9167
History | View | Annotate | Download (9.56 KB)
1 | 5918 | azabala | /*
|
---|---|---|---|
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$
|
||
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 | 8765 | jjdelcerro | * *** 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 | 6747 | azabala | * refactoring to make logic independent from UI
|
59 | *
|
||
60 | * 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.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 | 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 | import com.iver.cit.gvsig.geoprocess.impl.buffer.fmap.BufferGeoprocess; |
||
110 | import com.iver.cit.gvsig.geoprocess.impl.buffer.fmap.BufferVisitor; |
||
111 | 6747 | azabala | import com.iver.cit.gvsig.geoprocess.impl.buffer.gui.BufferPanelIF; |
112 | 5918 | azabala | 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 | 8765 | jjdelcerro | public class BufferGeoprocessController extends |
120 | 5918 | azabala | AbstractGeoprocessController { |
121 | /**
|
||
122 | 6747 | azabala | * UI class to read user entries.
|
123 | * By using UI interfaces, we are allowing geoprocessing
|
||
124 | * work with GUI and Command Line UI.
|
||
125 | 5918 | azabala | */
|
126 | 6747 | azabala | private BufferPanelIF bufferPanel;
|
127 | 5918 | azabala | /**
|
128 | * Geoprocess we are going to launch with
|
||
129 | * launchGeoprocess() method
|
||
130 | */
|
||
131 | private BufferGeoprocess buffer;
|
||
132 | 8765 | jjdelcerro | |
133 | 5918 | azabala | /**
|
134 | * Default constructor
|
||
135 | *
|
||
136 | */
|
||
137 | public BufferGeoprocessController(){}
|
||
138 | 8765 | jjdelcerro | |
139 | 5918 | azabala | /**
|
140 | * Sets GUI panel to read user entries
|
||
141 | */
|
||
142 | public void setView(IGeoprocessPanel viewPanel) { |
||
143 | 6747 | azabala | this.bufferPanel = (BufferPanelIF) viewPanel;
|
144 | 5918 | azabala | } |
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 | 6489 | azabala | 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 | 5918 | azabala | 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 | 9100 | jmvivo | errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
190 | 5918 | azabala | 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 | 9100 | jmvivo | errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
204 | 5918 | azabala | bufferPanel.error(errorDescription, error); |
205 | return false; |
||
206 | } |
||
207 | params.put("attr_name", attributeName);
|
||
208 | } |
||
209 | params.put("strategy_flag", new Byte(strategy)); |
||
210 | 8765 | jjdelcerro | |
211 | 5918 | azabala | //number of radial buffers
|
212 | int numberOfRadials = bufferPanel.getNumberOfRadialBuffers();
|
||
213 | params.put("numRings", new Integer(numberOfRadials)); |
||
214 | 8765 | jjdelcerro | |
215 | 5918 | azabala | //type of polygon buffer
|
216 | String typePolygonBuffer = bufferPanel.getTypePolygonBuffer();
|
||
217 | byte typePolBuffer = BufferVisitor.BUFFER_OUTSIDE_POLY;
|
||
218 | 6747 | azabala | if(typePolygonBuffer.equals(BufferPanelIF.BUFFER_INSIDE)){
|
219 | 5918 | azabala | typePolBuffer = BufferVisitor.BUFFER_INSIDE_POLY; |
220 | 6747 | azabala | }else if(typePolygonBuffer.equals(BufferPanelIF.BUFFER_INSIDE_OUTSIDE)){ |
221 | 5918 | azabala | typePolBuffer = BufferVisitor.BUFFER_INSIDE_OUTSIDE_POLY; |
222 | } |
||
223 | params.put("typePolBuffer", new Byte(typePolBuffer)); |
||
224 | 8765 | jjdelcerro | |
225 | 5918 | azabala | //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 | 8765 | jjdelcerro | |
240 | 5918 | azabala | SHPLayerDefinition definition = (SHPLayerDefinition) buffer |
241 | .createLayerDefinition(); |
||
242 | definition.setFile(outputFile); |
||
243 | 6093 | fjp | ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
244 | 5918 | azabala | 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 | 8765 | jjdelcerro | } |
253 | 5918 | azabala | 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 | 9100 | jmvivo | errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
269 | 5918 | azabala | bufferPanel.error(errorDescription, error); |
270 | return false; |
||
271 | } |
||
272 | 8765 | jjdelcerro | |
273 | 5918 | azabala | } |
274 | 8765 | jjdelcerro | public int getWidth() { |
275 | return 700; |
||
276 | } |
||
277 | 5918 | azabala | |
278 | 8765 | jjdelcerro | public int getHeight() { |
279 | return 375; |
||
280 | } |
||
281 | 5918 | azabala | } |