Revision 20984

View differences:

branches/v2_0_0_prep/libraries/libFMap/src-test/org/gvsig/fmap/AllTests.java
1
package org.gvsig.fmap;
2

  
3
import java.io.File;
4
import java.net.URL;
5

  
6
import junit.framework.Test;
7
import junit.framework.TestCase;
8
import junit.framework.TestSuite;
9

  
10
import org.cresques.cts.IProjection;
11
import org.gvsig.fmap.crs.CRSFactory;
12
import org.gvsig.fmap.drivers.formats.dbf.reading.TestDbf;
13
import org.gvsig.fmap.drivers.formats.dgn.reading.TestDgn;
14
import org.gvsig.fmap.drivers.iterators.DBFeatureIteratorTest;
15
import org.gvsig.fmap.drivers.iterators.FeatureIteratorTest;
16
import org.gvsig.fmap.drivers.iterators.PerformanceFeatureIteratorTest;
17
import org.gvsig.fmap.drivers.iterators.spatialindex.SpatialIndexTest;
18
import org.gvsig.fmap.mapcontext.MapContext;
19
import org.gvsig.fmap.mapcontext.ViewPort;
20
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
21
import org.gvsig.fmap.mapcontext.layers.FLayer;
22
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
23
import org.gvsig.fmap.mapcontext.layers.LayersIteratorTest;
24
import org.gvsig.fmap.mapcontext.rendering.legend.TestAbstractIntervalLegend;
25
import org.gvsig.fmap.mapcontext.rendering.legend.TestIClassifiedLegend;
26
import org.gvsig.fmap.mapcontext.rendering.legend.TestILegend;
27
import org.gvsig.fmap.mapcontext.rendering.symbols.TestCartographicSupportForSymbol;
28
import org.gvsig.fmap.mapcontext.rendering.symbols.TestCartographySupport;
29
import org.gvsig.fmap.mapcontext.rendering.symbols.TestDrawFills;
30
import org.gvsig.fmap.mapcontext.rendering.symbols.TestDrawLines;
31
import org.gvsig.fmap.mapcontext.rendering.symbols.TestDrawMarkers;
32
import org.gvsig.fmap.mapcontext.rendering.symbols.TestISymbol;
33
import org.gvsig.fmap.mapcontext.rendering.symbols.TestMultiLayerSymbol;
34
import org.gvsig.fmap.mapcontrol.tools.AreaListenerTest;
35

  
36
import com.vividsolutions.jts.operation.overlay.SnappingOverlayOperationTest;
37

  
38
public class AllTests extends TestCase{
39
	/**
40
	 * The EPSG:4326 projection
41
	 */
42
	public static IProjection TEST_DEFAULT_PROJECTION =
43
		CRSFactory.getCRS("EPSG:4326");
44
	
45
	/**
46
	 * The EPSG:23030 projection
47
	 */
48
	public static IProjection TEST_DEFAULT_MERCATOR_PROJECTION =
49
		CRSFactory.getCRS("EPSG:23030");
50
	
51
	/**
52
	 * The EPSG:23029 projection
53
	 */
54
	public static IProjection test_newProjection =
55
		CRSFactory.getCRS("EPSG:23029");
56

  
57
	public static Test suite() {
58
		TestSuite suite = new TestSuite("Test for com.iver.cit.gvsig.fmap");
59
		//$JUnit-BEGIN$
60

  
61
		/* LayersIterator */
62
			suite.addTestSuite(LayersIteratorTest.class);
63

  
64

  
65
		/* Symbols (jaume) */
66
			// integration tests
67
				// ISymbol
68
				suite.addTestSuite(TestISymbol.class);
69
				suite.addTestSuite(TestMultiLayerSymbol.class);
70

  
71
				// CartographicSupport
72
				suite.addTestSuite(TestCartographicSupportForSymbol.class);
73
				
74
		//
75
		/*
76
		 * Feature iterators
77
		 * */
78
		suite.addTestSuite(FeatureIteratorTest.class);
79
		
80
		/*
81
		 * Other Tests present in FMap (cesar)
82
		 * Remove them from here and the src-test dir if they are not
83
		 * useful anymore.
84
		 */
85

  
86
		suite.addTestSuite(AreaListenerTest.class);
87
		suite.addTestSuite(DBFeatureIteratorTest.class);
88
		suite.addTestSuite(PerformanceFeatureIteratorTest.class);
89
		suite.addTestSuite(SnappingOverlayOperationTest.class);
90
		suite.addTestSuite(SpatialIndexTest.class);
91
		suite.addTestSuite(TestAbstractIntervalLegend.class);
92
		suite.addTestSuite(TestCartographicSupportForSymbol.class);
93
		suite.addTestSuite(TestDbf.class);
94
		suite.addTestSuite(TestDgn.class);
95
		suite.addTestSuite(TestDrawFills.class);
96
		suite.addTestSuite(TestDrawLines.class);
97
		suite.addTestSuite(TestDrawMarkers.class);
98
		suite.addTestSuite(TestIClassifiedLegend.class);
99
		suite.addTestSuite(TestILegend.class);
100
		suite.addTestSuite(TestMultiLayerSymbol.class);
101

  
102
		//$JUnit-END$
103
		return suite;
104
	}
105

  
106
//// jaume
107
//// PASTED FROM FeatureIteratorTest.java to be globally accessible
108
	static final String fwAndamiDriverPath = "../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers";
109
	private static File baseDataPath;
110
	private static File baseDriversPath;
111

  
112

  
113
	public static void setUpDrivers() {
114
		try {
115
			URL url = AllTests.class.getResource("testdata");
116
			if (url == null)
117
				throw new Exception("No se encuentra el directorio con datos de prueba");
118

  
119
			baseDataPath = new File(url.getFile());
120
			if (!baseDataPath.exists())
121
				throw new Exception("No se encuentra el directorio con datos de prueba");
122

  
123
			baseDriversPath = new File(fwAndamiDriverPath);
124
			if (!baseDriversPath.exists())
125
				throw new Exception("Can't find drivers path: " + fwAndamiDriverPath);
126

  
127
			LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath());
128
			if (LayerFactory.getDM().getDriverNames().length < 1)
129
				throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath);
130
		} catch (Exception e) {
131
			throw new RuntimeException(e);
132
		}
