Revision 12049

View differences:

trunk/libraries/libFMap/src-test/com/iver/cit/gvsig/fmap/featureiterators/FeatureIteratorTest.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.6  2007-06-04 07:12:14  caballero
49
* connections refactoring
48
* Revision 1.7  2007-06-07 09:31:42  azabala
49
* *** empty log message ***
50 50
*
51 51
* Revision 1.5  2007/05/29 19:11:03  azabala
52 52
* *** empty log message ***
......
92 92
import com.iver.cit.gvsig.fmap.core.IGeometry;
93 93
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
94 94
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
95
import com.iver.cit.gvsig.fmap.drivers.ConnectionFactory;
96
import com.iver.cit.gvsig.fmap.drivers.ConnectionJDBC;
97 95
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
96
import com.iver.cit.gvsig.fmap.drivers.DefaultJDBCDriver;
98 97
import com.iver.cit.gvsig.fmap.drivers.IConnection;
99 98
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
100 99
import com.iver.cit.gvsig.fmap.drivers.IVectorialJDBCDriver;
......
120 119
		CRSFactory.getCRS("EPSG:23030");
121 120
	static IProjection newProjection =
122 121
		CRSFactory.getCRS("EPSG:23029");
123

  
122
	
124 123
	static{
125 124
		try {
126 125
			doSetup();
......
147 146
		if (LayerFactory.getDM().getDriverNames().length < 1)
148 147
			throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath);
149 148
	}
150

  
151

  
149
	
150
	
152 151
	protected void setUp() throws Exception {
153 152
		super.setUp();
154 153
		doSetup();
155

  
154
		
156 155
	}
157 156

  
158 157

  
......
170 169
	        String user = "root";
171 170
	        String pwd = "root";
172 171
	        String tableName = layerName;
173
	        IConnection conn;
172
	        Connection conn;
174 173
	        try {
175 174
				Class.forName("com.mysql.jdbc.Driver");
176 175
			} catch (ClassNotFoundException e1) {
177 176
				throw new LoadLayerException(layerName, e1);
178 177
			}
179 178
			try {
180
				conn = ConnectionFactory.createConnection(dbURL, user, pwd);
181
		        ((ConnectionJDBC)conn).getConnection().setAutoCommit(false);
179
				conn = DriverManager.getConnection(dbURL, user, pwd);
180
		        conn.setAutoCommit(false);
182 181

  
183 182
		        String fidField = "gid";
184 183
		        String geomField = "geom";
......
200 199
		        {
201 200
		            ((ICanReproject)driver).setDestProjection(strEPSG);
202 201
		        }
203
		        driver.setData(conn, lyrDef);
202
		        ((DefaultJDBCDriver)driver).setData((IConnection) conn, lyrDef);
204 203
		        IProjection proj = null;
205 204
		        if (driver instanceof ICanReproject)
206 205
		        {
......
214 213
			return null;
215 214

  
216 215
	}
217

  
218

  
216
	
217
	
219 218
	//test para chequear la rapidez de los metodos de verificacion de candidatos en consultas
220 219
	//a partir de rectangulo
221 220
	public void test0(){
......
225 224
		try {
226 225
			Geometry geo1 = reader.read(pol1);
227 226
			Geometry geo2 = reader.read(pol2);
228

  
227
			
229 228
			IGeometry igeo1 = FConverter.jts_to_igeometry(geo1);
230 229
			IGeometry igeo2 = FConverter.jts_to_igeometry(geo2);
231

  
230
			
232 231
			double xmin = 410000;
233 232
			double xmax = 415000;
234 233
			double ymin = 4790000;
235 234
			double ymax = 4793000;
236 235
			Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin));
237

  
236
			
238 237
			//PrecciseSpatialCheck
239 238
			 long t0 = System.currentTimeMillis();
240 239
			 int NUM_ITERATIONS = 50000;
......
243 242
						rect.getMinY(), rect.getWidth(), rect.getHeight());
