svn-gvsig-desktop / trunk / libraries / libFMap / src-test / com / iver / cit / gvsig / fmap / featureiterators / PerformanceFeatureIteratorTest.java @ 11906
History | View | Annotate | Download (14.2 KB)
1 |
/*
|
---|---|
2 |
* Created on 28-may-2007
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: PerformanceFeatureIteratorTest.java 11906 2007-05-30 20:12:41Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.2 2007-05-30 20:12:41 azabala
|
49 |
* fastIteration = true optimized.
|
50 |
*
|
51 |
* Revision 1.1 2007/05/29 19:11:03 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
package com.iver.cit.gvsig.fmap.featureiterators; |
57 |
|
58 |
import java.awt.geom.Rectangle2D; |
59 |
|
60 |
import org.cresques.cts.ICoordTrans; |
61 |
|
62 |
import junit.framework.TestCase; |
63 |
|
64 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
65 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
66 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
67 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
68 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
70 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
71 |
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex; |
72 |
|
73 |
|
74 |
/**
|
75 |
* Tests to probe feature iteration methods.
|
76 |
*
|
77 |
* These test are not functional-test (performance).
|
78 |
|
79 |
* @author azabala
|
80 |
*
|
81 |
*/
|
82 |
public class PerformanceFeatureIteratorTest extends TestCase { |
83 |
|
84 |
static FLyrVect lyr;
|
85 |
|
86 |
|
87 |
static{
|
88 |
try {
|
89 |
lyr = (FLyrVect) FeatureIteratorTest.newLayer("poly-valencia.shp",
|
90 |
FeatureIteratorTest.SHP_DRIVER_NAME); |
91 |
lyr.setAvailable(true);
|
92 |
} catch (LoadLayerException e) {
|
93 |
// TODO Auto-generated catch block
|
94 |
e.printStackTrace(); |
95 |
} |
96 |
} |
97 |
|
98 |
|
99 |
public void test1() { |
100 |
try {
|
101 |
//pruebas de iteracion espacial
|
102 |
System.out.println("TEST 1: ESPACIAL CON FULL EXTENT Y REPROYECCI?N"); |
103 |
Rectangle2D rect = lyr.getFullExtent();
|
104 |
IFeature feature = null;
|
105 |
//fast iteration
|
106 |
long t0 = System.currentTimeMillis(); |
107 |
ISpatialIndex spatialIndex = lyr.getSource().getSpatialIndex(); |
108 |
lyr.getSource().setSpatialIndex(null);
|
109 |
|
110 |
//Sin indice espacial, rapida
|
111 |
//si pedimos reproyeccion, el rectangulo de consulta debe estar en la proyeccion
|
112 |
//de destino
|
113 |
ICoordTrans trans = FeatureIteratorTest.PROJECTION_DEFAULT.getCT(FeatureIteratorTest.newProjection); |
114 |
rect = trans.convert(rect); |
115 |
IFeatureIterator iterator = lyr.getSource().getFeatureIterator(rect, |
116 |
null,
|
117 |
FeatureIteratorTest.newProjection, |
118 |
true);
|
119 |
int numFeatures = 0; |
120 |
while(iterator.hasNext()){
|
121 |
feature = iterator.next(); |
122 |
numFeatures++; |
123 |
} |
124 |
long t1 = System.currentTimeMillis(); |
125 |
|
126 |
//sin indice espacial, lenta
|
127 |
iterator = lyr.getSource().getFeatureIterator(rect, |
128 |
null,
|
129 |
FeatureIteratorTest.newProjection, |
130 |
false);
|
131 |
int numFeatures2 = 0; |
132 |
while(iterator.hasNext()){
|
133 |
feature = iterator.next(); |
134 |
numFeatures2++; |
135 |
} |
136 |
long t2 = System.currentTimeMillis(); |
137 |
|
138 |
lyr.getSource().setSpatialIndex(spatialIndex); |
139 |
long t3 = System.currentTimeMillis(); |
140 |
|
141 |
//con indice espacial rapida
|
142 |
iterator = lyr.getSource().getFeatureIterator(rect, |
143 |
null,
|
144 |
FeatureIteratorTest.newProjection, |
145 |
true);
|
146 |
int numFeatures3 = 0; |
147 |
while(iterator.hasNext()){
|
148 |
feature = iterator.next(); |
149 |
numFeatures3++; |
150 |
} |
151 |
long t4 = System.currentTimeMillis(); |
152 |
//con indice espacial lenta
|
153 |
iterator = lyr.getSource().getFeatureIterator(rect, |
154 |
null,
|
155 |
FeatureIteratorTest.newProjection, |
156 |
false);
|
157 |
int numFeatures4 = 0; |
158 |
while(iterator.hasNext()){
|
159 |
feature = iterator.next(); |
160 |
numFeatures4++; |
161 |
} |
162 |
long t5 = System.currentTimeMillis(); |
163 |
|
164 |
|
165 |
System.out.println((t1-t0)+" en la iteracion rapida sin indice espacial"); |
166 |
System.out.println("Recuperados "+numFeatures); |
167 |
System.out.println((t4-t3)+" en la iteracion rapida con indice espacial"); |
168 |
System.out.println("Recuperados "+numFeatures3); |
169 |
System.out.println((t2-t1)+" en la iteracion lenta sin indice espacial"); |
170 |
System.out.println("Recuperados "+numFeatures2); |
171 |
System.out.println((t5-t4)+" en la iteracion lenta con indice espacial"); |
172 |
System.out.println("Recuperados "+numFeatures4); |
173 |
|
174 |
} catch (ReadDriverException e) {
|
175 |
// TODO Auto-generated catch block
|
176 |
e.printStackTrace(); |
177 |
} catch (ExpansionFileReadException e) {
|
178 |
// TODO Auto-generated catch block
|
179 |
e.printStackTrace(); |
180 |
} |
181 |
} |
182 |
|
183 |
|
184 |
|
185 |
//test to ask a feature over the limit (numfeatures) to low level shapefile driver
|
186 |
//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 |
} |
208 |
|
209 |
//test to compare fast iteration based in spatial index with precisse iteration
|
210 |
//with a little filter area
|
211 |
public void test3(){ |
212 |
double xmin = 724000; |
213 |
double xmax = 725000; |
214 |
double ymin = 4373800; |
215 |
double ymax = 4374300; |
216 |
System.out.println("TEST 2: ESPACIAL CON RECTANGULO PEQUE?O Y REPROYECCI?N"); |
217 |
Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin)); |
218 |
ICoordTrans trans = FeatureIteratorTest.PROJECTION_DEFAULT. |
219 |
getCT(FeatureIteratorTest.newProjection); |
220 |
//si pedimos reproyeccion, el rectangulo de consulta debe estar en la proyeccion
|
221 |
//de destino
|
222 |
rect = trans.convert(rect); |
223 |
|
224 |
|
225 |
IFeature feature = null;
|
226 |
//fast iteration
|
227 |
try {
|
228 |
//fast iteration
|
229 |
long t0 = System.currentTimeMillis(); |
230 |
ISpatialIndex spatialIndex = lyr.getSource().getSpatialIndex(); |
231 |
lyr.getSource().setSpatialIndex(null);
|
232 |
|
233 |
//Sin indice espacial, rapida
|
234 |
|
235 |
IFeatureIterator iterator = lyr.getSource().getFeatureIterator(rect, |
236 |
null,
|
237 |
FeatureIteratorTest.newProjection, |
238 |
true);
|
239 |
int numFeatures = 0; |
240 |
while(iterator.hasNext()){
|
241 |
feature = iterator.next(); |
242 |
numFeatures++; |
243 |
} |
244 |
long t1 = System.currentTimeMillis(); |
245 |
|
246 |
//sin indice espacial, lenta
|
247 |
iterator = lyr.getSource().getFeatureIterator(rect, |
248 |
null,
|
249 |
FeatureIteratorTest.newProjection, |
250 |
false);
|
251 |
int numFeatures2 = 0; |
252 |
while(iterator.hasNext()){
|
253 |
feature = iterator.next(); |
254 |
numFeatures2++; |
255 |
} |
256 |
long t2 = System.currentTimeMillis(); |
257 |
|
258 |
lyr.getSource().setSpatialIndex(spatialIndex); |
259 |
long t3 = System.currentTimeMillis(); |
260 |
|
261 |
//con indice espacial rapida
|
262 |
iterator = lyr.getSource().getFeatureIterator(rect, |
263 |
null,
|
264 |
FeatureIteratorTest.newProjection, |
265 |
true);
|
266 |
int numFeatures3 = 0; |
267 |
while(iterator.hasNext()){
|
268 |
feature = iterator.next(); |
269 |
numFeatures3++; |
270 |
} |
271 |
long t4 = System.currentTimeMillis(); |
272 |
//con indice espacial lenta
|
273 |
iterator = lyr.getSource().getFeatureIterator(rect, |
274 |
null,
|
275 |
FeatureIteratorTest.newProjection, |
276 |
false);
|
277 |
int numFeatures4 = 0; |
278 |
while(iterator.hasNext()){
|
279 |
feature = iterator.next(); |
280 |
numFeatures4++; |
281 |
} |
282 |
long t5 = System.currentTimeMillis(); |
283 |
|
284 |
|
285 |
System.out.println((t1-t0)+" en la iteracion rapida sin indice espacial"); |
286 |
System.out.println("Recuperados "+numFeatures); |
287 |
System.out.println((t4-t3)+" en la iteracion rapida con indice espacial"); |
288 |
System.out.println("Recuperados "+numFeatures3); |
289 |
System.out.println((t2-t1)+" en la iteracion lenta sin indice espacial"); |
290 |
System.out.println("Recuperados "+numFeatures2); |
291 |
System.out.println((t5-t4)+" en la iteracion lenta con indice espacial"); |
292 |
System.out.println("Recuperados "+numFeatures4); |
293 |
|
294 |
} catch (ExpansionFileReadException e) {
|
295 |
// TODO Auto-generated catch block
|
296 |
e.printStackTrace(); |
297 |
} catch (ReadDriverException e) {
|
298 |
// TODO Auto-generated catch block
|
299 |
e.printStackTrace(); |
300 |
} |
301 |
|
302 |
} |
303 |
|
304 |
|
305 |
//the same test as test1 but without reprojection
|
306 |
public void test4() { |
307 |
try {
|
308 |
//pruebas de iteracion espacial
|
309 |
Rectangle2D rect = lyr.getFullExtent();
|
310 |
IFeature feature = null;
|
311 |
System.out.println("TEST 3: ESPACIAL CON FULL EXTENT SIN REPROYECCI?N"); |
312 |
//fast iteration
|
313 |
long t0 = System.currentTimeMillis(); |
314 |
ISpatialIndex spatialIndex = lyr.getSource().getSpatialIndex(); |
315 |
lyr.getSource().setSpatialIndex(null);
|
316 |
|
317 |
|
318 |
IFeatureIterator iterator = lyr.getSource().getFeatureIterator(rect, |
319 |
null,
|
320 |
FeatureIteratorTest.PROJECTION_DEFAULT, |
321 |
true);
|
322 |
int numFeatures = 0; |
323 |
while(iterator.hasNext()){
|
324 |
feature = iterator.next(); |
325 |
numFeatures++; |
326 |
} |
327 |
long t1 = System.currentTimeMillis(); |
328 |
|
329 |
//sin indice espacial, lenta
|
330 |
iterator = lyr.getSource().getFeatureIterator(rect, |
331 |
null,
|
332 |
FeatureIteratorTest.PROJECTION_DEFAULT, |
333 |
false);
|
334 |
int numFeatures2 = 0; |
335 |
while(iterator.hasNext()){
|
336 |
feature = iterator.next(); |
337 |
numFeatures2++; |
338 |
} |
339 |
long t2 = System.currentTimeMillis(); |
340 |
|
341 |
lyr.getSource().setSpatialIndex(spatialIndex); |
342 |
long t3 = System.currentTimeMillis(); |
343 |
|
344 |
//con indice espacial rapida
|
345 |
iterator = lyr.getSource().getFeatureIterator(rect, |
346 |
null,
|
347 |
FeatureIteratorTest.PROJECTION_DEFAULT, |
348 |
true);
|
349 |
int numFeatures3 = 0; |
350 |
while(iterator.hasNext()){
|
351 |
feature = iterator.next(); |
352 |
numFeatures3++; |
353 |
} |
354 |
long t4 = System.currentTimeMillis(); |
355 |
//con indice espacial lenta
|
356 |
iterator = lyr.getSource().getFeatureIterator(rect, |
357 |
null,
|
358 |
FeatureIteratorTest.PROJECTION_DEFAULT, |
359 |
false);
|
360 |
int numFeatures4 = 0; |
361 |
while(iterator.hasNext()){
|
362 |
feature = iterator.next(); |
363 |
numFeatures4++; |
364 |
} |
365 |
long t5 = System.currentTimeMillis(); |
366 |
|
367 |
|
368 |
System.out.println((t1-t0)+" en la iteracion rapida sin indice espacial"); |
369 |
System.out.println("Recuperados "+numFeatures); |
370 |
System.out.println((t4-t3)+" en la iteracion rapida con indice espacial"); |
371 |
System.out.println("Recuperados "+numFeatures3); |
372 |
System.out.println((t2-t1)+" en la iteracion lenta sin indice espacial"); |
373 |
System.out.println("Recuperados "+numFeatures2); |
374 |
System.out.println((t5-t4)+" en la iteracion lenta con indice espacial"); |
375 |
System.out.println("Recuperados "+numFeatures4); |
376 |
|
377 |
} catch (ReadDriverException e) {
|
378 |
// TODO Auto-generated catch block
|
379 |
e.printStackTrace(); |
380 |
} catch (ExpansionFileReadException e) {
|
381 |
// TODO Auto-generated catch block
|
382 |
e.printStackTrace(); |
383 |
} |
384 |
} |
385 |
|
386 |
//the same test as test3 without reprojection
|
387 |
public void test5(){ |
388 |
double xmin = 724000; |
389 |
double xmax = 725000; |
390 |
double ymin = 4373800; |
391 |
double ymax = 4374300; |
392 |
Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin)); |
393 |
System.out.println("TEST 4: ESPACIAL CON RECTANGULO PEQUE?O SIN REPROYECCI?N"); |
394 |
IFeature feature = null;
|
395 |
//fast iteration
|
396 |
try {
|
397 |
//fast iteration
|
398 |
long t0 = System.currentTimeMillis(); |
399 |
ISpatialIndex spatialIndex = lyr.getSource().getSpatialIndex(); |
400 |
lyr.getSource().setSpatialIndex(null);
|
401 |
|
402 |
//Sin indice espacial, rapida
|
403 |
|
404 |
IFeatureIterator iterator = lyr.getSource().getFeatureIterator(rect, |
405 |
null,
|
406 |
FeatureIteratorTest.PROJECTION_DEFAULT, |
407 |
true);
|
408 |
int numFeatures = 0; |
409 |
while(iterator.hasNext()){
|
410 |
feature = iterator.next(); |
411 |
numFeatures++; |
412 |
} |
413 |
long t1 = System.currentTimeMillis(); |
414 |
|
415 |
//sin indice espacial, lenta
|
416 |
iterator = lyr.getSource().getFeatureIterator(rect, |
417 |
null,
|
418 |
FeatureIteratorTest.PROJECTION_DEFAULT, |
419 |
false);
|
420 |
int numFeatures2 = 0; |
421 |
while(iterator.hasNext()){
|
422 |
feature = iterator.next(); |
423 |
numFeatures2++; |
424 |
} |
425 |
long t2 = System.currentTimeMillis(); |
426 |
|
427 |
lyr.getSource().setSpatialIndex(spatialIndex); |
428 |
long t3 = System.currentTimeMillis(); |
429 |
|
430 |
//con indice espacial rapida
|
431 |
iterator = lyr.getSource().getFeatureIterator(rect, |
432 |
null,
|
433 |
FeatureIteratorTest.PROJECTION_DEFAULT, |
434 |
true);
|
435 |
int numFeatures3 = 0; |
436 |
while(iterator.hasNext()){
|
437 |
feature = iterator.next(); |
438 |
numFeatures3++; |
439 |
} |
440 |
long t4 = System.currentTimeMillis(); |
441 |
//con indice espacial lenta
|
442 |
iterator = lyr.getSource().getFeatureIterator(rect, |
443 |
null,
|
444 |
FeatureIteratorTest.PROJECTION_DEFAULT, |
445 |
false);
|
446 |
int numFeatures4 = 0; |
447 |
while(iterator.hasNext()){
|
448 |
feature = iterator.next(); |
449 |
numFeatures4++; |
450 |
} |
451 |
long t5 = System.currentTimeMillis(); |
452 |
|
453 |
|
454 |
System.out.println((t1-t0)+" en la iteracion rapida sin indice espacial"); |
455 |
System.out.println("Recuperados "+numFeatures); |
456 |
System.out.println((t4-t3)+" en la iteracion rapida con indice espacial"); |
457 |
System.out.println("Recuperados "+numFeatures3); |
458 |
System.out.println((t2-t1)+" en la iteracion lenta sin indice espacial"); |
459 |
System.out.println("Recuperados "+numFeatures2); |
460 |
System.out.println((t5-t4)+" en la iteracion lenta con indice espacial"); |
461 |
System.out.println("Recuperados "+numFeatures4); |
462 |
|
463 |
} catch (ExpansionFileReadException e) {
|
464 |
// TODO Auto-generated catch block
|
465 |
e.printStackTrace(); |
466 |
} catch (ReadDriverException e) {
|
467 |
// TODO Auto-generated catch block
|
468 |
e.printStackTrace(); |
469 |
} |
470 |
|
471 |
} |
472 |
|
473 |
|
474 |
|
475 |
|
476 |
} |
477 |
|