133
	}
134

  
135
	public static FLayer newLayer(String fileName,
136
			String driverName)
137
	throws LoadLayerException {
138
		File file = new File(baseDataPath, fileName);
139
		return LayerFactory.createLayer(fileName,
140
				driverName,
141
				file, TEST_DEFAULT_MERCATOR_PROJECTION);
142
	}
143

  
144
	public static MapContext newMapContext(IProjection projection) {
145
		ViewPort vp = new ViewPort(projection);
146
		return new MapContext(vp);
147
	}
148

  
149
//// end past
150
}
0 151

  
branches/v2_0_0_prep/libraries/libFMap/src-test/org/gvsig/fmap/drivers/formats/dgn/reading/TestDgn.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.fmap.drivers.formats.dgn.reading;
42

  
43
import java.io.File;
44

  
45
import org.gvsig.fmap.drivers.formats.dgn.reading.DGNElemCore;
46
import org.gvsig.fmap.drivers.formats.dgn.reading.DGNReader;
47
import org.gvsig.fmap.drivers.formats.dgn.reading.DgnMemoryDriver;
48

  
49
import junit.framework.TestCase;
50

  
51
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
52
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
53
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
54

  
55
public class TestDgn extends TestCase {
56
	DgnMemoryDriver driver = new DgnMemoryDriver();
57
	File file = new File("c:/LP01C.dgn");
58

  
59
	public static void main(String[] args) {
60
		junit.textui.TestRunner.run(TestDgn.class);
61
	}
62

  
63
	protected void setUp() throws Exception {
64
		super.setUp();
65
	}
66

  
67
	/*
68
	 * Test method for 'com.iver.cit.gvsig.fmap.drivers.dgn.DgnMemoryDriver.initialize()'
69
	 */
70
	public void testInitialize() {
71
		try {
72
			driver.open(file);
73
			driver.initialize();
74
			DGNReader reader = new DGNReader(file.getAbsolutePath());
75
				reader.DGNGotoElement(100);
76
				DGNElemCore elemento = reader.DGNReadElement();
77

  
78
				reader.DGNDumpElement(reader.getInfo(), elemento, null);
79
		}  catch (OpenDriverException e) {
80
			e.printStackTrace();
81
		} catch (InitializeDriverException e) {
82
			e.printStackTrace();
83
		} catch (ReadDriverException e) {
84
			e.printStackTrace();
85
		}
86

  
87
	}
88

  
89
}
90

  
91

  
0 92

  
branches/v2_0_0_prep/libraries/libFMap/src-test/org/gvsig/fmap/drivers/formats/dbf/reading/TestDbf.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
package org.gvsig.fmap.drivers.formats.dbf.reading;
43
import java.io.File;
44

  
45
import org.gvsig.fmap.drivers.formats.dbf.reading.DBFDriver;
46

  
47
import junit.framework.TestCase;
48

  
49
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
50

  
51
public class TestDbf extends TestCase {
52
	DBFDriver driver = new DBFDriver();
53
	File file = new File("c:/prueba.dbf");
54

  
55
	public static void main(String[] args) {
56
		junit.textui.TestRunner.run(TestDbf.class);
57
	}
58

  
59
	protected void setUp() throws Exception {
60
		super.setUp();
61
	}
62

  
63
	/*
64
	 * Test method for 'com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver.initialize()'
65
	 */
66
	public void testInitialize() {
67
		try {
68
			driver.open(file);
69
			System.out.println(driver.getFields());//FieldValue(1,0));
70
		} catch (OpenDriverException e) {
71
			e.printStackTrace();
72
		}
73

  
74
	}
75

  
76
}
77

  
78

  
0 79

  
branches/v2_0_0_prep/libraries/libFMap/src-test/org/gvsig/fmap/drivers/iterators/FeatureIteratorTest.java
1
/*
2
 * Created on 17-abr-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$
47
* $Log$
48
* Revision 1.11  2007-09-20 08:08:29  jaume
49
* ReadExpansionFileException removed from this context
50
*
51
* Revision 1.10  2007/06/29 13:07:01  jaume
52
* +PictureLineSymbol
53
*
54
* Revision 1.9  2007/06/27 20:18:35  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.8  2007/06/07 10:20:38  azabala
58
* includes closeIterator
59
*
60
* Revision 1.7  2007/06/07 09:31:42  azabala
61
* *** empty log message ***
62
*
63
* Revision 1.5  2007/05/29 19:11:03  azabala
64
* *** empty log message ***
65
*
66
* Revision 1.4  2007/05/23 16:54:29  azabala
67
* new test for bug 2510 phpcollab task (infinite loop for poly-valencia.shp)
68
*
69
* Revision 1.3  2007/05/08 08:48:27  jaume
70
* GRAPHIC TESTING FOR ISYMBOLS!!!
71
*
72
* Revision 1.2  2007/04/25 15:16:10  azabala
73
* tests for featureiterators with mysql database
74
*
75
* Revision 1.1  2007/04/19 18:12:56  azabala
76
* *** empty log message ***
77
*
78
*
79
*/
80
package org.gvsig.fmap.drivers.iterators;
81

  
82
import java.awt.Dimension;
83
import java.awt.Toolkit;
84
import java.awt.geom.Rectangle2D;
85
import java.awt.image.BufferedImage;
86
import java.io.File;
87
import java.net.URL;
88
import java.util.prefs.Preferences;
89

  
90
import junit.framework.TestCase;
91

  
92
import org.cresques.cts.IProjection;
93
import org.geotools.resources.geometry.XRectangle2D;
94
import org.gvsig.fmap.core.features.IFeature;
95
import org.gvsig.fmap.core.geometries.IGeometry;
96
import org.gvsig.fmap.core.geometries.utils.FConverter;
97
import org.gvsig.fmap.crs.CRSFactory;
98
import org.gvsig.fmap.drivers.reading.ConnectionJDBC;
99
import org.gvsig.fmap.drivers.reading.DBLayerDefinition;
100
import org.gvsig.fmap.drivers.reading.DefaultJDBCDriver;
101
import org.gvsig.fmap.drivers.reading.ICanReproject;
102
import org.gvsig.fmap.drivers.reading.IFeatureIterator;
103
import org.gvsig.fmap.drivers.reading.IVectorialJDBCDriver;
104
import org.gvsig.fmap.mapcontext.MapContext;
105
import org.gvsig.fmap.mapcontext.ViewPort;
106
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
107
import org.gvsig.fmap.mapcontext.layers.FLayer;
108
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
109
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
110

  
111
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
112
import com.iver.utiles.swing.threads.Cancellable;
113
import com.vividsolutions.jts.geom.Geometry;
114
import com.vividsolutions.jts.geom.GeometryFactory;
115
import com.vividsolutions.jts.io.ParseException;
116
import com.vividsolutions.jts.io.WKTReader;
117

  
118
public class FeatureIteratorTest extends TestCase {
119
	static final String fwAndamiDriverPath = "../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers";
120
	private static File baseDataPath;
121
	private static File baseDriversPath;
122

  
123
	public static String SHP_DRIVER_NAME = "gvSIG shp driver";
124
	public  static String DXF_DRIVER_NAME = "gvSIG DXF Memory Driver";
125

  
126
	//TODO MOVER TODO LO ESTATICO A UNA CLASE AUXILIAR QUE NO SEA JUNIT
127
	static IProjection PROJECTION_DEFAULT =
128
		CRSFactory.getCRS("EPSG:23030");
129
	static IProjection newProjection =
130
		CRSFactory.getCRS("EPSG:23029");
131

  
132
	static{
133
		try {
134
			doSetup();
135
		} catch (Exception e) {
136
			// TODO Auto-generated catch block
137
			e.printStackTrace();
138
		}
139
	}
140

  
141
	private static void doSetup() throws Exception{
142
		URL url = FeatureIteratorTest.class.getResource("testdata");
143
		if (url == null)
144
			throw new Exception("No se encuentra el directorio con datos de prueba");
145

  
146
		baseDataPath = new File(url.getFile());
147
		if (!baseDataPath.exists())
148
			throw new Exception("No se encuentra el directorio con datos de prueba");
149

  
150
		baseDriversPath = new File(fwAndamiDriverPath);
151
		if (!baseDriversPath.exists())
152
			throw new Exception("Can't find drivers path: " + fwAndamiDriverPath);
153

  
154
		LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath());
155
		if (LayerFactory.getDM().getDriverNames().length < 1)
156
			throw new Exception("Can't find drivers in path: " + fwAndamiDriverPath);
157
	}
