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: */
017: package org.geotools.renderer.shape;
018:
019: import java.io.IOException;
020:
021: import junit.framework.TestCase;
022:
023: import org.geotools.data.FeatureSource;
024: import org.geotools.data.shapefile.ShapefileDataStore;
025: import org.geotools.map.DefaultMapContext;
026: import org.geotools.map.MapContext;
027: import org.geotools.resources.TestData;
028: import org.geotools.styling.SLDParser;
029: import org.geotools.styling.Style;
030: import org.geotools.styling.StyleFactory;
031: import org.geotools.styling.StyleFactoryFinder;
032:
033: import com.vividsolutions.jts.geom.Envelope;
034:
035: /**
036: * Tests the LiteRenderer labelling algorithms
037: *
038: * @author jeichar
039: *
040: * @since 0.9.0
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/shapefile-renderer/src/test/java/org/geotools/renderer/shape/LabelingTest.java $
042: */
043: public class LabelingTest extends TestCase {
044: private static final int CENTERX = 160;
045: private static final int CENTERY = 40;
046: private static final boolean INTERACTIVE = false;
047: private long timout = 1000;
048:
049: static Style loadStyle(String sldFilename) throws IOException {
050: StyleFactory factory = StyleFactoryFinder.createStyleFactory();
051:
052: java.net.URL surl = TestData.getResource(LabelingTest.class,
053: sldFilename);
054: SLDParser stylereader = new SLDParser(factory, surl);
055:
056: Style style = stylereader.readXML()[0];
057:
058: return style;
059: }
060:
061: public void testLineLabeling() throws Exception {
062: ShapefileDataStore ds = (ShapefileDataStore) TestUtilites
063: .getDataStore("theme1.shp");
064: Style style = loadStyle("LineStyle.sld");
065: assertNotNull(style);
066:
067: MapContext map = new DefaultMapContext();
068: map.addLayer(ds.getFeatureSource(), style);
069:
070: ShapefileRenderer renderer = new ShapefileRenderer(map);
071: Envelope env = map.getLayerBounds();
072: int boundary = 10;
073: TestUtilites.INTERACTIVE = INTERACTIVE;
074: env = new Envelope(env.getMinX() - boundary, env.getMaxX()
075: + boundary, env.getMinY() - boundary, env.getMaxY()
076: + boundary);
077: TestUtilites.showRender("testLineLabeling", renderer, timout,
078: env);
079: }
080:
081: public void testPolyLabeling() throws Exception {
082: ShapefileDataStore ds = (ShapefileDataStore) TestUtilites
083: .getDataStore("smallMultiPoly.shp");
084:
085: Style style = loadStyle("PolyStyle.sld");
086: assertNotNull(style);
087:
088: MapContext map = new DefaultMapContext();
089: map.addLayer(ds.getFeatureSource(), style);
090:
091: ShapefileRenderer renderer = new ShapefileRenderer(map);
092: Envelope env = map.getLayerBounds();
093: int boundary = 1;
094: env = new Envelope(env.getMinX() - boundary, env.getMaxX()
095: + boundary, env.getMinY() - boundary, env.getMaxY()
096: + boundary);
097: TestUtilites.INTERACTIVE = INTERACTIVE;
098: TestUtilites.showRender("testPolyLabeling", renderer, timout,
099: env);
100: }
101:
102: public void testPolyLabelingZoomedOut() throws Exception {
103: ShapefileDataStore ds = (ShapefileDataStore) TestUtilites
104: .getDataStore("smallMultiPoly.shp");
105: FeatureSource source = ds
106: .getFeatureSource(ds.getTypeNames()[0]);
107:
108: Style style = loadStyle("PolyStyle.sld");
109: assertNotNull(style);
110:
111: MapContext map = new DefaultMapContext();
112: map.addLayer(ds.getFeatureSource(), style);
113:
114: ShapefileRenderer renderer = new ShapefileRenderer(map);
115: Envelope env = map.getLayerBounds();
116: int boundary = 30;
117: env = new Envelope(env.getMinX() - boundary, env.getMaxX()
118: + boundary, env.getMinY() - boundary, env.getMaxY()
119: + boundary);
120: TestUtilites.INTERACTIVE = INTERACTIVE;
121: TestUtilites.showRender("testPolyLabeling", renderer, timout,
122: env);
123: }
124: }
|