Revision 12049 trunk/libraries/libFMap/src-test/com/iver/cit/gvsig/fmap/featureiterators/PerformanceFeatureIteratorTest.java

View differences:

PerformanceFeatureIteratorTest.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.2  2007-05-30 20:12:41  azabala
48
* Revision 1.3  2007-06-07 09:31:42  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.2  2007/05/30 20:12:41  azabala
49 52
* fastIteration = true optimized.
50 53
*
51 54
* Revision 1.1  2007/05/29 19:11:03  azabala
......
57 60

  
58 61
import java.awt.geom.Rectangle2D;
59 62

  
63
import junit.framework.TestCase;
64

  
60 65
import org.cresques.cts.ICoordTrans;
61 66

  
62
import junit.framework.TestCase;
63

  
64 67
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
65 68
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
66 69
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
67 70
import com.iver.cit.gvsig.fmap.core.IFeature;
68 71
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
72
import com.iver.cit.gvsig.fmap.drivers.featureiterators.SpatialQueryFeatureIterator;
69 73
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
70
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
71 74
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex;
72 75

  
73 76

  
......
184 187
	
185 188
	//test to ask a feature over the limit (numfeatures) to low level shapefile driver
186 189
	//classes
187
	public void test2(){
188
		try {
189
			FLyrVect layer = (FLyrVect) FeatureIteratorTest.newLayer("poly-valencia.shp", FeatureIteratorTest.SHP_DRIVER_NAME);
190
			int numShapes = layer.getSource().getShapeCount();
191
			ReadableVectorial source = layer.getSource();
192
			for(int i = numShapes -1; i < (numShapes + 50); i++){
193
				source.getShape(i);
194
			}
195
			assertTrue(1 == 2);//si llega aqui, no pasa el test
196
		} catch (LoadLayerException e) {
197
			// TODO Auto-generated catch block
198
			e.printStackTrace();
199
		} catch (ReadDriverException e) {
200
			// TODO Auto-generated catch block
201
			e.printStackTrace();
202
		} catch (ExpansionFileReadException e) {
203
			// TODO Auto-generated catch block
204
			e.printStackTrace();
205
		}
206

  
207
	}
190
//	public void test2(){
191
//		try {
192
//			FLyrVect layer = (FLyrVect) FeatureIteratorTest.newLayer("poly-valencia.shp", FeatureIteratorTest.SHP_DRIVER_NAME);
193
//			int numShapes = layer.getSource().getShapeCount();
194
//			ReadableVectorial source = layer.getSource();
195
//			for(int i = numShapes -1; i < (numShapes + 50); i++){
196
//				source.getShape(i);
197
//			}
198
//			assertTrue(1 == 2);//si llega aqui, no pasa el test
199
//		} catch (LoadLayerException e) {
200
//			// TODO Auto-generated catch block
201
//			e.printStackTrace();
202
//		} catch (ReadDriverException e) {
203
//			// TODO Auto-generated catch block
204
//			e.printStackTrace();
205
//		} catch (ExpansionFileReadException e) {
206
//			// TODO Auto-generated catch block
207
//			e.printStackTrace();
208
//		}
209
//
210
//	}
208 211
	
209 212
	//test to compare fast iteration based in spatial index with precisse iteration
210 213
	//with a little filter area
......
470 473
		
471 474
	}
472 475
	
476
	/** 
477
	 Este test hay que refinarlo. Simplemente es un intento, mediante simulacion, de encontrar el valor ideal
478
	 de rectangulo de consulta para discernir cuando una iteraci?n debe hacer uso de la caracteristica boundedshapes
479
	 (leer rectangulos sin leer la geometria, a modo de 'indice espacial') y cuando no
480
	*/
481
	public void test6(){
482
		double xmin = 724000;
483
		double width = 1000;
484
		double ymin = 4373800;
485
		double height = 500;
486
		System.out.println("TEST 5: BUSQUEDA DEL LIMITE OPTIMO ENTRE BOUNDEDSHAPES Y PRECISSE PARA ITERACIONES R?PIDAS");
487
		//fast iteration
488
		try {
489
			//fast iteration
490
			lyr.getSource().setSpatialIndex(null);
491
			
492
			
493
			double BOUND_FACTOR = SpatialQueryFeatureIterator.BOUNDED_SHAPES_FACTOR;
494
			double lyrWidth = lyr.getSource().getFullExtent().getWidth();
495
			Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, width, height);
496
			while(width <= lyrWidth){
497
				
498
				ICoordTrans trans = FeatureIteratorTest.PROJECTION_DEFAULT.
499
									getCT(FeatureIteratorTest.newProjection);
500
				//si pedimos reproyeccion, el rectangulo de consulta debe estar en la proyeccion
501
				//de destino
502
				rect = trans.convert(rect);
503
//				SpatialQueryFeatureIterator.BOUNDED_SHAPES_FACTOR = 4d;
504
				BOUND_FACTOR = SpatialQueryFeatureIterator.BOUNDED_SHAPES_FACTOR;
505
				while (BOUND_FACTOR >= 1){
506
					long t0 = System.currentTimeMillis();
507
					IFeatureIterator iterator = lyr.getSource().getFeatureIterator(rect, 
508
																	null, 
509
																	FeatureIteratorTest.newProjection, 
510
																	true);
511
					while(iterator.hasNext()){
512
						iterator.next();
513
					}
514
					long t1 = System.currentTimeMillis();
515
					
516
					
517
					Rectangle2D driverExtent = lyr.getSource().getFullExtent();
518
					double areaExtent = rect.getWidth() * rect.getHeight();
519
					double areaFullExtent = driverExtent.getWidth() *
520
						                         driverExtent.getHeight();
521
					System.out.println("areaExtent="+areaExtent+", areaFullExtent="+areaFullExtent);
522
					System.out.println("full/BoundFactor="+(areaFullExtent / BOUND_FACTOR));
523
					System.out.println("BOUND_F="+BOUND_FACTOR+";time="+(t1-t0));
524
					BOUND_FACTOR /= 2d;
525
//					SpatialQueryFeatureIterator.BOUNDED_SHAPES_FACTOR = BOUND_FACTOR;
526
				}//while
527
				width *= 3;
528
				height *= 3;
529
				rect = new Rectangle2D.Double(xmin, ymin, width, height);
530
			}//while
531
			
532
		} catch (ExpansionFileReadException e) {
533
			// TODO Auto-generated catch block
534
			e.printStackTrace();
535
		} catch (ReadDriverException e) {
536
			// TODO Auto-generated catch block
537
			e.printStackTrace();
538
		}
539
	}
540
}
473 541
	
474 542
	
475 543
	
476
}
544
	
477 545

  
546

  

Also available in: Unified diff