158

  
159

  
160
	protected void setUp() throws Exception {
161
		super.setUp();
162
		doSetup();
163

  
164
	}
165

  
166

  
167
	public static  FLayer newLayer(String fileName,
168
									   String driverName)
169
								throws LoadLayerException {
170
		File file = new File(baseDataPath, fileName);
171
		return LayerFactory.createLayer(fileName,
172
										driverName,
173
										file, PROJECTION_DEFAULT);
174
	}
175

  
176
	public static FLyrVect newJdbcLayer(String layerName) throws LoadLayerException{
177
	        String dbURL = "jdbc:mysql://localhost:3306/datos";
178
	        String user = "root";
179
	        String pwd = "root";
180
	        String tableName = layerName;
181
	        //Connection conn;
182
	        try {
183
				Class.forName("com.mysql.jdbc.Driver");
184
			} catch (ClassNotFoundException e1) {
185
				throw new LoadLayerException(layerName, e1);
186
			}
187
			try {
188
				
189
				ConnectionJDBC conn = new ConnectionJDBC();
190
				conn.setDataConnection(dbURL, user, pwd);
191
				
192
		        String fidField = "gid";
193
		        String geomField = "geom";
194
		        String[] fields = new String[1];
195
		        fields[0] = "gid";
196
		        String whereClause = "";
197
		        IVectorialJDBCDriver driver = (IVectorialJDBCDriver)
198
		        	LayerFactory.getDM().getDriver("mySQL JDBC Driver");
199
		        String strEPSG = "23030";
200
		        DBLayerDefinition lyrDef = new DBLayerDefinition();
201
		        lyrDef.setName(layerName);
202
		        lyrDef.setTableName(tableName);
203
		        lyrDef.setWhereClause(whereClause);
204
		        lyrDef.setFieldGeometry(geomField);
205
		        lyrDef.setFieldNames(fields);
206
		        lyrDef.setFieldID(fidField);
207
		        lyrDef.setSRID_EPSG(strEPSG);
208
		        lyrDef.setConnection(conn);
209
		        if (driver instanceof ICanReproject)
210
		        {
211
		            ((ICanReproject)driver).setDestProjection(strEPSG);
212
		        }
213
		        ((DefaultJDBCDriver)driver).setData(conn, lyrDef);
214
		        IProjection proj = newProjection;//ahora, si no reproyecta la bbdd reproyecta el iterador
215
//		        if (driver instanceof ICanReproject)
216
//		        {
217
//		            proj = CRSFactory.getCRS("EPSG:" + ((ICanReproject)driver).getSourceProjection());
218
//		        }
219

  
220
		        return (FLyrVect) LayerFactory.createDBLayer(driver, layerName, proj);
221
			}catch(Exception e){
222
				e.printStackTrace();
223
			}
224
			return null;
225

  
226
	}
227

  
228

  
229
	//test para chequear la rapidez de los metodos de verificacion de candidatos en consultas
230
	//a partir de rectangulo
