Revision 4447

View differences:

trunk/extensions/extGeoProcessing/.classpath
4 4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5 5
	<classpathentry kind="src" path="/appgvSIG"/>
6 6
	<classpathentry kind="src" path="/libFMap"/>
7
	<classpathentry kind="src" path="/_fwAndami"/>
8
	<classpathentry kind="lib" path="/_fwAndami/lib/iver-utiles.jar"/>
9 7
	<classpathentry kind="lib" path="/libFMap/lib/gdbms-0.8-SNAPSHOT.jar"/>
10 8
	<classpathentry kind="src" path="/libCq CMS for java"/>
11 9
	<classpathentry kind="lib" path="/libFMap/lib/driver-manager-1.1.jar"/>
12 10
	<classpathentry kind="lib" path="/libFMap/lib/jts-1.7.jar"/>
13 11
	<classpathentry kind="lib" path="lib/ehcache-1.2beta4.jar"/>
14 12
	<classpathentry kind="lib" path="lib/spatialindex.jar"/>
13
	<classpathentry combineaccessrules="false" kind="src" path="/_fwAndami"/>
14
	<classpathentry combineaccessrules="false" kind="src" path="/libIverUtiles"/>
15 15
	<classpathentry kind="output" path="bin"/>
16 16
</classpath>
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/model/IGeoprocess.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.3  2006-03-14 18:32:46  fjp
48
* Revision 1.4  2006-03-15 18:34:50  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.3  2006/03/14 18:32:46  fjp
49 52
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
*
51 54
* Revision 1.2  2006/02/13 17:55:25  azabala
......
72 75
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
73 76
import com.iver.cit.gvsig.fmap.edition.ISchemaManager;
74 77
import com.iver.cit.gvsig.fmap.edition.IWriter;
75
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
76 78
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
79
import com.iver.utiles.swing.threads.IBackgroundExecution;
77 80

  
78 81
/**
79 82
 * 
80 83
 * Spatial process which operates with one or more
81
 * vectorial layers to produce a new vectorial layer
84
 * vectorial layers to produce a new vectorial layer.
85
 * So geoprocesses could be costly task, extends IBackgroundExecution
86
 * interface that offers a method to run in background.
82 87
 * 
83 88
 * @author azabala
84 89
 * 
85
 * TODO Migrate to libGeoprocess al geoprocessing logic,
90
 * TODO Migrate to libGeoprocess all geoprocessing logic,
86 91
 * and GUIS in extGeoprocessing
92
 * 
93
 * 
87 94
 *
88 95
 */