244 243
				 igeo2.fastIntersects(rect.getMinX(),
245 244
							rect.getMinY(), rect.getWidth(), rect.getHeight());
246
			 }
245
			 }	 
247 246
			 long t1 = System.currentTimeMillis();
248 247
			 System.out.println((t1-t0)+" con precissespatialcheck");
249

  
248
			
250 249
			//FastSpatialCheck
251 250
			 Rectangle2D b1 = igeo1.getBounds2D();
252 251
			 Rectangle2D b2 = igeo2.getBounds2D();
253

  
254

  
252
			 
253
			 
255 254
			 long t2 = System.currentTimeMillis();
256 255
			 for(int i = 0; i < NUM_ITERATIONS;i++){
257 256
				 XRectangle2D.intersectInclusive(rect, b1);
258 257
				 XRectangle2D.intersectInclusive(rect, b2);
259
			 }
258
			 }	 
260 259
			 long t3 = System.currentTimeMillis();
261 260
			 System.out.println((t3-t2)+" con fastspatialcheck");
262

  
261
			 
263 262
			 assertTrue((t3-t2) < (t1 - t0));
264 263
			//Spatial index check
265

  
264
			
266 265
		} catch (ParseException e) {
267 266
			// TODO Auto-generated catch block
268 267
			e.printStackTrace();
269 268
		}
270

  
269
		
271 270
	}
271
	
272
	
273
	
272 274

  
273

  
274

  
275

  
276 275
	//pruebas de iteracion para shp (vectorialfileadapter) y dxf (vectorialadapter)
277 276
	public void test1() {
278 277
		try {
279 278
			//pruebas de reproyeccion y seleccion de numero de campos
280 279
			FLyrVect lyr = (FLyrVect) newLayer("Cantabria.shp", SHP_DRIVER_NAME);
281 280
			lyr.setAvailable(true);
282

  
281
			
283 282
			//iteration selecting two fields
284 283
			IFeatureIterator iterator = lyr.getSource().getFeatureIterator(new String[]{"ID", "AREA"}, null);
285 284
			IFeature feature = iterator.next();
......
290 289
			IFeature feature2 = iterator.next();
291 290
			//test of field restriction
292 291
			assertTrue(feature.getAttributes().length == 2);
293
			assertTrue(feature2.getAttributes().length > 2);
292
			//si pasamos null, no devuelve ning?n campo
293
			assertTrue(feature2.getAttributes().length == 0);
294 294
			assertTrue(!feature.getGeometry().toJTSGeometry().equals(feature2.getGeometry().toJTSGeometry()));
295 295

  
296 296

  
......
302 302
			double ymin = 4790000;
303 303
			double ymax = 4793000;
304 304
			Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin));
305

  
305
			
306 306
			//fast iteration
307 307
			long t0 = System.currentTimeMillis();
308 308
			iterator = lyr2.getSource().getFeatureIterator(rect, null, newProjection, true);
......
312 312
				numFeatures++;
313 313
			}
314 314
			long t1 = System.currentTimeMillis();
315

  
315
		
316 316
			//vemos si hay diferencia entre el fast = true y el fast = false
317 317
			iterator = lyr2.getSource().getFeatureIterator(rect, null, newProjection, false);
318 318
			int numFeatures3 = 0;
......
322 322
			}
323 323
			long t2 = System.currentTimeMillis();
324 324
			assertTrue(numFeatures3 <= numFeatures);
325

  
325
			
326 326
			System.out.println((t1-t0)+" en la iteracion rapida");
327 327
			System.out.println("Recuperados "+numFeatures);
328 328
			System.out.println((t2-t1)+" en la iteracion lenta");
329 329
			System.out.println("Recuperados "+numFeatures3);
330

  
331

  
330
			
331
			
332 332
			int numFeatures2 = 0;
333 333
			iterator = lyr2.getSource().getFeatureIterator();
334 334
			while(iterator.hasNext()){
......
383 383
		}
384 384
	}
385 385

  
386

  
387

  
386
	