231
	public void test0(){
232
		String pol1 = "MULTIPOLYGON (((413434.195990259 4790622.699703139, 413441.7000601477 4790624.699360616, 413442.6978540559 4790620.700045662, 413435.2020303979 4790618.700388186, 413434.195990259 4790622.699703139, 413434.195990259 4790622.699703139)))";
233
		String pol2 = "MULTIPOLYGON (((411585.59723499016 4791781.20126231, 411575.39664767997 4791791.999412685, 411586.29816459515 4791802.297648691, 411596.4987519054 4791791.499498316, 411585.59723499016 4791781.20126231, 411585.59723499016 4791781.20126231)))";
234
		WKTReader reader = new WKTReader(new GeometryFactory());
235
		try {
236
			Geometry geo1 = reader.read(pol1);
237
			Geometry geo2 = reader.read(pol2);
238

  
239
			IGeometry igeo1 = FConverter.jts_to_igeometry(geo1);
240
			IGeometry igeo2 = FConverter.jts_to_igeometry(geo2);
241

  
242
			double xmin = 410000;
243
			double xmax = 415000;
244
			double ymin = 4790000;
245
			double ymax = 4793000;
246
			Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin));
247

  
248
			//PrecciseSpatialCheck
249
			 long t0 = System.currentTimeMillis();
250
			 int NUM_ITERATIONS = 50000;
251
			 for(int i = 0; i < NUM_ITERATIONS;i++){
252
				 igeo1.fastIntersects(rect.getMinX(),
253
						rect.getMinY(), rect.getWidth(), rect.getHeight());
254
				 igeo2.fastIntersects(rect.getMinX(),
255
							rect.getMinY(), rect.getWidth(), rect.getHeight());
256
			 }
257
			 long t1 = System.currentTimeMillis();
258
			 System.out.println((t1-t0)+" con precissespatialcheck");
259

  
260
			//FastSpatialCheck
261
			 Rectangle2D b1 = igeo1.getBounds2D();
262
			 Rectangle2D b2 = igeo2.getBounds2D();
263

  
264

  
265
			 long t2 = System.currentTimeMillis();
266
			 for(int i = 0; i < NUM_ITERATIONS;i++){
267
				 XRectangle2D.intersectInclusive(rect, b1);
268
				 XRectangle2D.intersectInclusive(rect, b2);
269
			 }
270
			 long t3 = System.currentTimeMillis();
271
			 System.out.println((t3-t2)+" con fastspatialcheck");
272

  
273
			 assertTrue((t3-t2) < (t1 - t0));
274
			//Spatial index check
275

  
276
		} catch (ParseException e) {
277
			// TODO Auto-generated catch block
278
			e.printStackTrace();
279
		}
280

  
281
	}
282

  
283

  
284

  
285

  
286
	//pruebas de iteracion para shp (vectorialfileadapter) y dxf (vectorialadapter)
287
	public void test1() {
288
		try {
289
			//pruebas de reproyeccion y seleccion de numero de campos
290
			FLyrVect lyr = (FLyrVect) newLayer("Cantabria.shp", SHP_DRIVER_NAME);
291
			lyr.setAvailable(true);
292

  
293
			//iteration selecting two fields
294
			IFeatureIterator iterator = lyr.getSource().getFeatureIterator(new String[]{"ID", "AREA"}, null);
295
			IFeature feature = iterator.next();
296
			assertTrue(feature != null);
297

  
298
			//iteration with reprojection
299
			iterator = lyr.getSource().getFeatureIterator((String[])null, newProjection);
300
			IFeature feature2 = iterator.next();
301
			//test of field restriction
302
			assertTrue(feature.getAttributes().length == 2);
303
			//si pasamos null, no devuelve ning?n campo
304
			assertTrue(feature2.getAttributes().length == 0);
305
			assertTrue(!feature.getGeometry().toJTSGeometry().equals(feature2.getGeometry().toJTSGeometry()));
306
			iterator.closeIterator();
307

  
308
			//pruebas de iteracion espacial
309
			FLyrVect lyr2 = (FLyrVect) newLayer("Edificaciones.shp", SHP_DRIVER_NAME);
310
			lyr2.setAvailable(true);
311
			double xmin = 410000;
312
			double xmax = 415000;
313
			double ymin = 4790000;
314
			double ymax = 4793000;
315
			Rectangle2D rect = new Rectangle2D.Double(xmin, ymin, (xmax-xmin), (ymax-ymin));
316

  
317
			//fast iteration
318
			long t0 = System.currentTimeMillis();
319
			iterator = lyr2.getSource().getFeatureIterator(rect, null, newProjection, true);
320
			int numFeatures = 0;
321
			while(iterator.hasNext()){
322
				feature = iterator.next();
323
				numFeatures++;
324
			}
325
			long t1 = System.currentTimeMillis();
326

  
327
			//vemos si hay diferencia entre el fast = true y el fast = false
328
			iterator = lyr2.getSource().getFeatureIterator(rect, null, newProjection, false);
329
			int numFeatures3 = 0;
330
			while(iterator.hasNext()){
331
				feature = iterator.next();
332
				numFeatures3++;
333
			}
334
			long t2 = System.currentTimeMillis();
335
			assertTrue(numFeatures3 <= numFeatures);
336
			iterator.closeIterator();
337
			System.out.println((t1-t0)+" en la iteracion rapida");
338
			System.out.println("Recuperados "+numFeatures);
339
			System.out.println((t2-t1)+" en la iteracion lenta");
340
			System.out.println("Recuperados "+numFeatures3);
341

  
342

  
343
			int numFeatures2 = 0;
344
			iterator = lyr2.getSource().getFeatureIterator();
345
			while(iterator.hasNext()){
346
				feature = iterator.next();
347
				numFeatures2++;
348
			}
349
			assertTrue(numFeatures2 > numFeatures);
350
			iterator.closeIterator();
351

  
352
			//pruebas de iteracion en base a criterios alfanumericos
353
			final String expr = "select * from " + lyr.getRecordset().getName() + " where area < 700;";
354
			iterator = lyr.getSource().getFeatureIterator(expr, null);
355
			numFeatures2 = 0;
356
			while(iterator.hasNext()){
357
				feature = iterator.next();
358
				numFeatures2++;
359
			}
360
			iterator.closeIterator();
361
			
362

  
363
			
364
			FLayer lyr53245 = LayerFactory.createLayer("/home/jaume/callestodo.shp",
365
					SHP_DRIVER_NAME,
366
					new File("/home/jaume/callestodo.shp"), PROJECTION_DEFAULT);
367
			
368
			iterator = ((FLyrVect) lyr53245).getSource().getFeatureIterator("select * from " + ((FLyrVect) lyr53245).getRecordset().getName() +" where (TIPCALLE = 'C' or  TIPCALLE='AV' or TIPCALLE='PL');", null);
369
			while(iterator.hasNext()){
370
				feature = iterator.next();
371
				numFeatures++;
372
			}
373
			iterator.closeIterator();
374
			
375
			iterator = lyr.getSource().getFeatureIterator();
376
			while(iterator.hasNext()){
377
				feature = iterator.next();
378
				numFeatures++;
379
			}
380
			assertTrue(numFeatures2 > 0);
381
			assertTrue(numFeatures > numFeatures2);
382
			iterator.closeIterator();
383

  
384
			//pruebas con el driver dxf en vez del shp
385
			FLyrVect lyr3 = (FLyrVect) newLayer("es1120003_2_02.dxf", DXF_DRIVER_NAME);
386
			lyr3.setAvailable(true);
387
			iterator = lyr3.getSource().getFeatureIterator("select * from "+lyr3.getRecordset().getName()+" where ID > 17;", null);
388
			numFeatures2 = 0;
389
			while(iterator.hasNext()){
390
				feature = iterator.next();
391
				numFeatures2++;
392
			}
393
			iterator.closeIterator();
394
			assertTrue(numFeatures2 > 0);
395

  
396
			//queda por probar los iteradores contra base de datos
397
			//en base a criterios alfanumericos y espaciales
398

  
399
		} catch (LoadLayerException e) {
400
			// TODO Auto-generated catch block
401
			e.printStackTrace();
402
		} catch (ReadDriverException e) {
403
			// TODO Auto-generated catch block
404
			e.printStackTrace();
405
		} 
406
	}
