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 PointLazySearchCollectionTest 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 PointLazySearchCollectionTest() throws IOException {
28: super ("LazySearchIteratorTest");
29: }
30:
31: protected void setUp() throws Exception {
32: super .setUp();
33: file = copyShapefiles("shapes/archsites.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(585000, 610000,
64: 4910000, 4930000, crs);
65: LazySearchCollection collection = new LazySearchCollection(
66: tree, env);
67: assertEquals(25, collection.size());
68: }
69:
70: public void testGetOneFeatures() throws Exception {
71: ReferencedEnvelope env = new ReferencedEnvelope(597867, 598068,
72: 4918863, 4919031, crs);
73: LazySearchCollection collection = new LazySearchCollection(
74: tree, env);
75: assertEquals(1, collection.size());
76:
77: }
78:
79: public void testGetNoFeatures() throws Exception {
80: ReferencedEnvelope env = new ReferencedEnvelope(592211, 597000,
81: 4910947, 4913500, crs);
82: LazySearchCollection collection = new LazySearchCollection(
83: tree, env);
84: assertEquals(0, collection.size());
85: }
86: }
|