Revision 12950

View differences:

trunk/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/difference/fmap/DifferenceVisitor.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.3  2007-03-06 16:47:58  caballero
48
 * Revision 1.4  2007-08-07 15:42:19  azabala
49
 * centrilizing JTS in JTSFacade
50
 *
51
 * Revision 1.3  2007/03/06 16:47:58  caballero
49 52
 * Exceptions
50 53
 *
51 54
 * Revision 1.2  2006/12/04 19:44:25  azabala
......
107 110
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
108 111
import com.iver.cit.gvsig.geoprocess.core.fmap.FeatureFactory;
109 112
import com.iver.cit.gvsig.geoprocess.core.fmap.FeatureProcessor;
110
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes;
113
import com.iver.cit.gvsig.geoprocess.core.util.JTSFacade;
111 114
import com.vividsolutions.jts.geom.Geometry;
112
import com.vividsolutions.jts.geom.MultiPolygon;
113
import com.vividsolutions.jts.geom.Polygon;
114 115
import com.vividsolutions.jts.precision.EnhancedPrecisionOp;
115 116

  
116 117
public class DifferenceVisitor implements FeatureVisitor {
......
174 175
	 * @author azabala
175 176
	 *
176 177
	 */
178
	
179
	/*
180
	 * TODO Dado un feature, es factible pensar que los de la otra capa que lo cubran pueden
181
	 * estar en memoria (aunque esto no sea siempre as?). Podemos hacer un
182
	 * EnhancedMemoryOverlay, que primero lo haga todo en memoria, capture un OutOfMemoryException
183
	 * y lo haga de modo incremental
184
	 * 
185
	 * */
177 186
	class UnionOverlaysVisitor implements FeatureVisitor {
178 187
		/**
179 188
		 * Result of the strategy process (union of overlays of a IGeometry)
......
192 201
		public void visit(IGeometry g, int index) throws VisitorException, ProcessVisitorException {
193 202
			if(g == null)
194 203
				return;
204
			
205
			/*
206
			 * TODO
207
			 * Cuando hagamos uso de los iteradores en geoprocessing, meter
208
			 * un readableVectorial.getFeatureIterator(IFeatureFilter), que pueda
209
			 * englobar varias opciones de filtrado.
210
			 * As?, por ejemplo, puedo tener en cuenta las SELECCIONES.
211
			 * 
212
			 * */
195 213
			if (overlayLayerSelected) {
196 214
				try {
197 215
					if (!overlayLayer.getRecordset().getSelection().get(index))
......
202 220
				}// geometry g is not selected
203 221
			}
204 222

  
223
			/*
224
			Prueba para hacer diferencia entre cualquier tipo de geometria
205 225
			if(g.getGeometryType() != XTypes.POLYGON &&
206 226
					g.getGeometryType() != XTypes.MULTI)
207 227
				return;
208

  
228
			*/
229
			
209 230
			Geometry actualGeometry = g.toJTSGeometry();
210 231
			if (overlayGeometry == null) {
211 232
				overlayGeometry = actualGeometry;
212 233
			} else {
213
				overlayGeometry = actualGeometry.union(overlayGeometry);
234
				overlayGeometry = JTSFacade.union(actualGeometry, overlayGeometry);
235
//				overlayGeometry = actualGeometry.union(overlayGeometry);
214 236
			}// if
215 237

  
216 238
		}// visit
......
231 253
	public void visit(IGeometry g, final int index) throws VisitorException, ProcessVisitorException {
232 254
		if(g == null)
233 255
			return;
256
		
257
		
258
		/*
234 259
		if(g.getGeometryType() != XTypes.POLYGON &&
235 260
				g.getGeometryType() != XTypes.MULTI)
236 261
			return;
237

  
262
		*/
238 263
		Geometry firstJts = g.toJTSGeometry();
239 264
		Geometry solution = null;
240 265
		try {
241 266
			UnionOverlaysVisitor unionVisitor = new UnionOverlaysVisitor();
242 267
			unionVisitor.overlayLayerSelected = onlyOverlayLayerSelected;
243 268
			strategy.process(unionVisitor, g.getBounds2D());
269
			
244 270
			// now we compute difference of firstJts and overlaysUnion
245 271
			Geometry overlays = unionVisitor.getUnionOfOverlays();
246 272
			if (overlays != null) {
......
248 274
			} else {
249 275
				solution = firstJts;
250 276
			}
277
			
278
			/*
279
			 * TODO Que pasa si la diferencia entre dos lineas es un punto, o una linea???
280
			 * Saldr?an geometrias mezcladas
281
			 * 
251 282
			if (!(solution instanceof Polygon)) {
252 283
				if (!(solution instanceof MultiPolygon)) {
253 284
					// intersection of adjacent polygons is a linestring
......
255 286
					return;
256 287
				}
257 288
			}
258
			featureProcessor.processFeature(createFeature(solution, index));
259

  
289
			*/
290
			if(!JTSFacade.checkNull(solution)){
291
				featureProcessor.processFeature(createFeature(solution, index));
292
			}
260 293
		} catch (ReadDriverException e) {
261 294
			throw new ProcessVisitorException(overlayLayer.getName(),e,
262 295
					"Error buscando los overlays que intersectan con un feature");
......
299 332
	 * atributos con el mismo nombre?) De momento, se buscar? en
300 333
	 * ILayerDefinition la posicion que ocupa un campo a partir de su nombre.
301 334
	 * Esto obliga a que 2 campos no tomen el mismo nombre
335
	 * 
336
	 * POSIBLE SOLUCION: ANTEPONER EL NOMBRE DE LA LAYER AL NOMBRE DEL CAMPO
302 337
	 */
303 338
	private IFeature createFeature(Geometry jtsGeometry, int firstLayerIndex)
304 339
			throws ReadDriverException {
......
326 361
		return solution;
327 362
	}
328 363

  
329
	/*
330
	 * Value[] featureAttr = new Value[numFieldsA]; for (int indexField = 0;
331
	 * indexField < numFieldsA; indexField++) { featureAttr[indexField] =
332
	 * firstRs.getFieldValue(firstLayerIndex, indexField); } solution =
333
	 * FeatureFactory.createFeature(featureAttr, diffGeometry); return solution;
334
	 */
335

  
336 364
	public void setFeatureProcessor(FeatureProcessor featureProcessor) {
337 365
		this.featureProcessor = featureProcessor;
338 366
	}
trunk/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/difference/fmap/DifferenceGeoprocess.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.4  2007-05-15 07:24:19  cesar
48
 * Revision 1.5  2007-08-07 15:42:19  azabala
49
 * centrilizing JTS in JTSFacade
50
 *
51
 * Revision 1.4  2007/05/15 07:24:19  cesar
49 52
 * Add the finished method for execution from Event Dispatch Thread
50 53
 *
51 54
 * Revision 1.3  2007/03/06 16:47:58  caballero
......
105 108
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
106 109
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException;
107 110
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
111
import com.iver.cit.gvsig.fmap.core.FShape;
108 112
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
109 113
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
110 114
import com.iver.cit.gvsig.fmap.layers.FBitSet;
......
116 120
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2;
117 121
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
118 122
import com.iver.cit.gvsig.geoprocess.core.fmap.IOverlayGeoprocess;
119
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes;
120 123
import com.iver.utiles.swing.threads.CancellableMonitorable;
121 124
import com.iver.utiles.swing.threads.DefaultCancellableMonitorable;
122 125
import com.iver.utiles.swing.threads.IMonitorableTask;
......
190 193
			throw new GeoprocessException(
191 194
					"Operacion de interseccion sin especificar capa de resultados");
192 195
		}
196
		/*AZABALA: PERMITIMOS CAPAS DE PUNTOS, LINEAS Y DE POLIGONOS
193 197
		try {
194 198
			if (firstLayer.getShapeType() != XTypes.POLYGON
195 199
					&& firstLayer.getShapeType() != XTypes.MULTI) {
......
205 209
			throw new GeoprocessException(
206 210
			"Error al tratar de chequear si las capas a intersectar son de pol?gonos");
207 211
		}
212
		*/
208 213

  
209 214
	}