407

  
408

  
409

  
410
//	public void test3(){
411
//		try {
412
//			FLyrVect layer = (FLyrVect) newLayer("poly-valencia.shp", SHP_DRIVER_NAME);
413
//			IFeatureIterator iterator = layer.getSource().getFeatureIterator();
414
//			int numFeatures = 0;
415
//			while(iterator.hasNext()){
416
//				iterator.next();
417
//				numFeatures++;
418
//			}
419
//			assert(layer.getSource().getShapeCount() == numFeatures);
420
//
421
//		} catch (LoadLayerException e) {
422
//			// TODO Auto-generated catch block
423
//			e.printStackTrace();
424
//		} catch (ReadDriverException e) {
425
//			// TODO Auto-generated catch block
426
//			e.printStackTrace();
427
//		} catch (ExpansionFileReadException e) {
428
//			// TODO Auto-generated catch block
429
//			e.printStackTrace();
430
//		}
431
//
432
//	}
433

  
434
	//test of featureIterator with layer poly-valencia using a spatial filter.
435
	//jaume found a bug with an infinite loop iteration
436

  
437
	public void test4(){
438
		try {
439
			FLyrVect layer = (FLyrVect) newLayer("poly-valencia.shp", SHP_DRIVER_NAME);
440
			Rectangle2D extent = layer.getFullExtent();
441
			String[] fields = layer.getRecordset().getFieldNames();
442

  
443

  
444
			IFeatureIterator iterator = layer.
445
							getSource().
446
							getFeatureIterator(extent,fields, null, true);
447
			int numFeatures = 0;
448
			while(iterator.hasNext()){
449
				iterator.next();
450
				numFeatures++;
451
			}
452
			iterator.closeIterator();
453
			assert(layer.getSource().getShapeCount() == numFeatures);
454

  
455
		} catch (LoadLayerException e) {
456
			// TODO Auto-generated catch block
457
			e.printStackTrace();
458
		} catch (ReadDriverException e) {
459
			// TODO Auto-generated catch block
460
			e.printStackTrace();
461
		}
462
	}
463

  
464

  
465

  
466

  
467

  
468
	public void test5(){
469
		try {
470
			int WIDTH = 300;
471
			int HEIGHT = 200;
472
			FLyrVect layer = (FLyrVect) newLayer("municipios.shp", SHP_DRIVER_NAME);
473
			ViewPort vp = new ViewPort(PROJECTION_DEFAULT);
474
			vp.setImageSize(new Dimension(WIDTH, HEIGHT));
475
			vp.setExtent(layer.getFullExtent());
476
			MapContext mapa = new MapContext(vp);
477
			mapa.getLayers().addLayer(layer);
478
			BufferedImage img = new BufferedImage(WIDTH, HEIGHT,
479
					BufferedImage.TYPE_INT_ARGB);
480

  
481
			long t0 = System.currentTimeMillis();
482
			mapa.draw(img, img.createGraphics(),mapa.getScaleView());
483
			long t1 = System.currentTimeMillis();
484
			System.out.println((t1-t0)+" en dibujar con MapContext.draw");
485

  
486

  
487
			long t2 = System.currentTimeMillis();
488
			layer.draw(img, img.createGraphics(),vp, new Cancellable(){
489
				public boolean isCanceled() {
490
					return false;
491
				}
492
				public void setCanceled(boolean canceled) {
493
				}}, getScaleView(vp));
494
			long t3 = System.currentTimeMillis();
495
			System.out.println((t3-t2)+" en dibujar con layer._draw");
496

  
497
		} catch (LoadLayerException e) {
498
			// TODO Auto-generated catch block
499
			e.printStackTrace();
500
		} catch (ReadDriverException e) {
501
			// TODO Auto-generated catch block
502
			e.printStackTrace();
503
		} 
504
	}
