Revision 11971 trunk/libraries/libFMap/src-test/com/iver/cit/gvsig/fmap/featureiterators/FeatureIteratorTest.java
FeatureIteratorTest.java | ||
---|---|---|
45 | 45 |
* |
46 | 46 |
* $Id$ |
47 | 47 |
* $Log$ |
48 |
* Revision 1.5 2007-05-29 19:11:03 azabala |
|
48 |
* Revision 1.6 2007-06-04 07:12:14 caballero |
|
49 |
* connections refactoring |
|
50 |
* |
|
51 |
* Revision 1.5 2007/05/29 19:11:03 azabala |
|
49 | 52 |
* *** empty log message *** |
50 | 53 |
* |
51 | 54 |
* Revision 1.4 2007/05/23 16:54:29 azabala |
... | ... | |
89 | 92 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
90 | 93 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
91 | 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; |
|
92 | 97 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
98 |
import com.iver.cit.gvsig.fmap.drivers.IConnection; |
|
93 | 99 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
94 |
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
|
100 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialJDBCDriver;
|
|
95 | 101 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
96 | 102 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
97 | 103 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
... | ... | |
114 | 120 |
CRSFactory.getCRS("EPSG:23030"); |
115 | 121 |
static IProjection newProjection = |
116 | 122 |
CRSFactory.getCRS("EPSG:23029"); |
117 |
|
|
123 |
|
|
118 | 124 |
static{ |
119 | 125 |
try { |
120 | 126 |
doSetup(); |
... | ... | |
141 | 147 |
if (LayerFactory.getDM().getDriverNames().length < 1) |
142 | 148 |
throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath); |
143 | 149 |
} |
144 |
|
|
145 |
|
|
150 |
|
|
151 |
|
|
146 | 152 |
protected void setUp() throws Exception { |
147 | 153 |
super.setUp(); |
148 | 154 |
doSetup(); |
149 |
|
|
155 |
|
|
150 | 156 |
} |
151 | 157 |
|
152 | 158 |
|
... | ... | |
164 | 170 |
String user = "root"; |
165 | 171 |
String pwd = "root"; |
166 | 172 |
String tableName = layerName; |
167 |
Connection conn; |
|
173 |
IConnection conn;
|
|
168 | 174 |
try { |
169 | 175 |
Class.forName("com.mysql.jdbc.Driver"); |
170 | 176 |
} catch (ClassNotFoundException e1) { |
171 | 177 |
throw new LoadLayerException(layerName, e1); |
172 | 178 |
} |
173 | 179 |
try { |
174 |
conn = DriverManager.getConnection(dbURL, user, pwd);
|
|
175 |
conn.setAutoCommit(false);
|
|
180 |
conn = ConnectionFactory.createConnection(dbURL, user, pwd);
|
|
181 |
((ConnectionJDBC)conn).getConnection().setAutoCommit(false);
|
|
176 | 182 |
|
177 | 183 |
String fidField = "gid"; |
178 | 184 |
String geomField = "geom"; |
179 | 185 |
String[] fields = new String[1]; |
180 | 186 |
fields[0] = "gid"; |
181 | 187 |
String whereClause = ""; |
182 |
VectorialJDBCDriver driver = (VectorialJDBCDriver)
|
|
188 |
IVectorialJDBCDriver driver = (IVectorialJDBCDriver)
|
|
183 | 189 |
LayerFactory.getDM().getDriver("mySQL JDBC Driver"); |
184 | 190 |
String strEPSG = "23030"; |
185 | 191 |
DBLayerDefinition lyrDef = new DBLayerDefinition(); |
... | ... | |
208 | 214 |
return null; |
209 | 215 |
|
210 | 216 |
} |
211 |
|
|
212 |
|
|
217 |
|
|
218 |
|
|
213 | 219 |
//test para chequear la rapidez de los metodos de verificacion de candidatos en consultas |
214 | 220 |
//a partir de rectangulo |
215 | 221 |
public void test0(){ |
... | ... | |
219 | 225 |
try { |
220 | 226 |
Geometry geo1 = reader.read(pol1); |
221 | 227 |
Geometry geo2 = reader.read(pol2); |
222 |
|
|
228 |
|
|
223 | 229 |
IGeometry igeo1 = FConverter.jts_to_igeometry(geo1); |
224 | 230 |
IGeometry igeo2 = FConverter.jts_to_igeometry(geo2); |
225 |
|
|
231 |
|
|
226 | 232 |
double xmin = 410000; |
227 | 233 |
double xmax = 415000; |
228 | 234 |
double ymin = 4790000; |
229 | 235 |
double ymax = 4793000; |
230 | 236 |
Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin)); |
231 |
|
|
237 |
|
|
232 | 238 |
//PrecciseSpatialCheck |
233 | 239 |
long t0 = System.currentTimeMillis(); |
234 | 240 |
int NUM_ITERATIONS = 50000; |
... | ... | |
237 | 243 |
rect.getMinY(), rect.getWidth(), rect.getHeight()); |
238 | 244 |
igeo2.fastIntersects(rect.getMinX(), |
239 | 245 |
rect.getMinY(), rect.getWidth(), rect.getHeight()); |
240 |
}
|
|
246 |
} |
|
241 | 247 |
long t1 = System.currentTimeMillis(); |
242 | 248 |
System.out.println((t1-t0)+" con precissespatialcheck"); |
243 |
|
|
249 |
|
|
244 | 250 |
//FastSpatialCheck |
245 | 251 |
Rectangle2D b1 = igeo1.getBounds2D(); |
246 | 252 |
Rectangle2D b2 = igeo2.getBounds2D(); |
247 |
|
|
248 |
|
|
253 |
|
|
254 |
|
|
249 | 255 |
long t2 = System.currentTimeMillis(); |
250 | 256 |
for(int i = 0; i < NUM_ITERATIONS;i++){ |
251 | 257 |
XRectangle2D.intersectInclusive(rect, b1); |
252 | 258 |
XRectangle2D.intersectInclusive(rect, b2); |
253 |
}
|
|
259 |
} |
|
254 | 260 |
long t3 = System.currentTimeMillis(); |
255 | 261 |
System.out.println((t3-t2)+" con fastspatialcheck"); |
256 |
|
|
262 |
|
|
257 | 263 |
assertTrue((t3-t2) < (t1 - t0)); |
258 | 264 |
//Spatial index check |
259 |
|
|
265 |
|
|
260 | 266 |
} catch (ParseException e) { |
261 | 267 |
// TODO Auto-generated catch block |
262 | 268 |
e.printStackTrace(); |
263 | 269 |
} |
264 |
|
|
270 |
|
|
265 | 271 |
} |
266 |
|
|
267 |
|
|
268 |
|
|
269 | 272 |
|
273 |
|
|
274 |
|
|
275 |
|
|
270 | 276 |
//pruebas de iteracion para shp (vectorialfileadapter) y dxf (vectorialadapter) |
271 | 277 |
public void test1() { |
272 | 278 |
try { |
273 | 279 |
//pruebas de reproyeccion y seleccion de numero de campos |
274 | 280 |
FLyrVect lyr = (FLyrVect) newLayer("Cantabria.shp", SHP_DRIVER_NAME); |
275 | 281 |
lyr.setAvailable(true); |
276 |
|
|
282 |
|
|
277 | 283 |
//iteration selecting two fields |
278 | 284 |
IFeatureIterator iterator = lyr.getSource().getFeatureIterator(new String[]{"ID", "AREA"}, null); |
279 | 285 |
IFeature feature = iterator.next(); |
... | ... | |
296 | 302 |
double ymin = 4790000; |
297 | 303 |
double ymax = 4793000; |
298 | 304 |
Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin)); |
299 |
|
|
305 |
|
|
300 | 306 |
//fast iteration |
301 | 307 |
long t0 = System.currentTimeMillis(); |
302 | 308 |
iterator = lyr2.getSource().getFeatureIterator(rect, null, newProjection, true); |
... | ... | |
306 | 312 |
numFeatures++; |
307 | 313 |
} |
308 | 314 |
long t1 = System.currentTimeMillis(); |
309 |
|
|
315 |
|
|
310 | 316 |
//vemos si hay diferencia entre el fast = true y el fast = false |
311 | 317 |
iterator = lyr2.getSource().getFeatureIterator(rect, null, newProjection, false); |
312 | 318 |
int numFeatures3 = 0; |
... | ... | |
316 | 322 |
} |
317 | 323 |
long t2 = System.currentTimeMillis(); |
318 | 324 |
assertTrue(numFeatures3 <= numFeatures); |
319 |
|
|
325 |
|
|
320 | 326 |
System.out.println((t1-t0)+" en la iteracion rapida"); |
321 | 327 |
System.out.println("Recuperados "+numFeatures); |
322 | 328 |
System.out.println((t2-t1)+" en la iteracion lenta"); |
323 | 329 |
System.out.println("Recuperados "+numFeatures3); |
324 |
|
|
325 |
|
|
330 |
|
|
331 |
|
|
326 | 332 |
int numFeatures2 = 0; |
327 | 333 |
iterator = lyr2.getSource().getFeatureIterator(); |
328 | 334 |
while(iterator.hasNext()){ |
... | ... | |
377 | 383 |
} |
378 | 384 |
} |
379 | 385 |
|
380 |
|
|
381 |
|
|
386 |
|
|
387 |
|
|
382 | 388 |
// public void test3(){ |
383 | 389 |
// try { |
384 | 390 |
// FLyrVect layer = (FLyrVect) newLayer("poly-valencia.shp", SHP_DRIVER_NAME); |
... | ... | |
402 | 408 |
// } |
403 | 409 |
// |
404 | 410 |
// } |
405 |
|
|
411 |
|
|
406 | 412 |
//test of featureIterator with layer poly-valencia using a spatial filter. |
407 |
//jaume found a bug with an infinite loop iteration
|
|
408 |
|
|
413 |
//jaume found a bug with an infinite loop iteration |
|
414 |
|
|
409 | 415 |
public void test4(){ |
410 | 416 |
try { |
411 | 417 |
FLyrVect layer = (FLyrVect) newLayer("poly-valencia.shp", SHP_DRIVER_NAME); |
412 | 418 |
Rectangle2D extent = layer.getFullExtent(); |
413 | 419 |
String[] fields = layer.getRecordset().getFieldNames(); |
414 |
|
|
415 |
|
|
420 |
|
|
421 |
|
|
416 | 422 |
IFeatureIterator iterator = layer. |
417 | 423 |
getSource(). |
418 | 424 |
getFeatureIterator(extent,fields, null, true); |
... | ... | |
434 | 440 |
e.printStackTrace(); |
435 | 441 |
} |
436 | 442 |
} |
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
|
441 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
447 |
|
|
442 | 448 |
public void test5(){ |
443 | 449 |
try { |
444 | 450 |
int WIDTH = 300; |
... | ... | |
451 | 457 |
mapa.getLayers().addLayer(layer); |
452 | 458 |
BufferedImage img = new BufferedImage(WIDTH, HEIGHT, |
453 | 459 |
BufferedImage.TYPE_INT_ARGB); |
454 |
|
|
460 |
|
|
455 | 461 |
long t0 = System.currentTimeMillis(); |
456 | 462 |
mapa.draw(img, img.createGraphics(),mapa.getScaleView()); |
457 | 463 |
long t1 = System.currentTimeMillis(); |
458 | 464 |
System.out.println((t1-t0)+" en dibujar con MapContext.draw"); |
459 |
|
|
460 |
|
|
465 |
|
|
466 |
|
|
461 | 467 |
long t2 = System.currentTimeMillis(); |
462 | 468 |
layer._draw(img, img.createGraphics(),vp, new Cancellable(){ |
463 | 469 |
public boolean isCanceled() { |
... | ... | |
467 | 473 |
}}, getScaleView(vp)); |
468 | 474 |
long t3 = System.currentTimeMillis(); |
469 | 475 |
System.out.println((t3-t2)+" en dibujar con layer._draw"); |
470 |
|
|
476 |
|
|
471 | 477 |
} catch (LoadLayerException e) { |
472 | 478 |
// TODO Auto-generated catch block |
473 | 479 |
e.printStackTrace(); |
... | ... | |
478 | 484 |
// TODO Auto-generated catch block |
479 | 485 |
e.printStackTrace(); |
480 | 486 |
} |
481 |
|
|
487 |
|
|
482 | 488 |
} |
483 |
|
|
484 |
|
|
485 |
|
|
486 |
|
|
487 |
|
|
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
|
493 |
|
|
488 | 494 |
//TODO Mover spatialindextest a esta clase |
489 | 495 |
public void test7(){ |
490 |
|
|
496 |
|
|
491 | 497 |
} |
492 |
|
|
493 |
|
|
498 |
|
|
499 |
|
|
494 | 500 |
private long getScaleView(ViewPort viewPort) { |
495 | 501 |
double[] CHANGE = { 100000, 100, 1, 0.1, 160934.4, |
496 | 502 |
91.44, 30.48, 2.54, 1/8.983152841195214E-4 }; |
... | ... | |
512 | 518 |
viewPort.getAdjustedExtent().getMaxX(), viewPort.getImageSize() |
513 | 519 |
.getWidth(), dpi)); |
514 | 520 |
} |
515 |
|
|
521 |
|
|
516 | 522 |
} |
517 | 523 |
|
Also available in: Unified diff