Revision 5628 trunk/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/spatialjoin/fmap/SpatialJoinGeoprocess.java

View differences:

SpatialJoinGeoprocess.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.1  2006-05-24 21:09:47  azabala
48
 * Revision 1.2  2006-06-02 18:21:28  azabala
49
 * *** empty log message ***
50
 *
51
 * Revision 1.1  2006/05/24 21:09:47  azabala
49 52
 * primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
50 53
 *
51 54
 * Revision 1.10  2006/05/08 15:38:05  azabala
......
86 89

  
87 90
import com.iver.andami.PluginServices;
88 91
import com.iver.cit.gvsig.fmap.DriverException;
92
import com.iver.cit.gvsig.fmap.core.IGeometry;
89 93
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
90 94
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
91 95
import com.iver.cit.gvsig.fmap.edition.EditionException;
92 96
import com.iver.cit.gvsig.fmap.layers.FBitSet;
93 97
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
98
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
94 99
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
95 100
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
96 101
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
97 102
import com.iver.cit.gvsig.fmap.spatialindex.INearestNeighbourFinder;
98 103
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex;
104
import com.iver.cit.gvsig.fmap.spatialindex.RTreeJsi;
99 105
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocess;
100 106
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2;
101 107
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
......
204 210
			this.nearestSpatialJoin = nearest.booleanValue();
205 211
		if(nearestSpatialJoin){
206 212
			try {
207
				ISpatialIndex spatialIndex = secondLayer.getISpatialIndex();
208
				if(spatialIndex != null && 
209
						(spatialIndex instanceof INearestNeighbourFinder))
210
				{
213
//				ISpatialIndex spatialIndex = secondLayer.getISpatialIndex();
214
//				if(spatialIndex != null && 
215
//						(spatialIndex instanceof INearestNeighbourFinder))
216
//				{
211 217
					visitor = new SpatiallyIndexedSpatialJoinVisitor(this.firstLayer, 
212 218
							this.secondLayer,
213 219
							processor);
214
				}else{
215
					
216
					visitor = new NearestSpatialJoinVisitor(this.firstLayer, 
217
							this.secondLayer,
218
							processor);
219
				}
220
//				}else{
221
//					
222
//					visitor = new NearestSpatialJoinVisitor(this.firstLayer, 
223
//							this.secondLayer,
224
//							processor);
225
//				}
220 226
			} catch (DriverException e) {
221 227
				throw new GeoprocessException("Error preparando el procesado de las capas a enlazar");
222 228
			}
......
261 267
	}
262 268

  
263 269
	public void process() throws GeoprocessException {
264
		//Comentado: esto se le debe preguntar al usuario
265
//		if(!secondLayer.isSpatiallyIndexed()){
266
//			//Revisar. Si el driver es ISpatialDB no es 
267
//			//necesario construir indice
268
//			secondLayer.createSpatialIndex();
269
//		}
270 270
		Strategy strategy =
271 271
			StrategyManager.getStrategy(firstLayer);
272 272
		
......
397 397
		}
398 398

  
399 399
		public void run() throws GeoprocessException {
400
			if(!secondLayer.isSpatiallyIndexed()){
401
				//Revisar. Si el driver es ISpatialDB no es 
402
				//necesario construir indice
403
				secondLayer.createSpatialIndex();
400
			ISpatialIndex oldSptIdx = null;
401
			if(nearestSpatialJoin){
402
				oldSptIdx = secondLayer.getISpatialIndex();
403
				if(oldSptIdx == null || ! (oldSptIdx instanceof INearestNeighbourFinder)){
404
					RTreeJsi newSptIdx = new RTreeJsi();
405
					newSptIdx.create();
406
					ReadableVectorial source = secondLayer.getSource();
407
					try {
408
						int numFeatures = source.getShapeCount();
409
						for(int i = 0; i < numFeatures; i++){
410
							IGeometry geometry = source.getShape(i);
411
							newSptIdx.insert(geometry.getBounds2D(), i);
412
						}
413
					} catch (DriverIOException e) {
414
						throw new GeoprocessException("Error intentando indexar para busqueda por mas proximo");
415
					}
416
					secondLayer.setISpatialIndex(newSptIdx);
417
				}//if oldSptIdx
418
			}//if nearest
419
			
420
			if(visitor instanceof SpatiallyIndexedSpatialJoinVisitor)
421
			{
422
				//here checks for Nearest Neighbour capabilitie
423
				((SpatiallyIndexedSpatialJoinVisitor)visitor).initialize();
404 424
			}
425
			
405 426
			Strategy strategy =
406 427
				StrategyManager.getStrategy(firstLayer);
407 428
			Strategy secondLyrStrategy =
......
419 440
					strategy.process(visitor, cancelMonitor);
420 441
				}
421 442
				
443
//				If we changed spatial index to allow Nearest Neighbour queries,
444
				//recover the old spatial index
445
				if(oldSptIdx != null)
446
					secondLayer.setISpatialIndex(oldSptIdx);
447
				
422 448
			} catch (DriverException e) {
423 449
				throw new GeoprocessException("Error al acceder a los datos durante un spatial join");
424 450
			} catch (VisitException e) {

Also available in: Unified diff