89
public interface IGeoprocess {
96
public interface IGeoprocess extends IBackgroundExecution{
90 97
	
91 98
	/**
92 99
	 * It sets geoprocess parameters
......
138 145
	 * 
139 146
	 * @return LayerDefinition that describes result layer.
140 147
	 */
148

  
141 149
	public ILayerDefinition createLayerDefinition();
142 150
}
143 151

  
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/jtsprocessors/FeaturePersisterProcessor.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.3  2006-03-14 18:32:46  fjp
48
* Revision 1.4  2006-03-15 18:34:03  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.3  2006/03/14 18:32:46  fjp
49 52
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
*
51 54
* Revision 1.2  2006/02/26 20:54:52  azabala
......
76 79
 * It saves in a persistent data store the result of an individual geoprocess.
77 80
 * @author azabala
78 81
 * 
79
 * TODO Crear una interfaz AttrContentProvider para rellenar el alfanumerico
80
 * de un geoproceso. Esta clase funciona bien con el clip, o con el spatial
81
 * join (1-1). Pero el dissolve o el union no funciona as?
82
 
82 83
 *
83 84
 */
84 85
public class FeaturePersisterProcessor extends GeometryPersisterProcessor {
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/jtsprocessors/DeferredFeaturePersisterProcessor.java
1
/*
2
 * Created on 15-mar-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
* Revision 1.1  2006-03-15 18:33:53  azabala
49
* *** empty log message ***
50
*
51
*
52
*/
53
package com.iver.gvsig.geoprocessing.impl.jtsprocessors;
54

  
55
import com.iver.cit.gvsig.fmap.edition.EditionException;
56
import com.iver.cit.gvsig.fmap.edition.IWriter;
57
/**
58
 * Subclass of FeaturePersisterProcessor2 that
59
 * deferred postProcess call to subjacent IWriter.
60
 * 
61
 * It is thinked for batch processes, because delegates
62
 * preprocess and postprocess calls to external processes
63
 * that uses this class' instances.
64
 * 
65
 * PRECONDITIONS: IWriter has preprocessed yet.
66
 * POSTCONDITIONS: Must call IWriter postprocess externally
67
 * 
68
 * 
69
 * @author azabala
70
 *
71
 */
72

  
73
public class DeferredFeaturePersisterProcessor extends
74
		FeaturePersisterProcessor2 {
75

  
76
	public DeferredFeaturePersisterProcessor(IWriter writer) {
77
		super(writer);
78
	}
79
	
80
	public void start() throws EditionException{
81
	}
82

  
83
	public void finish() {
84

  
85
	}
86

  
87
}
88

  
0 89

  
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/jtsprocessors/FeaturePersisterProcessor2.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.2  2006-03-05 19:58:58  azabala
48
* Revision 1.3  2006-03-15 18:34:03  azabala
49 49
* *** empty log message ***
50 50
*
51
* Revision 1.2  2006/03/05 19:58:58  azabala
52
* *** empty log message ***
53
*
51 54
* Revision 1.1  2006/02/26 20:55:08  azabala
52 55
* *** empty log message ***
53 56
*
......
58 61
import com.iver.cit.gvsig.fmap.core.IRow;
59 62
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited;
60 63
import com.iver.cit.gvsig.fmap.edition.EditionException;
61
import com.iver.cit.gvsig.fmap.edition.ISchemaManager;
62 64
import com.iver.cit.gvsig.fmap.edition.IWriter;
63 65
import com.iver.gvsig.geoprocessing.model.FeatureProcessor;
64 66

  
67
/**
68
 * It saves in a persistent data store Features, by using a IWriter.
69
 * It does preprocess and postprocess in start() and stop() methods.
70
 * @author azabala
71
 *
72
 */
65 73
public class FeaturePersisterProcessor2 implements FeatureProcessor {
66 74
	/*
67 75
	 * precondition: writer must have its schema created with
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/intersection/IntersectionGeoprocess.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.4  2006-03-14 18:32:46  fjp
48
 * Revision 1.5  2006-03-15 18:33:36  azabala
49
 * *** empty log message ***
50
 *
51
 * Revision 1.4  2006/03/14 18:32:46  fjp
49 52
 * Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
 *
51 54
 * Revision 1.3  2006/03/07 21:01:33  azabala
......
66 69
import com.hardcode.gdbms.engine.data.driver.DriverException;
67 70
import com.iver.cit.gvsig.fmap.core.IFeature;
68 71
import com.iver.cit.gvsig.fmap.core.IGeometry;
72
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
69 73
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
70
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
71 74
import com.iver.cit.gvsig.fmap.edition.EditionException;
72 75
import com.iver.cit.gvsig.fmap.layers.FBitSet;
73 76
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
77
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable;
78
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable;
74 79
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
75 80
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
76 81
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
......
80 85
import com.iver.gvsig.geoprocessing.model.IOverlayGeoprocess;
81 86
import com.iver.gvsig.geoprocessing.schemabuilder.DefinitionUtils;
82 87
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
88
import com.iver.utiles.swing.threads.IMonitorableTask;
83 89
/**
84 90
 * Computes intersection between two layers.
85 91
 * 
......
224 230
		return null;
225 231
	}
226 232

  
233
	public IMonitorableTask createTask() {
234
		try {
235
			return new IntersectionMonitorableTask();
236
		} catch (DriverIOException e) {
237
			return null;
238
		}
239
	}
240
	
241
	/**
242
	 * IMonitorableTask that allows to run diff geoprocess in background,
243
	 * with cancelation requests.
244
	 * 
245
	 * @author azabala
246
	 * 
247
	 */
248
	class IntersectionMonitorableTask implements IMonitorableTask {
249
		private CancellableMonitorable cancelMonitor = null;
250

  
251
		// FIXME INTERNACIONALIZAR ESTO
252
		String INTERSECTION_MESSAGE = "Computing intersections: ";
253

  
254
		private boolean finished = false;
255

  
256
		IntersectionMonitorableTask() throws DriverIOException {
257
			initialize();
258
		}
259
		void initialize() throws DriverIOException {
260
			cancelMonitor = createCancelMonitor();
261
		}
262

  
263
		private CancellableMonitorable createCancelMonitor()
264
				throws DriverIOException {
265
			DefaultCancellableMonitorable monitor = new 
266
							DefaultCancellableMonitorable();
267
			monitor.setInitialStep(0);
268
			//Really its undeterminated, but  we must to process all
269
			//elements of first layer (or selection) we are going to 
270
			//consideer determinated
271
			monitor.setDeterminatedProcess(true);
272
			int numSteps = 0;
273
			if (onlyFirstLayerSelection) {
274
				FBitSet selection = firstLayer.getRecordset().getSelection();
275
				numSteps = selection.cardinality();
276
			} else {
277
				numSteps = firstLayer.getSource().getShapeCount();
278
			}
279
			monitor.setFinalStep(numSteps);
280
			return monitor;
281
		}
282

  
283
		public int getInitialStep() {
284
			return cancelMonitor.getInitialStep();
285
		}
286

  
287
		public int getFinishStep() {
288
			return cancelMonitor.getFinalStep();
289
		}
290

  
291
		public int getCurrentStep() {
292
			return cancelMonitor.getCurrentStep();
293
		}
294

  
295
		public String getStatusMessage() {
296
			// FIXME Cambiar esto por un mecanismo de eventos,
297
			// de forma que la tarea lo que tenga sea un escuchador
298
			// que cambie el mensaje de estado segun los eventos
299
			// de tareas que se est?n realizando
300
			return "Intersection Geoprocess...";
301
		}
302

  
303
		public String getNote() {
304
			// FIXME Cambiar esto por un mecanismo de eventos,
305
			// de forma que la tarea lo que tenga sea un escuchador
306
			// que cambie el mensaje de estado segun los eventos
307
			// de tareas que se est?n realizando
308
			return INTERSECTION_MESSAGE + getCurrentStep() + "of " + getFinishStep();
309
		}
310

  
311
		public void cancel() {
312
			((DefaultCancellableMonitorable) cancelMonitor).setCanceled(true);
313
		}
314

  
315
		public void run() throws GeoprocessException {
316

  
317
			try {
318
				//Prepare the result
319
				schemaManager.createOrAlterSchema(createLayerDefinition());
320
				writer.preProcess();
321
				Strategy strategy = 
322
					StrategyManager.getStrategy(firstLayer);
323
				Strategy overlayStrategy = 
324
					StrategyManager.getStrategy(overlayLayer);
325
				FeaturePersisterProcessor2 featureProcessor =
326
					new FeaturePersisterProcessor2(writer);
327
				IntersectVisitor visitor = new IntersectVisitor(overlayLayer, 
328
															featureProcessor, 
329
															overlayStrategy,
330
															onlyClipLayerSelection);
331
				if(onlyFirstLayerSelection){
332
					strategy.process(visitor, 
333
						firstLayer.getRecordset().getSelection(),
334
						cancelMonitor);
335
				}else{
336
					strategy.process(visitor, cancelMonitor);
337
				}
338
				
339
			} catch (EditionException e) {
340
				throw new GeoprocessException("Error al crear el esquema/fichero de la nueva capa");
341
			} catch (DriverException e) {
342
				throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion");
343
			} catch (com.iver.cit.gvsig.fmap.DriverException e) {
344
				throw new GeoprocessException("Error de driver al calcular el geoproceso interseccion");
345
			} catch (VisitException e) {
346
				throw new GeoprocessException("Error al procesar el feature de una capa durante el geoproceso interseccion");
347
			}finally{
348
				finished = true;
349
			}
350
		}
351

  
352
		public boolean isDefined() {
353
			return cancelMonitor.isDeterminatedProcess();
354
		}
355

  
356
		public boolean isCanceled() {
357
			return cancelMonitor.isCanceled();
358
		}
359

  
360
		public boolean isFinished() {
361
			return finished;
362
		}
363
	}
364

  
227 365
}
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/clip/ClipGeoprocess.java
40 40
 *
41 41
 *   +34 963163400
42 42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
43
 
45 44
*
46 45
* $Id$
47 46
* $Log$
48
* Revision 1.7  2006-03-14 18:32:46  fjp
47
* Revision 1.8  2006-03-15 18:30:39  azabala
48
* *** empty log message ***
49
*
50
* Revision 1.7  2006/03/14 18:32:46  fjp
49 51
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 52
*
51 53
* Revision 1.6  2006/03/07 21:01:33  azabala
......
74 76

  
75 77
import com.iver.cit.gvsig.fmap.core.IFeature;
76 78
import com.iver.cit.gvsig.fmap.core.IGeometry;
79
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
77 80
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
78 81
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
79 82
import com.iver.cit.gvsig.fmap.edition.ISchemaManager;
80 83
import com.iver.cit.gvsig.fmap.edition.IWriter;
81 84
import com.iver.cit.gvsig.fmap.layers.FBitSet;
82 85
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
86
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable;
87
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable;
83 88
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
84 89
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
85 90
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
......
89 94
import com.iver.gvsig.geoprocessing.model.IOverlayGeoprocess;
90 95
import com.iver.gvsig.geoprocessing.schemabuilder.DefinitionUtils;
91 96
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
97
import com.iver.utiles.swing.threads.IMonitorableTask;
92 98
import com.vividsolutions.jts.geom.Geometry;
99

  
93 100
/**
94
 * A clip between two layers is the intersection
95
 * of the first layer with the convex hull
96
 * of the second layer.
101
 * A clip between two layers is the intersection of the first layer with the
102
 * convex hull of the second layer.
97 103
 * 
98
 * It is an individual case of OverlayGeoprocess.
99
 * When we would have piped geoprocesses, we could
100
 * model it like a pipe of a ConvexHull geoprocess and
101
 * an intersection geoprocess.
104
 * It is an individual case of OverlayGeoprocess. When we would have piped
105
 * geoprocesses, we could model it like a pipe of a ConvexHull geoprocess and an
106
 * intersection geoprocess.
107
 * 
102 108
 * @author azabala
103
 *
109
 * 
104 110
 */
105
public class ClipGeoprocess extends AbstractGeoprocess 
106
						implements IOverlayGeoprocess {
107
	
111
public class ClipGeoprocess extends AbstractGeoprocess implements
112
		IOverlayGeoprocess {
113

  
108 114
	/**
109 115
	 * overlay layer
110 116
	 */
111 117
	private FLyrVect overlayLayer;
118

  
112 119
	/**
113 120
	 * Schema of the result layer
114 121
	 */
122

  
115 123
	private ILayerDefinition resultLayerDefinition;
124

  
116 125
	/**
117 126
	 * flag to only clip selection of input layer
118 127
	 */
119 128
	private boolean onlyFirstLayerSelection = false;
129

  
120 130
	/**
121 131
	 * flag to only clip with selection of clipping layer
122 132
	 */
123 133
	private boolean onlyClipLayerSelection = false;
134

  
124 135
	/**
125
	 * processes input layer's features to clip its geometries
126
	 * with clipping layer bounding box
136
	 * processes input layer's features to clip its geometries with clipping
137
	 * layer bounding box
127 138
	 */
128 139
	private ClipVisitor visitor;
129
	
140

  
130 141
	/**
131
	 * Constructor 
132
	 *
142
	 * Constructor
143
	 * 
133 144
	 */
134
	public ClipGeoprocess(FLyrVect inputLayer){
145
	public ClipGeoprocess(FLyrVect inputLayer) {
135 146
		setFirstOperand(inputLayer);
136 147
	}
137
	
148

  
138 149
	public void setSecondOperand(FLyrVect secondLayer) {
139 150
		this.overlayLayer = secondLayer;
140 151

  
......
145 156
	}
146 157

  
147 158
	public void setParameters(Map params) throws GeoprocessException {
148
		Boolean firstLayerSelection = (Boolean) params.get("firstlayerselection");
149
		if(firstLayerSelection != null)
159
		Boolean firstLayerSelection = (Boolean) params
160
				.get("firstlayerselection");
161
		if (firstLayerSelection != null)
150 162
			this.onlyFirstLayerSelection = firstLayerSelection.booleanValue();
151
		
152
		Boolean secondLayerSelection = (Boolean) params.get("secondlayerselection");
153
		if(secondLayerSelection != null)
163

  
164
		Boolean secondLayerSelection = (Boolean) params
165
				.get("secondlayerselection");
166
		if (secondLayerSelection != null)
154 167
			this.onlyClipLayerSelection = secondLayerSelection.booleanValue();
155 168
	}
156 169

  
......
159 172
			throw new GeoprocessException("Clip: capa de entrada a null");
160 173
		if (overlayLayer == null)
161 174
			throw new GeoprocessException("Clip: capa de clip a null");
162
		if(this.writer == null || 
163
		   this.schemaManager == null){
164
			throw new GeoprocessException("Operacion de clip sin especificar capa de resultados");
175
		if (this.writer == null || this.schemaManager == null) {
176
			throw new GeoprocessException(
177
					"Operacion de clip sin especificar capa de resultados");
165 178
		}
166
		
179

  
167 180
		try {
168
			if(overlayLayer.getShapeType() != XTypes.POLYGON){
169
				throw new GeoprocessException("La capa de recorte no es de pol?gonos");
181
			if (overlayLayer.getShapeType() != XTypes.POLYGON) {
182
				throw new GeoprocessException(
183
						"La capa de recorte no es de pol?gonos");
170 184
			}
171 185
		} catch (com.iver.cit.gvsig.fmap.DriverException e) {
172
			throw new GeoprocessException("Error al tratar de chequear si la capa de recorte es de pol?gonos");
186
			throw new GeoprocessException(
187
					"Error al tratar de chequear si la capa de recorte es de pol?gonos");
173 188
		}
174 189
	}
175 190

  
176 191
	public void process() throws GeoprocessException {
177 192
		Geometry clippingGeometry = null;
178 193
		try {
179
			clippingGeometry = computeJtsClippingPoly();
194
			clippingGeometry = computeJtsClippingPoly(null);
180 195
		} catch (Exception e) {
181
			throw new GeoprocessException("Error calculando el convex hull de la clipping layer");
196
			throw new GeoprocessException(
197
					"Error calculando el convex hull de la clipping layer");
182 198
		}
183
		visitor = new ClipVisitor(clippingGeometry,
184
				resultLayerDefinition, 
185
				schemaManager, 
186
				writer);
187
		Strategy strategy = StrategyManager.
188
			getStrategy(firstLayer);
199
		visitor = new ClipVisitor(clippingGeometry, resultLayerDefinition,
200
				schemaManager, writer);
201
		Strategy strategy = StrategyManager.getStrategy(firstLayer);
189 202
		try {
190
			if(onlyFirstLayerSelection){
191
				strategy.process(visitor, 
192
						firstLayer.getRecordset().
193
						getSelection());
194
			}else{
203
			if (onlyFirstLayerSelection) {
204
				strategy.process(visitor, firstLayer.getRecordset()
205
						.getSelection());
206
			} else {
195 207
				strategy.process(visitor);
196 208
			}
197 209
		} catch (Exception e) {
198
			throw new GeoprocessException("Problemas al leer los datos de la capa a clipear");
210
			throw new GeoprocessException(
211
					"Problemas al leer los datos de la capa a clipear");
199 212
		}
200 213
	}
201 214

  
......
211 224

  
212 225
	}
213 226

  
227

  
214 228
	public ILayerDefinition createLayerDefinition() {
215 229
		//result layer definition will be the same that
216 230
		//input layer
217 231
		if(resultLayerDefinition == null){
218 232
			try {
219
				resultLayerDefinition = DefinitionUtils.
220
					createLayerDefinition(firstLayer);
233
				resultLayerDefinition = DefinitionUtils
234
						.createLayerDefinition(firstLayer);
221 235
			} catch (Exception e) {
222
				//TODO Quizas createLayerDefinition deberia lanzar
223
				//una excepcion
236
				// TODO Quizas createLayerDefinition deberia lanzar
237
				// una excepcion
224 238
				e.printStackTrace();
225 239
			}
226 240
		}
227 241
		return resultLayerDefinition;
228 242
	}
229
	
230
	
231
	private Geometry computeJtsClippingPoly() throws com.iver.cit.gvsig.fmap.DriverException, VisitException {
232
		ScalableUnionVisitor visitor = 
233
			new ScalableUnionVisitor();
234
		
235
		Strategy strategy = 
236
			StrategyManager.getStrategy(overlayLayer);
237
		if(onlyClipLayerSelection){
238
			strategy.process(visitor, 
239
					overlayLayer.getRecordset().getSelection());
240
		}else{
241
			strategy.process(visitor);
243

  
244
	/**
245
	 * Computes union of all geometries of the clipping layer
246
	 * 
247
	 * @param cancel
248
	 *            monitors cancellations and progress of clipping polygon
249
	 *            computation.
250
	 * @return
251
	 * @throws com.iver.cit.gvsig.fmap.DriverException
252
	 * @throws VisitException
253
	 */
254
	private Geometry computeJtsClippingPoly(CancellableMonitorable cancel)
255
			throws com.iver.cit.gvsig.fmap.DriverException, VisitException {
256
		ScalableUnionVisitor visitor = new ScalableUnionVisitor();
257

  
258
		Strategy strategy = StrategyManager.getStrategy(overlayLayer);
259
		if (onlyClipLayerSelection) {
260
			strategy.process(visitor, overlayLayer.getRecordset()
261
					.getSelection(), cancel);
262
		} else {
263
			strategy.process(visitor, cancel);
242 264
		}
243
		return 	visitor.getJtsConvexHull();
265
		return visitor.getJtsConvexHull();
244 266
	}
245 267

  
246 268
	public FBitSet getOverlays(IGeometry firstLayerGeometry, int index) {
......
248 270
		return null;
249 271
	}
250 272

  
251
	public IFeature[] computeIntersection(IGeometry firsLayerGeometry, int firstLayerFeatureIndex, IGeometry secondLayerGeometry, int secondLayerFeatureIndex) {
273
	public IFeature[] computeIntersection(IGeometry firsLayerGeometry,
274
			int firstLayerFeatureIndex, IGeometry secondLayerGeometry,
275
			int secondLayerFeatureIndex) {
252 276
		// TODO Auto-generated method stub
253 277
		return null;
254 278
	}
255 279

  
280
	public IMonitorableTask createTask() {
281
		final CancellableMonitorable cancelMonitor = 
282
			createCancelMonitor();
283

  
284
		return new IMonitorableTask() {
285
			String CLIP_MESSAGE = "Computing clip polygon: ";
286
			String INTERS_MESSAGE = "Clipping geometries: ";
287
			String currentMsg = CLIP_MESSAGE;
288
			private boolean finished = false;
289

  
290
			public int getInitialStep() {
291
				return cancelMonitor.getInitialStep();
292
			}
293

  
294
			public int getFinishStep() {
295
				return cancelMonitor.getFinalStep();
296
			}
297

  
298
			public int getCurrentStep() {
299
				return cancelMonitor.getCurrentStep();
300
			}
301

  
302
			public String getStatusMessage() {
303
				// FIXME Cambiar esto por un mecanismo de eventos,
304
				// de forma que la tarea lo que tenga sea un escuchador
305
				// que cambie el mensaje de estado segun los eventos
306
				// de tareas que se est?n realizando
307
				return "Clip Geoprocess...";
308
			}
309

  
310
			public String getNote() {
311
				// FIXME Cambiar esto por un mecanismo de eventos,
312
				// de forma que la tarea lo que tenga sea un escuchador
313
				// que cambie el mensaje de estado segun los eventos
314
				// de tareas que se est?n realizando
315
				return currentMsg  +
316
				getCurrentStep()+ 
317
				" de "+
318
				getFinishStep();
319
			}
320

  
321
			public void cancel() {
322
				((DefaultCancellableMonitorable) cancelMonitor)
323
						.setCanceled(true);
324
			}
325

  
326
			public void run() {
327
				
328
				Geometry clippingGeometry = null;
329
				try {
330
					clippingGeometry = computeJtsClippingPoly(cancelMonitor);
331
				} catch (Exception e) {
332
					//FIXME Ver que pasa con las excepciones que
333
					//que pueda lanzar un ITask
334
				}
335
				currentMsg = INTERS_MESSAGE;
336
				visitor = new ClipVisitor(clippingGeometry, resultLayerDefinition,
337
						schemaManager, writer);
338
				Strategy strategy = StrategyManager.getStrategy(firstLayer);
339
				try {
340
					if (onlyFirstLayerSelection) {
341
						strategy.process(visitor, firstLayer.getRecordset()
342
								.getSelection(), cancelMonitor);
343
					} else {
344
						strategy.process(visitor, cancelMonitor);
345
					}
346
				} catch (Exception e) {
347
					//FIXME Ver que pasa con las excepciones de las ITask
348
				}
349
				finished = true;
350
			}
351

  
352
			public boolean isDefined() {
353
				return cancelMonitor.isDeterminatedProcess();
354
			}
355

  
356
			public boolean isCanceled() {
357
				return cancelMonitor.isCanceled();
358
			}
359

  
360
			public boolean isFinished() {
361
				return finished;
362
			}
363
		};
364
	}
365

  
366
	private DefaultCancellableMonitorable createCancelMonitor() {
367
		DefaultCancellableMonitorable monitor = new DefaultCancellableMonitorable();
368
		monitor.setInitialStep(0);
369
		monitor.setDeterminatedProcess(true);
370
		int clipSteps = 0;
371
		if (onlyClipLayerSelection){
372
			FBitSet selection = overlayLayer.getRecordset().getSelection();
373
			clipSteps = selection.cardinality();
374
		}else{
375
			try {
376
				clipSteps = overlayLayer.getSource().getShapeCount();
377
			} catch (DriverIOException e) {
378
				// TODO Auto-generated catch block
379
				e.printStackTrace();
380
			}
381
		}
382
		int  firstSteps = 0;
383
		if (onlyFirstLayerSelection) {
384
			FBitSet selection = firstLayer.getRecordset().getSelection();
385
			firstSteps = selection.cardinality();
386
		} else {
387
			try {
388
				firstSteps = firstLayer.getSource()
389
								.getShapeCount();
390
			} catch (DriverIOException e) {
391
				e.printStackTrace();
392
			}
393
		}
394
		int totalSteps = clipSteps + firstSteps;
395
		monitor.setFinalStep(totalSteps);
396
		return monitor;
397
	}
398

  
256 399
}
257

  
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/clip/ClipVisitor.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.3  2006-03-14 18:32:46  fjp
48
* Revision 1.4  2006-03-15 18:30:39  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.3  2006/03/14 18:32:46  fjp
49 52
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
*
51 54
* Revision 1.2  2006/03/07 21:01:33  azabala
......
77 80
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
78 81
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
79 82
import com.iver.gvsig.geoprocessing.impl.jtsprocessors.FeaturePersisterProcessor;
80
import com.iver.gvsig.geoprocessing.model.GeoprocessingResultsProcessor;
81 83
import com.vividsolutions.jts.geom.Geometry;
82 84
/**
83 85
 * This class analyzes all features of a layer, clipping its geometries
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/convexhull/ScalableConvexHullVisitor.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.2  2006-03-07 21:01:33  azabala
48
* Revision 1.3  2006-03-15 18:31:06  azabala
49 49
* *** empty log message ***
50 50
*
51
* Revision 1.2  2006/03/07 21:01:33  azabala
52
* *** empty log message ***
53
*
51 54
* Revision 1.1  2006/03/06 19:48:39  azabala
52 55
* *** empty log message ***
53 56
*
......
65 68
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
66 69
import com.iver.cit.gvsig.fmap.layers.FLayer;
67 70
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
68
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
69 71
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
70 72
import com.vividsolutions.jts.geom.Geometry;
71 73
import com.vividsolutions.jts.geom.GeometryCollection;
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/convexhull/ConvexHullGeoprocess.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.6  2006-03-14 18:32:46  fjp
48
* Revision 1.7  2006-03-15 18:31:06  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.6  2006/03/14 18:32:46  fjp
49 52
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
*
51 54
* Revision 1.5  2006/03/07 21:01:33  azabala
......
62 65
*
63 66
* Revision 1.1  2006/02/17 16:32:20  azabala
64 67
* *** empty log message ***
65
*
66
*
67
*/
68
 *
69
 *
70
 */
71

  
68 72
package com.iver.gvsig.geoprocessing.impl.convexhull;
69 73

  
70 74
import java.util.Map;
71 75

  
72

  
73 76
import com.iver.cit.gvsig.fmap.DriverException;
74 77
import com.iver.cit.gvsig.fmap.core.IFeature;
75 78
import com.iver.cit.gvsig.fmap.core.IGeometry;
79
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
76 80
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
77 81
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
78 82
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
79 83
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
80 84
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited;
81 85
import com.iver.cit.gvsig.fmap.edition.EditionException;
86
import com.iver.cit.gvsig.fmap.layers.FBitSet;
82 87
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
88
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable;
89
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable;
83 90
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
84 91
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
85 92
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
......
88 95
import com.iver.gvsig.geoprocessing.model.IOneLayerGeoprocess;
89 96
import com.iver.gvsig.geoprocessing.schemabuilder.FeatureFactory;
90 97
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
98
import com.iver.utiles.swing.threads.IMonitorableTask;
99

  
91 100
/**
92
 * Geoprocess that computes the convex hull of all geometries
93
 * of the input layer.
101
 * Geoprocess that computes the convex hull of all geometries of the input
102
 * layer.
94 103
 * 
95 104
 * @author azabala
96
 *
105
 * 
97 106
 */
98
public class ConvexHullGeoprocess extends AbstractGeoprocess
99
							implements IOneLayerGeoprocess {
100
	
107
public class ConvexHullGeoprocess extends AbstractGeoprocess implements
108
		IOneLayerGeoprocess {
109

  
101 110
	/**
102 111
	 * Schema of the result layer
103 112
	 */
104 113
	private LayerDefinition resultLayerDefinition;
114

  
105 115
	/**
106
	 * Iterates over geometries computing convex
107
	 * hull.
108
	 * TODO Comparative Memory vs Scalable
116
	 * Iterates over geometries computing convex hull. 
117
	 * TODO Comparative Memory
118
	 * vs Scalable
109 119
	 */
110 120
	private ScalableConvexHullVisitor visitor;
121

  
111 122
	/**
112
	 * If only consideer selection to compute
113
	 * convex hull
123
	 * If only consideer selection to compute convex hull
114 124
	 */
115 125
	private boolean convexSelection;
116
	
117
	
118
	public ConvexHullGeoprocess(){
126

  
127
	public ConvexHullGeoprocess() {
119 128
		visitor = new ScalableConvexHullVisitor();
120 129
	}
121
	
122
	
130

  
123 131
	public void setParameters(Map params) throws GeoprocessException {
124
		Boolean onlySelection =
125
			(Boolean) params.get("layer_selection");
126
		if(onlySelection != null)
132
		Boolean onlySelection = (Boolean) params.get("layer_selection");
133
		if (onlySelection != null)
127 134
			convexSelection = onlySelection.booleanValue();
128
		
135

  
129 136
	}
130 137

  
131 138
	public void checkPreconditions() throws GeoprocessException {
132 139
		if (firstLayer == null)
133
			throw new GeoprocessException("Convex Hull con capa de entrada a null");
134
		if(this.writer == null || 
135
		   this.schemaManager == null){
136
			throw new GeoprocessException("Operacion de convex hull sin especificar capa de resultados");
140
			throw new GeoprocessException(
141
					"Convex Hull con capa de entrada a null");
142
		if (this.writer == null || this.schemaManager == null) {
143
			throw new GeoprocessException(
144
					"Operacion de convex hull sin especificar capa de resultados");
137 145
		}
138 146

  
139 147
	}
140 148

  
141 149
	public void process() throws GeoprocessException {
142
		Strategy strategy = StrategyManager.
143
			getStrategy(firstLayer);
150
		Strategy strategy = StrategyManager.getStrategy(firstLayer);
144 151
		try {
145
			if(convexSelection){
146
				strategy.process(visitor,
147
						firstLayer.getRecordset().getSelection());
148
			}else{
152
			if (convexSelection) {
153
				strategy.process(visitor, firstLayer.getRecordset()
154
						.getSelection());
155
			} else {
149 156
				strategy.process(visitor);
150 157
			}
151
			
152
			IGeometry convexHull = 
153
				visitor.getConvexHull();
158

  
159
			IGeometry convexHull = visitor.getConvexHull();
154 160
			Object[] attrs = new Object[1];
155 161
			attrs[0] = new Long(0);
156
			IFeature feature = FeatureFactory.createFeature(attrs, 
157
					convexHull, 
162
			IFeature feature = FeatureFactory.createFeature(attrs, convexHull,
158 163
					resultLayerDefinition);
159 164
			writer.preProcess();
160
			DefaultRowEdited editedFeature = new
161
						DefaultRowEdited(feature, 
162
						DefaultRowEdited.STATUS_ADDED, 0);
165
			DefaultRowEdited editedFeature = new DefaultRowEdited(feature,
166
					DefaultRowEdited.STATUS_ADDED, 0);
163 167
			writer.process(editedFeature);
164 168
			writer.postProcess();
165
			
169

  
166 170
		} catch (DriverException e) {
167
			throw new GeoprocessException("Problemas con el driver calculando el convex hull");
171
			throw new GeoprocessException(
172
					"Problemas con el driver calculando el convex hull");
168 173
		} catch (VisitException e) {
169
			throw new GeoprocessException("Problemas durante el proceso de calculo del convex hull");
170
		} catch (EditionException e){
171
			throw new GeoprocessException("Problemas al guardar la capa resultado del convex hull");
174
			throw new GeoprocessException(
175
					"Problemas durante el proceso de calculo del convex hull");
176
		} catch (EditionException e) {
177
			throw new GeoprocessException(
178
					"Problemas al guardar la capa resultado del convex hull");
172 179
		}
173 180
	}
174 181

  
175 182
	public void cancel() {
176 183
		// TODO Implementar la cancelacion
184
		//llamar a ISchemaManager.drop() para borrar la capa
185
		//resultado
177 186

  
178 187
	}
179 188

  
189

  
180 190
	public ILayerDefinition createLayerDefinition() {
181 191
		if(resultLayerDefinition == null){
182 192
			resultLayerDefinition = new SHPLayerDefinition();
......
195 205
		this.firstLayer = firstLayer;
196 206
	}
197 207

  
208
	public IMonitorableTask createTask() {
209
		try {
210
			return new ConvexHullMonitorableTask();
211
		} catch (DriverIOException e) {
212
			return null;
213
		}
214
	}
215

  
216
	/**
217
	 * IMonitorableTask that allows to run convex hull geoprocess in background,
218
	 * with cancelation requests.
219
	 * 
220
	 * @author azabala
221
	 * 
222
	 */
223
	class ConvexHullMonitorableTask implements IMonitorableTask {
224
		private CancellableMonitorable cancelMonitor = null;
225

  
226
		// FIXME INTERNACIONALIZAR ESTO
227
		String HULL_MESSAGE = "Computing convex hull:";
228

  
229
		private boolean finished = false;
230

  
231
		ConvexHullMonitorableTask() throws DriverIOException{
232
			initialize();
233
		}
234
		void initialize() throws DriverIOException {
235
			cancelMonitor = createCancelMonitor();
236
		}
237

  
238
		private CancellableMonitorable createCancelMonitor()
239
				throws DriverIOException {
240
			DefaultCancellableMonitorable monitor = new DefaultCancellableMonitorable();
241
			monitor.setInitialStep(0);
242
			monitor.setDeterminatedProcess(true);
243
			int numSteps = 0;
244
			if (convexSelection) {
245
				FBitSet selection = firstLayer.getRecordset().getSelection();
246
				numSteps = selection.cardinality();
247
			} else {
248
				numSteps = firstLayer.getSource().getShapeCount();
249
			}
250
			monitor.setFinalStep(numSteps);
251
			return monitor;
252
		}
253

  
254
		public int getInitialStep() {
255
			return cancelMonitor.getInitialStep();
256
		}
257

  
258
		public int getFinishStep() {
259
			return cancelMonitor.getFinalStep();
260
		}
261

  
262
		public int getCurrentStep() {
263
			return cancelMonitor.getCurrentStep();
264
		}
265

  
266
		public String getStatusMessage() {
267
			// FIXME Cambiar esto por un mecanismo de eventos,
268
			// de forma que la tarea lo que tenga sea un escuchador
269
			// que cambie el mensaje de estado segun los eventos
270
			// de tareas que se est?n realizando
271
			return "Convex Hull Geoprocess...";
272
		}
273

  
274
		public String getNote() {
275
			// FIXME Cambiar esto por un mecanismo de eventos,
276
			// de forma que la tarea lo que tenga sea un escuchador
277
			// que cambie el mensaje de estado segun los eventos
278
			// de tareas que se est?n realizando
279
			return HULL_MESSAGE +
280
			getCurrentStep()+ 
281
			" de "  +
282
			getFinishStep();
283
		}
284

  
285
		public void cancel() {
286
			((DefaultCancellableMonitorable) cancelMonitor).setCanceled(true);
287
		}
288

  
289
		public void run() throws GeoprocessException {
290

  
291
			Strategy strategy = StrategyManager.getStrategy(firstLayer);
292
			try {
293
				if (convexSelection) {
294
					strategy.process(visitor, firstLayer.getRecordset()
295
							.getSelection(), cancelMonitor);
296
				} else {
297
					strategy.process(visitor, cancelMonitor);
298
				}
299

  
300
				IGeometry convexHull = visitor.getConvexHull();
301
				Object[] attrs = new Object[1];
302
				attrs[0] = new Long(0);
303
				IFeature feature = FeatureFactory.createFeature(attrs,
304
						convexHull, resultLayerDefinition);
305
				writer.preProcess();
306
				DefaultRowEdited editedFeature = new DefaultRowEdited(feature,
307
						DefaultRowEdited.STATUS_ADDED, 0);
308
				writer.process(editedFeature);
309
				writer.postProcess();
310

  
311
			} catch (DriverException e) {
312
				throw new GeoprocessException(
313
						"Problemas con el driver calculando el convex hull");
314
			} catch (VisitException e) {
315
				throw new GeoprocessException(
316
						"Problemas durante el proceso de calculo del convex hull");
317
			} catch (EditionException e) {
318
				throw new GeoprocessException(
319
						"Problemas al guardar la capa resultado del convex hull");
320
			}
321
			finished = true;
322
		}
323

  
324
		public boolean isDefined() {
325
			return cancelMonitor.isDeterminatedProcess();
326
		}
327

  
328
		public boolean isCanceled() {
329
			return cancelMonitor.isCanceled();
330
		}
331

  
332
		public boolean isFinished() {
333
			return finished;
334
		}
335

  
336
	}
337

  
198 338
}
199

  
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/dissolve/DissolveVisitor.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.2  2006-03-07 21:01:33  azabala
48
 * Revision 1.3  2006-03-15 18:33:24  azabala
49 49
 * *** empty log message ***
50 50
 *
51
 * Revision 1.2  2006/03/07 21:01:33  azabala
52
 * *** empty log message ***
53
 *
51 54
 * Revision 1.1  2006/03/06 19:48:39  azabala
52 55
 * *** empty log message ***
53 56
 *
......
145 148
		this.featureProcessor = processor;
146 149
		dissolvedGeometries = new FBitSet();
147 150
	}
151
	
152
	public int getNumProcessedGeometries(){
153
		return dissolvedGeometries.cardinality();
154
	}
148 155

  
149 156
	public void setDissolvedAttributesInfo(Map numericField_sumFunction) {
150 157
		this.numericField_sumarizeFunction = numericField_sumFunction;
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/dissolve/DissolveGeoprocess.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.5  2006-03-14 18:32:46  fjp
48
* Revision 1.6  2006-03-15 18:33:24  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.5  2006/03/14 18:32:46  fjp
49 52
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
*
51 54
* Revision 1.4  2006/03/07 21:01:33  azabala
......
69 72
import java.util.Map;
70 73

  
71 74
import com.iver.cit.gvsig.fmap.DriverException;
75
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
72 76
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
73 77
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
74 78
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
75 79
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
80
import com.iver.cit.gvsig.fmap.edition.EditionException;
76 81
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
82
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable;
83
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable;
77 84
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
78 85
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
79 86
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
......
83 90
import com.iver.gvsig.geoprocessing.model.IOneLayerGeoprocess;
84 91
import com.iver.gvsig.geoprocessing.model.SummarizationFunction;
85 92
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
93
import com.iver.utiles.swing.threads.IMonitorableTask;
86 94
/**
87 95
 * Processes each geometry of a polygonal vectorial layer, looking for
88 96
 * its adjacent polygons. If this adjacent polygons has the same specified 
......
135 143
			throw new GeoprocessException("Buffer con capa de entrada a null");
136 144
		if(this.writer == null || 
137 145
		   this.schemaManager == null){
138
			throw new GeoprocessException("Operacion de buffer sin especificar capa de resultados");
146
			throw new GeoprocessException("Operacion de dissolve sin especificar capa de resultados");
139 147
		}
140 148
		if(this.dissolveField == null)
141 149
			throw new GeoprocessException("No se ha proporcionado el campo para dissolver");
......
168 176
	
169 177

  
170 178
	public void cancel() {
171
		// TODO Auto-generated method stub
172

  
179
		try {
180
			schemaManager.drop();
181
		} catch (EditionException e) {
182
			// TODO Auto-generated catch block
183
			e.printStackTrace();
184
		}
173 185
	}
174 186
	
175 187
	public ILayerDefinition createLayerDefinition() {
......
214 226
		return resultLayerDefinition;
215 227
	}
216 228

  
229
	public IMonitorableTask createTask() {
230
		try {
231
			return new DissolveMonitorableTask();
232
		} catch (DriverIOException e) {
233
			return null;
234
		}
235
	}
236
	
237
	/**
238
	 * IMonitorableTask that allows to run diff geoprocess in background,
239
	 * with cancelation requests.
240
	 * 
241
	 * @author azabala
242
	 * 
243
	 */
244
	class DissolveMonitorableTask implements IMonitorableTask {
245
		private CancellableMonitorable cancelMonitor = null;
246

  
247
		// FIXME INTERNACIONALIZAR ESTO
248
		String DISSOLVE_MESSAGE = "Computing dissolve: ";
249

  
250
		private boolean finished = false;
251

  
252
		DissolveMonitorableTask() throws DriverIOException {
253
			initialize();
254
		}
255
		void initialize() throws DriverIOException{
256
			cancelMonitor = createCancelMonitor();
257
		}
258

  
259
		private CancellableMonitorable createCancelMonitor() throws DriverIOException{
260
			DefaultCancellableMonitorable monitor = new 
261
							DefaultCancellableMonitorable();
262
			monitor.setInitialStep(0);
263
			//monitor.setDeterminatedProcess(false);
264
			monitor.setFinalStep(firstLayer.getSource().getShapeCount());
265
			monitor.setDeterminatedProcess(true);
266
			return monitor;
267
		}
268

  
269
		public int getInitialStep() {
270
			return cancelMonitor.getInitialStep();
271
		}
272

  
273
		public int getFinishStep() {
274
			return cancelMonitor.getFinalStep();
275
		}
276

  
277
		public int getCurrentStep() {
278
			//return cancelMonitor.getCurrentStep();
279
			if(visitor == null)
280
				return getInitialStep();
281
			else
282
				return visitor.getNumProcessedGeometries();
283
		}
284

  
285
		public String getStatusMessage() {
286
			// FIXME Cambiar esto por un mecanismo de eventos,
287
			// de forma que la tarea lo que tenga sea un escuchador
288
			// que cambie el mensaje de estado segun los eventos
289
			// de tareas que se est?n realizando
290
			return "Dissolve Geoprocess...";
291
		}
292

  
293
		public String getNote() {
294
			// FIXME Cambiar esto por un mecanismo de eventos,
295
			// de forma que la tarea lo que tenga sea un escuchador
296
			// que cambie el mensaje de estado segun los eventos
297
			// de tareas que se est?n realizando
298
			return DISSOLVE_MESSAGE + getCurrentStep() + " of " +
299
													getFinishStep();
300
		}
301

  
302
		public void cancel() {
303
			((DefaultCancellableMonitorable) cancelMonitor).setCanceled(true);
304
		}
305

  
306
		public void run() throws GeoprocessException {
307

  
308
			try {
309

  
310
				FeaturePersisterProcessor2 processor =
311
					new FeaturePersisterProcessor2(writer);
312
				visitor = new DissolveVisitor(dissolveField, processor);
313
				visitor.setDissolvedAttributesInfo(fields_functions);
314
				Strategy strategy =
315
					StrategyManager.getStrategy(firstLayer);
316
				visitor.setStrategy(strategy);
317
				if(dissolveOnlySelection){
318
					strategy.process(visitor, firstLayer.
319
												   getRecordset().
320
												   getSelection(),
321
												   cancelMonitor);
322
				}else{
323
					strategy.process(visitor, cancelMonitor);
324
				}
325
			} catch (DriverException e) {
326
				throw new GeoprocessException("Error accediendo a los datos durante un dissolve");
327
			} catch (VisitException e) {
328
				throw new GeoprocessException("Error al procesar los elementos de la capa de entrada durante un dissolve");
329
			} finally{
330
				finished = true;
331
			}
332
		}
333

  
334
		public boolean isDefined() {
335
			return cancelMonitor.isDeterminatedProcess();
336
		}
337

  
338
		public boolean isCanceled() {
339
			return cancelMonitor.isCanceled();
340
		}
341

  
342
		public boolean isFinished() {
343
			return finished;
344
		}
345
	}
346

  
217 347
}
218 348

  
trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/union/UnionGeoprocess.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.6  2006-03-14 18:32:46  fjp
48
* Revision 1.7  2006-03-15 18:34:41  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.6  2006/03/14 18:32:46  fjp
49 52
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
*
51 54
* Revision 1.5  2006/03/07 21:01:33  azabala
......
72 75
import com.iver.cit.gvsig.fmap.DriverException;
73 76
import com.iver.cit.gvsig.fmap.core.IFeature;
74 77
import com.iver.cit.gvsig.fmap.core.IGeometry;
78
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
75 79
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
76
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
77 80
import com.iver.cit.gvsig.fmap.edition.EditionException;
78 81
import com.iver.cit.gvsig.fmap.layers.FBitSet;
79 82
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
83
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable;
84
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable;
80 85
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
81 86
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
82 87
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
83 88
import com.iver.gvsig.geoprocessing.impl.AbstractGeoprocess;
84 89
import com.iver.gvsig.geoprocessing.impl.difference.DifferenceVisitor;
85 90
import com.iver.gvsig.geoprocessing.impl.intersection.IntersectVisitor;
91
import com.iver.gvsig.geoprocessing.impl.jtsprocessors.DeferredFeaturePersisterProcessor;
86 92
import com.iver.gvsig.geoprocessing.impl.jtsprocessors.FeaturePersisterProcessor2;
87 93
import com.iver.gvsig.geoprocessing.model.GeoprocessException;
88 94
import com.iver.gvsig.geoprocessing.model.IOverlayGeoprocess;
89 95
import com.iver.gvsig.geoprocessing.schemabuilder.DefinitionUtils;
90 96
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
97
import com.iver.utiles.swing.threads.IMonitorableTask;
91 98
/**
92 99
 * Union geoprocess is known like "spatial or" because is an overlay
93 100
 * geoprocess (it computes intersections between features of
94 101
 * two layers) formed for geometries of one layer or another.
95
 * To compute that, geoprocess do this:
96
 * for each feature of first layer.
97
 * 	does intersect with features of second layer?
98
 * if not, saves the feature.
99
 * if yes, compute intersections, save intersections, and
100
 * save difference of the original feature with intersections.
101
 * mark all features of second layer that intersect with feature.
102
 * We also mark in a new FBitSet all that feature of the second layer
103
 * that are completely within first layer bounding box.
104
 * 
105
 * Secondly, saves all features of second layer that arent marked
106
 * (they dont intersect with any feature of first layer)
107
 * 
108
 * At last, we do a new pass, processing all second layer features that 
109
 * are not completily within first layer bounding box, and we will save
110
 * its differences with intersections.
102
 * <br>
103
 *  Algorithm makes these three passes:
104
 *  a) computing intersections and saves them in a temp file.
105
 *  b) computing differences with first layer.
106
 *  c) computing differences with second layer.
111 107
 * @author azabala
112 108
 *
113 109
 *TODO Is very similar to ClipGeoprocess. Build an overlay abstract class.
114 110
 *
115 111
 *
116
 *TODO Revise algorithm (probably simpler is make three passes:
117
 *a) computing intersections and saves them in a temp file.
118
 *b) computing differences with first layer.
119
 *c) computing differences with second layer.
120
 *ES MUCHO MAS SIMPLE HACERLO DE ESTA OTRA MANERA
121
 *
122 112
 */
123 113
public class UnionGeoprocess extends AbstractGeoprocess 
124 114
							implements IOverlayGeoprocess {
......
275 265
		return null;
276 266
	}
277 267

  
268
	public IMonitorableTask createTask() {
269
		try {
270
			return new UnionMonitorableTask();
271
		} catch (DriverIOException e) {
272
			return null;
273
		}
274
	}
275
	
276
	/**
277
	 * IMonitorableTask that allows to run diff geoprocess in background,
278
	 * with cancelation requests.
279
	 * 
280
	 * @author azabala
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff