01: package org.geotools.index.quadtree;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05: import java.io.IOException;
06: import java.nio.channels.FileChannel;
07: import java.util.Iterator;
08:
09: import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore;
10: import org.geotools.data.shapefile.indexed.TestCaseSupport;
11: import org.geotools.data.shapefile.shp.IndexFile;
12: import org.geotools.geometry.jts.ReferencedEnvelope;
13: import org.geotools.index.quadtree.fs.FileSystemIndexStore;
14: import org.opengis.referencing.crs.CoordinateReferenceSystem;
15:
16: /**
17: * @author Jesse
18: */
19: public class PolygonLazySearchCollectionTest extends TestCaseSupport {
20:
21: private File file;
22: private IndexedShapefileDataStore ds;
23: private QuadTree tree;
24: private Iterator iterator;
25: private CoordinateReferenceSystem crs;
26:
27: public PolygonLazySearchCollectionTest() throws IOException {
28: super ("LazySearchIteratorTest");
29: }
30:
31: protected void setUp() throws Exception {
32: super .setUp();
33: file = copyShapefiles("shapes/statepop.shp");
34: ds = new IndexedShapefileDataStore(file.toURL());
35: ds.buildQuadTree(0);
36: tree = openQuadTree();
37: crs = ds.getSchema().getDefaultGeometry().getCoordinateSystem();
38: }
39:
40: private QuadTree openQuadTree() throws StoreException {
41: FileSystemIndexStore store = new FileSystemIndexStore(sibling(
42: file, "qix"));
43: try {
44:
45: FileInputStream in = new FileInputStream(sibling(file,
46: "shx"));
47: FileChannel channel = in.getChannel();
48: return store.load(new IndexFile(channel));
49: } catch (IOException e) {
50: throw new StoreException(e);
51: }
52: }
53:
54: protected void tearDown() throws Exception {
55: if (iterator != null)
56: tree.close(iterator);
57: tree.close();
58: super .tearDown();
59: file.getParentFile().delete();
60: }
61:
62: public void testGetAllFeatures() throws Exception {
63: ReferencedEnvelope env = new ReferencedEnvelope(-125.5, -66,
64: 23.6, 53.0, crs);
65: LazySearchCollection collection = new LazySearchCollection(
66: tree, env);
67: assertEquals(49, collection.size());
68: }
69:
70: public void testGetOneFeatures() throws Exception {
71: ReferencedEnvelope env = new ReferencedEnvelope(-70, -68.2,
72: 44.5, 45.7, crs);
73: LazySearchCollection collection = new LazySearchCollection(
74: tree, env);
75: assertEquals(10, collection.size());
76:
77: }
78:
79: public void testGetNoFeatures() throws Exception {
80: ReferencedEnvelope env = new ReferencedEnvelope(0, 10, 0, 10,
81: crs);
82: LazySearchCollection collection = new LazySearchCollection(
83: tree, env);
84: assertEquals(0, collection.size());
85: }
86: }
|