01: package org.geotools.data.ogr;
02:
03: import java.io.IOException;
04: import java.net.URL;
05:
06: import org.geotools.TestData;
07: import org.geotools.data.DefaultQuery;
08: import org.geotools.data.FeatureReader;
09: import org.geotools.data.Query;
10: import org.geotools.data.Transaction;
11: import org.geotools.data.shapefile.ShapefileDataStore;
12: import org.geotools.feature.AttributeTypeFactory;
13: import org.geotools.referencing.CRS;
14:
15: public class OGRPeformanceTest extends TestCaseSupport {
16: final static String STATE_POP = "shapes/statepop.shp";
17:
18: public OGRPeformanceTest(String name) throws IOException {
19: super (name);
20: }
21:
22: protected void setUp() throws Exception {
23: super .setUp();
24: AttributeTypeFactory.newAttributeType("Gimbo", String.class,
25: true, 200, "AAA");
26: CRS.decode("EPSG:4326");
27: }
28:
29: public void testShapefilePerformance() throws Exception {
30: URL url = TestData.url(STATE_POP);
31: ShapefileDataStore sds = new ShapefileDataStore(url);
32: long start = System.currentTimeMillis();
33: sds.getSchema();
34: long end = System.currentTimeMillis();
35: System.out.println("SDS schema: " + (end - start) / 1000.0);
36:
37: DefaultQuery query = new DefaultQuery(sds.getTypeNames()[0]);
38: start = System.currentTimeMillis();
39: FeatureReader sfr = sds.getFeatureReader(query,
40: Transaction.AUTO_COMMIT);
41: while (sfr.hasNext())
42: sfr.next();
43: sfr.close();
44: end = System.currentTimeMillis();
45: System.out.println("SDS: " + (end - start) / 1000.0);
46:
47: System.out.println("Attribute count: "
48: + sds.getSchema().getAttributeCount());
49: System.out.println("Feature count: "
50: + sds.getFeatureSource(sds.getSchema().getTypeName())
51: .getCount(Query.ALL));
52: }
53:
54: public void testOGRShapePerformance() throws Exception {
55: OGRDataStore ods = new OGRDataStore(getAbsolutePath(STATE_POP),
56: null, null);
57: long start = System.currentTimeMillis();
58: ods.getSchema(ods.getTypeNames()[0]);
59: long end = System.currentTimeMillis();
60: System.out.println("OGR schema: " + (end - start) / 1000.0);
61: DefaultQuery query = new DefaultQuery(ods.getTypeNames()[0]);
62: start = System.currentTimeMillis();
63: FeatureReader ofr = ods.getFeatureReader(query,
64: Transaction.AUTO_COMMIT);
65: while (ofr.hasNext())
66: ofr.next();
67: ofr.close();
68: end = System.currentTimeMillis();
69: System.out.println("OGR: " + (end - start) / 1000.0);
70: }
71:
72: }
|