001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.renderer.shape;
017:
018: import java.awt.Rectangle;
019: import java.io.IOException;
020:
021: import junit.framework.TestCase;
022:
023: import org.geotools.data.FeatureSource;
024: import org.geotools.data.shapefile.Lock;
025: import org.geotools.data.shapefile.ShapefileDataStore;
026: import org.geotools.data.shapefile.ShapefileRendererUtil;
027: import org.geotools.data.shapefile.indexed.ShapeFileIndexer;
028: import org.geotools.filter.IllegalFilterException;
029: import org.geotools.map.DefaultMapContext;
030: import org.geotools.map.MapContext;
031: import org.geotools.referencing.operation.transform.IdentityTransform;
032: import org.geotools.resources.TestData;
033: import org.geotools.styling.Style;
034:
035: import com.vividsolutions.jts.geom.Envelope;
036:
037: /**
038: *
039: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/shapefile-renderer/src/test/java/org/geotools/renderer/shape/IndexedRenderingTest_Disabled.java $
040: */
041: public class IndexedRenderingTest_Disabled extends TestCase {
042: private static final boolean INTERACTIVE = false;
043: private Lock lock = new Lock();
044:
045: protected void tearDown() {
046: try {
047: TestData.file(IndexedRenderingTest_Disabled.class,
048: "lakes.qix").delete();
049: } catch (IOException e) {
050: }
051:
052: try {
053: TestData.file(IndexedRenderingTest_Disabled.class,
054: "lakes.grx").delete();
055: } catch (IOException e) {
056: }
057:
058: try {
059: TestData.file(IndexedRenderingTest_Disabled.class,
060: "streams.qix").delete();
061: } catch (IOException e) {
062: }
063:
064: try {
065: TestData.file(IndexedRenderingTest_Disabled.class,
066: "streams.grx").delete();
067: } catch (IOException e) {
068: }
069: }
070:
071: public void testQuadTree() throws Exception {
072: ShapeFileIndexer indexer = new ShapeFileIndexer();
073: indexer.setIdxType(ShapeFileIndexer.QUADTREE);
074: indexer.setShapeFileName(TestData.file(
075: IndexedRenderingTest_Disabled.class, "lakes.shp")
076: .getPath());
077: indexer.index(true, lock);
078:
079: performRenderTest(IndexInfo.QUAD_TREE, TestUtilites
080: .getDataStore("lakes.shp").getFeatureSource(),
081: TestUtilites.createTestStyle("lakes", null), 100);
082: performRenderTest(IndexInfo.QUAD_TREE, TestUtilites
083: .getDataStore("lakes.shp").getFeatureSource(),
084: TestUtilites.createTestStyle("lakes", null),
085: new Envelope(553330.3289999997, 570423.7210000004,
086: 5233544.282249999, 5245830.157749998), 91);
087:
088: indexer.setShapeFileName(TestData.file(
089: IndexedRenderingTest_Disabled.class, "streams.shp")
090: .getPath());
091: indexer.index(true, lock);
092:
093: performRenderTest(IndexInfo.QUAD_TREE, TestUtilites
094: .getDataStore("streams.shp").getFeatureSource(),
095: TestUtilites.createTestStyle(null, "streams"), 116);
096:
097: performRenderTest(IndexInfo.QUAD_TREE, TestUtilites
098: .getDataStore("streams.shp").getFeatureSource(),
099: TestUtilites.createTestStyle(null, "streams"),
100: new Envelope(552383.9726608695, 569483.1330782612,
101: 5233875.318546738, 5246165.340096739), 97);
102: }
103:
104: private void performRenderTest(byte treeType, FeatureSource ds,
105: Style s, int expectedFeatures) throws IOException,
106: IllegalFilterException, Exception {
107: performRenderTest(treeType, ds, s, null, expectedFeatures);
108: }
109:
110: /**
111: * DOCUMENT ME!
112: *
113: * @param treeType DOCUMENT ME!
114: * @param ds DOCUMENT ME!
115: * @param s DOCUMENT ME!
116: * @param env DOCUMENT ME!
117: * @param expectedFeatures DOCUMENT ME!
118: *
119: * @throws IOException
120: * @throws IllegalFilterException
121: * @throws Exception
122: */
123: private void performRenderTest(byte treeType, FeatureSource ds,
124: Style s, Envelope env, int expectedFeatures)
125: throws IOException, IllegalFilterException, Exception {
126: MapContext map = new DefaultMapContext();
127: map.addLayer(ds, s);
128:
129: ShapefileRenderer renderer = new ShapefileRenderer(map);
130: assertEquals(treeType, renderer.layerIndexInfo[0].treeType);
131: map.setAreaOfInterest(map.getLayerBounds(), ds.getSchema()
132: .getDefaultGeometry().getCoordinateSystem());
133:
134: if (env == null) {
135: env = map.getLayerBounds();
136: env = new Envelope(env.getMinX(), env.getMaxX(), env
137: .getMinY(), env.getMaxY());
138: }
139:
140: IndexInfo.Reader reader = new IndexInfo.Reader(
141: renderer.layerIndexInfo[0], ShapefileRendererUtil
142: .getShpReader((ShapefileDataStore) ds
143: .getDataStore(), new Envelope(0, 0,
144: 100, 100),
145: new Rectangle(0, 0, 100, 100),
146: IdentityTransform.create(2), false,
147: false), new Envelope(
148: env.getMinX() + 10, env.getMaxX() - 10, env
149: .getMinY() + 10, env.getMaxY() - 10));
150: assertNotNull("Should find records", reader.goodRecs);
151: TestUtilites.INTERACTIVE = INTERACTIVE;
152: TestUtilites.showRender("testQuadTree", renderer, 1000, env,
153: expectedFeatures);
154: }
155: }
|