505

  
506

  
507

  
508

  
509

  
510
	//TODO Mover spatialindextest a esta clase
511
	public void test7(){
512

  
513
	}
514

  
515

  
516
	private long getScaleView(ViewPort viewPort) {
517
		double[] CHANGE = { 100000, 100, 1, 0.1, 160934.4,
518
				91.44, 30.48, 2.54, 1/8.983152841195214E-4 };
519
		Preferences prefsResolution = Preferences.userRoot().node( "gvsig.configuration.screen" );
520
		Toolkit kit = Toolkit.getDefaultToolkit();
521
		double dpi = prefsResolution.getInt("dpi",kit.getScreenResolution());
522
		IProjection proj = viewPort.getProjection();
523
		if (viewPort.getImageSize() == null)
524
			return -1;
525
		if (viewPort.getAdjustedExtent() == null) {
526
			return 0;
527
		}
528
		if (proj == null) {
529
			double w = ((viewPort.getImageSize().getWidth() / dpi) * 2.54);
530
			return (long) (viewPort.getAdjustedExtent().getWidth() / w * CHANGE[viewPort.getMapUnits()]);
531
		}
532

  
533
		return Math.round(proj.getScale(viewPort.getAdjustedExtent().getMinX(),
534
				viewPort.getAdjustedExtent().getMaxX(), viewPort.getImageSize()
535
						.getWidth(), dpi));
536
	}
537

  
538
}
539

  
0 540

  
branches/v2_0_0_prep/libraries/libFMap/src-test/org/gvsig/fmap/drivers/iterators/spatialindex/SpatialIndexTest.java
1
package org.gvsig.fmap.drivers.iterators.spatialindex;
2

  
3
import java.awt.geom.Point2D;
4
import java.awt.geom.Rectangle2D;
5
import java.io.File;
6
import java.net.URL;
7
import java.util.List;
8

  
9
import junit.framework.TestCase;
10

  
11
import org.cresques.cts.IProjection;
12
import org.gvsig.fmap.core.geometries.IGeometry;
13
import org.gvsig.fmap.crs.CRSFactory;
14
import org.gvsig.fmap.drivers.exceptions.ExpansionFileReadException;
15
import org.gvsig.fmap.drivers.exceptions.VisitorException;
16
import org.gvsig.fmap.drivers.iterators.spatialindex.PersistentRTreeJsi;
17
import org.gvsig.fmap.drivers.iterators.spatialindex.QuadtreeGt2;
18
import org.gvsig.fmap.drivers.iterators.spatialindex.SpatialIndexException;
19
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
20
import org.gvsig.fmap.mapcontext.layers.FBitSet;
21
import org.gvsig.fmap.mapcontext.layers.FLayer;
22
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
23
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
24

  
25
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
26

  
27
public class SpatialIndexTest extends TestCase {
28

  
29
	// TODO MOVER TODO LO ESTATICO A UNA CLASE AUXILIAR QUE NO SEA JUNIT
30

  
31
	String fwAndamiDriverPath = "../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers";
32

  
33
	File baseDataPath;
34

  
35
	File baseDriversPath;
36

  
37
	String SHP_DRIVER_NAME = "gvSIG shp driver";
38

  
39
	IProjection PROJECTION_DEFAULT = CRSFactory.getCRS("EPSG:23030");
40
	
41
	FLyrVect cantabria;
42
	FLyrVect edificaciones;
43

  
44
	public SpatialIndexTest(String name) {
45
		super(name);
46
	}
47

  
48
	protected void setUp() throws Exception {
49
		super.setUp();
50
		URL url = SpatialIndexTest.class.getResource("testdata");
51
		if (url == null)
52
			throw new Exception(
53
					"No se encuentra el directorio con datos de prueba");
54

  
55
		baseDataPath = new File(url.getFile());
56
		if (!baseDataPath.exists())
57
			throw new Exception(
58
					"No se encuentra el directorio con datos de prueba");
59

  
60
		baseDriversPath = new File(fwAndamiDriverPath);
61
		if (!baseDriversPath.exists())
62
			throw new Exception("Can't find drivers path: "
63
					+ fwAndamiDriverPath);
64

  
65
		LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath());
66
		if (LayerFactory.getDM().getDriverNames().length < 1)
67
			throw new Exception("Can't find drivers in path: "
68
					+ fwAndamiDriverPath);
69
		
70
		cantabria = (FLyrVect) newLayer("Cantabria.shp", SHP_DRIVER_NAME);
71
		edificaciones = (FLyrVect) newLayer("Edificaciones.shp", SHP_DRIVER_NAME);
72
		
73
	}
74

  
75
	public FLayer newLayer(String fileName, String driverName)
76
			throws LoadLayerException {
77
		File file = new File(baseDataPath, fileName);
78
		return LayerFactory.createLayer(fileName, driverName, file,
79
				PROJECTION_DEFAULT);
80
	}
81

  
82
	protected void tearDown() throws Exception {
83
		super.tearDown();
84
		PROJECTION_DEFAULT = null;
85
	}
86

  
87
	public void testSpatialIndexFullExtent() throws ReadDriverException,
88
			ExpansionFileReadException, VisitorException, LoadLayerException {
89
		
90
		Rectangle2D rect2D = cantabria.getFullExtent();
91
		FBitSet bitset = cantabria.queryByRect(rect2D);
92
		assertTrue(bitset.cardinality() != 0);
93

  
94
		double x = rect2D.getCenterX();
95
		double y = rect2D.getCenterY();
96
		rect2D = new Rectangle2D.Double(x, y, 100d, 100d);
97
		bitset = cantabria.queryByRect(rect2D);
98
		assertTrue(bitset.cardinality() != 0);
99
	}