210 215

  
......
213 218
	//es que usa visitors distintos
214 219
	//REDISE?AR TODOS LOS OVERLAYGEOPROCESS
215 220
	public void process() throws GeoprocessException {
216

  
217 221
		try {
218
			//FIXME Sacar esto de aqu? y ponerlo fuera. Marcaremos como precondicion
219
			//que el esquema del geoproceso haya sido creado
220
			// Prepare the result
221
			this.schemaManager.createSchema(createLayerDefinition());
222
			writer.preProcess();
223
			Strategy strategy =
224
				StrategyManager.getStrategy(firstLayer);
225
			FeaturePersisterProcessor2 featureProcessor = new FeaturePersisterProcessor2(
226
					writer);
227
			Strategy overlayStrategy =
228
				StrategyManager.getStrategy(overlayLayer);
229
			DifferenceVisitor visitor = new DifferenceVisitor(overlayLayer,
230
					featureProcessor, overlayStrategy, onlyClipLayerSelection);
231
			visitor.setLayerDefinition(resultLayerDefinition);
232
			if (this.onlyFirstLayerSelection) {
233
				strategy.process(visitor, this.firstLayer.getRecordset()
234
						.getSelection());
235
			} else {
236
				strategy.process(visitor);
237
			}
238

  
239
		} catch (ProcessVisitorException e) {
240
			throw new GeoprocessException(
241
					"Error al procesar el feature de una capa durante el geoproceso interseccion");
242
		} catch (ReadDriverException e) {
243
			throw new GeoprocessException(
244
				"Error de driver al calcular el geoproceso interseccion");
245
		} catch (SchemaEditionException e) {
246
			throw new GeoprocessException(
247
			  	"Error en el esquema de la nueva capa");
248
		} catch (ExpansionFileReadException e) {
249
			throw new GeoprocessException(
250
				"Error de driver al calcular el geoproceso interseccion");
251
		} catch (VisitorException e) {
252
			throw new GeoprocessException(
253
			 	"Error de driver al calcular el geoproceso interseccion");
222
			new DifferenceMonitorableTask().run();
223
		}catch (DriverIOException e) {
224
			throw new GeoprocessException("Error de lectura de driver durante geoproceso diferencia");
254 225
		}
255 226
	}
256 227

  
......
266 237
	public ILayerDefinition createLayerDefinition() {
267 238
		if (resultLayerDefinition == null) {
268 239
			try {
269
//				resultLayerDefinition = DefinitionUtils.mergeLayerDefinitions(
270
//						firstLayer, overlayLayer);
271 240
				resultLayerDefinition = DefinitionUtils.createLayerDefinition(firstLayer);
241
				//All overlay geoprocesses could generate various kind of geometry types
242
				resultLayerDefinition.setShapeType(FShape.MULTI);
272 243
			} catch (Exception e) {
273 244
				// TODO Quizas createLayerDefinition deberia lanzar
274 245
				// una excepcion

Also available in: Unified diff