387
	
388 388
//	public void test3(){
389 389
//		try {
390 390
//			FLyrVect layer = (FLyrVect) newLayer("poly-valencia.shp", SHP_DRIVER_NAME);
......
408 408
//		}
409 409
//
410 410
//	}
411

  
411
	
412 412
	//test of featureIterator with layer poly-valencia using a spatial filter.
413
	//jaume found a bug with an infinite loop iteration
414

  
413
	//jaume found a bug with an infinite loop iteration 
414
	
415 415
	public void test4(){
416 416
		try {
417 417
			FLyrVect layer = (FLyrVect) newLayer("poly-valencia.shp", SHP_DRIVER_NAME);
418 418
			Rectangle2D extent = layer.getFullExtent();
419 419
			String[] fields = layer.getRecordset().getFieldNames();
420

  
421

  
420
			
421
			
422 422
			IFeatureIterator iterator = layer.
423 423
							getSource().
424 424
							getFeatureIterator(extent,fields, null, true);
......
440 440
			e.printStackTrace();
441 441
		}
442 442
	}
443

  
444

  
445

  
446

  
447

  
443
	
444
	
445
	
446
	
447
	
448 448
	public void test5(){
449 449
			try {
450 450
				int WIDTH = 300;
451 451
				int HEIGHT = 200;
452
				FLyrVect layer = (FLyrVect) newLayer("poly-valencia.shp", SHP_DRIVER_NAME);
452
				FLyrVect layer = (FLyrVect) newLayer("municipios.shp", SHP_DRIVER_NAME);
453 453
				ViewPort vp = new ViewPort(PROJECTION_DEFAULT);
454 454
				vp.setImageSize(new Dimension(WIDTH, HEIGHT));
455 455
				vp.setExtent(layer.getFullExtent());
......
457 457
				mapa.getLayers().addLayer(layer);
458 458
				BufferedImage img = new BufferedImage(WIDTH, HEIGHT,
459 459
						BufferedImage.TYPE_INT_ARGB);
460

  
460
				
461 461
				long t0 = System.currentTimeMillis();
462 462
				mapa.draw(img, img.createGraphics(),mapa.getScaleView());
463 463
				long t1 = System.currentTimeMillis();
464 464
				System.out.println((t1-t0)+" en dibujar con MapContext.draw");
465

  
466

  
465
				
466
				
467 467
				long t2 = System.currentTimeMillis();
468
				layer._draw(img, img.createGraphics(),vp, new Cancellable(){
468
				layer.draw(img, img.createGraphics(),vp, new Cancellable(){
469 469
					public boolean isCanceled() {
470 470
						return false;
471 471
					}
......
473 473
					}}, getScaleView(vp));
474 474
				long t3 = System.currentTimeMillis();
475 475
				System.out.println((t3-t2)+" en dibujar con layer._draw");
476

  
476
				
477 477
			} catch (LoadLayerException e) {
478 478
				// TODO Auto-generated catch block
479 479
				e.printStackTrace();
......
484 484
				// TODO Auto-generated catch block
485 485
				e.printStackTrace();
486 486
			}
487

  
487
			
488 488
	}
489

  
490

  
491

  
492

  
493

  
489
	
490
	
491
		
492
		
493
	
494 494
	//TODO Mover spatialindextest a esta clase
495 495
	public void test7(){
496

  
496
		
497 497
	}
498

  
499

  
498
	
499
	
500 500
	private long getScaleView(ViewPort viewPort) {
501 501
		double[] CHANGE = { 100000, 100, 1, 0.1, 160934.4,
502 502
				91.44, 30.48, 2.54, 1/8.983152841195214E-4 };
......
518 518
				viewPort.getAdjustedExtent().getMaxX(), viewPort.getImageSize()
519 519
						.getWidth(), dpi));
520 520
	}
521

  
521
	
522 522
}
523 523

  
trunk/libraries/libFMap/src-test/com/iver/cit/gvsig/fmap/featureiterators/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