100

  
101
	public void testPersistentRtreeJsi() throws LoadLayerException,
102
			ReadDriverException, ExpansionFileReadException,
103
			SpatialIndexException {
104
		try {
105
			PersistentRTreeJsi rtree = new PersistentRTreeJsi(baseDataPath
106
					.getAbsolutePath()
107
					+ "/Cantabria", true);
108
			
109

  
110
			int numShapes = cantabria.getSource().getShapeCount();
111
			for (int i = 0; i < numShapes; i++) {
112
				IGeometry g = cantabria.getSource().getShape(i);
113
				if (g == null)
114
					System.out.println("geometria a null");
115
				rtree.insert(g.getBounds2D(), i);
116
			}
117
			rtree.flush();
118

  
119
			rtree = null;
120

  
121
			rtree = new PersistentRTreeJsi(baseDataPath.getAbsolutePath()
122
					+ "/Cantabria", false);
123

  
124
			Rectangle2D rect2D = cantabria.getFullExtent();
125
			List results = rtree.query(rect2D);
126
			assertTrue(results.size() != 0);
127
			
128
		} catch (Exception e) {
129
			e.printStackTrace();
130
		}
131
	}
132
	
133
	public void testPerformanceRtreeJsiQuadtreeGt2() throws LoadLayerException, ExpansionFileReadException, SpatialIndexException, ReadDriverException {
134
		
135
		
136
		String fileName = baseDataPath.getAbsolutePath()
137
							+ "/Edificaciones.shp";
138
		long t0 = System.currentTimeMillis();
139
		QuadtreeGt2	spatialIndex = new QuadtreeGt2(fileName,
140
														"NM", 
141
										edificaciones.getSource().getFullExtent(),
142
										edificaciones.getSource().getShapeCount(), 
143
										true);
144
		int numShapes = edificaciones.getSource().getShapeCount();
145
		for (int i = 0; i < numShapes; i++) {
146
			IGeometry g = edificaciones.getSource().getShape(i);
147
			spatialIndex.insert(g.getBounds2D(), i);
148
		}
149
		spatialIndex.flush();
150
		long t1 = System.currentTimeMillis();
151
		System.out.println((t1-t0)+ " en generar Edificaciones.qix");
152
		
153
		t0 = System.currentTimeMillis();
154
		PersistentRTreeJsi rtree = new PersistentRTreeJsi(baseDataPath
155
				.getAbsolutePath()
156
				+ "/Edificaciones", true);
157
		numShapes = edificaciones.getSource().getShapeCount();
158
		for (int i = 0; i < numShapes; i++) {
159
			IGeometry g = edificaciones.getSource().getShape(i);
160
			rtree.insert(g.getBounds2D(), i);
161
		}
162
		t1 = System.currentTimeMillis();
163
		System.out.println((t1-t0)+" en generar Edificaciones.rix");
164
		rtree.flush();
165
		
166
		t0 = System.currentTimeMillis();
167
		spatialIndex = new QuadtreeGt2(fileName,
168
				"NM", 
169
				edificaciones.getSource().getFullExtent(),
170
				edificaciones.getSource().getShapeCount(), 
171
				false);
172
		t1 = System.currentTimeMillis();
173
		System.out.println((t1-t0)+" en cargar Edificaciones.qix");
174

  
175
		t0 = System.currentTimeMillis();
176
		rtree = new PersistentRTreeJsi(baseDataPath
177
				.getAbsolutePath()
178
				+ "/Edificaciones", false);
179
		t1 = System.currentTimeMillis();
180
		System.out.println((t1-t0)+" en cargar Edificaciones.rix");
181
		
182
		Rectangle2D rect2D = edificaciones.getFullExtent();
183
		
184
		t0 = System.currentTimeMillis();
185
		List results = rtree.query(rect2D);
186
		int nb1 = results.size();
187
		t1 = System.currentTimeMillis();
188
		System.out.println((t1-t0)+" en resolver query con RIX");
189
		System.out.println("encontrados "+nb1);
190
		t0 = System.currentTimeMillis();
191
		results = spatialIndex.query(rect2D);
192
		int nb2 = results.size();
193
		t1 = System.currentTimeMillis();
194
		System.out.println((t1-t0)+" en resolver query con QIX");
195
		System.out.println("encontrados "+nb2);
196
		
197
	}
198
	
199
	public void testNearestRectanglePoint() throws SpatialIndexException, ExpansionFileReadException, ReadDriverException{
200
		long t0 = System.currentTimeMillis();
201
		PersistentRTreeJsi rtree = new PersistentRTreeJsi(baseDataPath
202
				.getAbsolutePath()
203
				+ "/Edificaciones", false);
204
		long t1 = System.currentTimeMillis();
205
		
206
		System.out.println((t1-t0)+" en cargar Edificaciones.rix");
207
		
208
		Rectangle2D edifFullExtent = edificaciones.getFullExtent();
209
		double xc = edifFullExtent.getCenterX();
210
		double yc = edifFullExtent.getCenterY();
211
		double width = 200;
212
		int numberOfNearest = 20;
213
		Point2D p = new Point2D.Double(xc, yc);
214
		Rectangle2D query = new Rectangle2D.Double(xc, yc, width, width);
215
		
216
		t0 = System.currentTimeMillis();
217
		List solution = rtree.findNNearest(numberOfNearest, p);
218
		t1 = System.currentTimeMillis();
219
		
220
		System.out.println((t1-t0)+" en obtener los 20 mas cercanos al punto");
221
		
222
		assert(solution.size() > 0);
223
		
224
		t0 = System.currentTimeMillis();
225
		solution = rtree.findNNearest(numberOfNearest, query);
226
		t1 = System.currentTimeMillis();
227
		System.out.println((t1-t0)+" en obtener los 20 mas cercanos al rectangulo");
228
		assert(solution.size() > 0);
229
		
230
	}
231

  
232
}
0 233

  
branches/v2_0_0_prep/libraries/libFMap/src-test/org/gvsig/fmap/drivers/iterators/spatialindex/testdata/Edificaciones.prj
1
PROJCS["European 1950 Based UTM, Zone 30 North, Meter",GEOGCS["ERP50-W",DATUM["D_ERP50-W",SPHEROID["International_1924",6378388,297.0000000000601]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
0 2

  
branches/v2_0_0_prep/libraries/libFMap/src-test/org/gvsig/fmap/drivers/iterators/PerformanceFeatureIteratorTest.java
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$
47
* $Log$
48
* Revision 1.6  2007-09-20 08:08:29  jaume
49
* ReadExpansionFileException removed from this context
50
*
51
* Revision 1.5  2007/06/29 13:07:01  jaume
52
* +PictureLineSymbol
53
*
54
* Revision 1.4  2007/06/07 10:20:38  azabala
55
* includes closeIterator
56
*
57
* Revision 1.3  2007/06/07 09:31:42  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.2  2007/05/30 20:12:41  azabala
61
* fastIteration = true optimized.
62
*
63
* Revision 1.1  2007/05/29 19:11:03  azabala
64
* *** empty log message ***
65
*
66
*
67
*/
68
package org.gvsig.fmap.drivers.iterators;
69

  
70
import java.awt.geom.Rectangle2D;
71

  
72
import junit.framework.TestCase;
73

  
74
import org.cresques.cts.ICoordTrans;
75
import org.gvsig.fmap.core.features.IFeature;
76
import org.gvsig.fmap.drivers.exceptions.ExpansionFileReadException;
77
import org.gvsig.fmap.drivers.iterators.SpatialQueryFeatureIterator;
78
import org.gvsig.fmap.drivers.iterators.spatialindex.ISpatialIndex;
79
import org.gvsig.fmap.drivers.reading.IFeatureIterator;
80
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
81
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
82

  
83
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
84

  
85

  
86
/**
87
 * Tests to probe feature iteration methods.
88
 *
89
 * These test are not functional-test (performance).
90

  
91
 * @author azabala
92
 *
93
 */
94
public class PerformanceFeatureIteratorTest extends TestCase {
95

  
96
   static FLyrVect lyr;
97

  
98

  
99
	static{
100
			try {
101
				lyr = (FLyrVect) FeatureIteratorTest.newLayer("ejesc.shp",
102
										FeatureIteratorTest.SHP_DRIVER_NAME);
103
				lyr.setAvailable(true);
104
			} catch (LoadLayerException e) {
105
				// TODO Auto-generated catch block
106
				e.printStackTrace();
107
			}
108
	}
109

  
110
	public void test1() {
111
		try {
112
			//pruebas de iteracion espacial
113
			System.out.println("TEST 1: ESPACIAL CON FULL EXTENT Y REPROYECCI?N");
114
			Rectangle2D rect = lyr.getFullExtent();
115
			IFeature feature = null;
116
			//fast iteration
117
			long t0 = System.currentTimeMillis();
118
			ISpatialIndex spatialIndex = lyr.getSource().getSpatialIndex();
119
			lyr.getSource().setSpatialIndex(null);
120

  
121
			//Sin indice espacial, rapida
122
			//si pedimos reproyeccion, el rectangulo de consulta debe estar en la proyeccion
123
			//de destino
124
			ICoordTrans trans = FeatureIteratorTest.PROJECTION_DEFAULT.getCT(FeatureIteratorTest.newProjection);
125
			rect = trans.convert(rect);
126
			IFeatureIterator iterator = lyr.getSource().getFeatureIterator(rect,
127
															null,
128
															FeatureIteratorTest.newProjection,
129
															true);
130
			int numFeatures = 0;
131
			while(iterator.hasNext()){
132
				feature = iterator.next();
133
				numFeatures++;
134
			}
135
			long t1 = System.currentTimeMillis();
136
			iterator.closeIterator();
137
			//sin indice espacial, lenta
138
			iterator = lyr.getSource().getFeatureIterator(rect,
139
															null,
140
								FeatureIteratorTest.newProjection,
141
												false);
142
			int numFeatures2 = 0;
143
			while(iterator.hasNext()){
144
				feature = iterator.next();
145
				numFeatures2++;
146
			}
147
			long t2 = System.currentTimeMillis();
148
			iterator.closeIterator();
149
			lyr.getSource().setSpatialIndex(spatialIndex);
150
			long t3 = System.currentTimeMillis();
151

  
152
			//con indice espacial rapida
153
			iterator = lyr.getSource().getFeatureIterator(rect,
154
															null,
155
								FeatureIteratorTest.newProjection,
156
												true);
157
			int numFeatures3 = 0;
158
			while(iterator.hasNext()){
159
				feature = iterator.next();
160
				numFeatures3++;
161
			}
162
			long t4 = System.currentTimeMillis();
163
			iterator.closeIterator();
164
			//con indice espacial lenta
165
			iterator = lyr.getSource().getFeatureIterator(rect,
166
					null,
167
					FeatureIteratorTest.newProjection,
168
					false);
169
			int numFeatures4 = 0;
170
			while(iterator.hasNext()){
171
			feature = iterator.next();
172
			numFeatures4++;
173
			}
174
			long t5 = System.currentTimeMillis();
175
			iterator.closeIterator();
176

  
177
			System.out.println((t1-t0)+" en la iteracion rapida sin indice espacial");
178
			System.out.println("Recuperados "+numFeatures);
179
			System.out.println((t4-t3)+" en la iteracion rapida con indice espacial");
180
			System.out.println("Recuperados "+numFeatures3);
181
			System.out.println((t2-t1)+" en la iteracion lenta sin indice espacial");
182
			System.out.println("Recuperados "+numFeatures2);
183
			System.out.println((t5-t4)+" en la iteracion lenta con indice espacial");
184
			System.out.println("Recuperados "+numFeatures4);
185

  
186
		} catch (ReadDriverException e) {
187
			// TODO Auto-generated catch block
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff