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.brewer.color;
017:
018: import java.awt.Color;
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023: import org.geotools.data.DataStore;
024: import org.geotools.data.DataTestCase;
025: import org.geotools.data.DefaultQuery;
026: import org.geotools.data.jdbc.JDBCFeatureSource;
027: import org.geotools.data.postgis.PostgisDataStoreFactory;
028: import org.geotools.data.postgis.collection.PostgisFeatureCollection;
029: import org.geotools.filter.AttributeExpression;
030: import org.geotools.filter.FilterFactory;
031: import org.geotools.filter.FilterFactoryFinder;
032: import org.geotools.filter.function.ClassificationFunction;
033: import org.geotools.filter.function.Classifier;
034: import org.geotools.filter.function.ExplicitClassifier;
035: import org.geotools.filter.function.UniqueIntervalFunction;
036: import org.geotools.styling.FeatureTypeStyle;
037:
038: /**
039: *
040: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/brewer/src/test/java/org/geotools/brewer/color/StyleGeneratorOnlineTest.java $
041: */
042: public class StyleGeneratorOnlineTest extends DataTestCase {
043: static boolean WKB_ENABLED = true;
044: static boolean CHECK_TYPE = false;
045: PostgisTests.Fixture f;
046: DataStore data;
047: Map remote;
048: PostgisFeatureCollection fc;
049:
050: public StyleGeneratorOnlineTest(String arg0) {
051: super (arg0);
052: }
053:
054: public String getFixtureFile() {
055: return "fixture.properties";
056: }
057:
058: protected void setUp() throws Exception {
059: super .setUp();
060:
061: f = PostgisTests.newFixture(getFixtureFile());
062:
063: remote = new HashMap();
064: remote.put("dbtype", "postgis");
065: remote.put("charset", "");
066: remote.put("host", f.host);
067: remote.put("port", f.port);
068: remote.put("database", f.database);
069: remote.put("user", f.user);
070: remote.put("passwd", f.password);
071: remote.put("namespace", f.namespace);
072:
073: PostgisDataStoreFactory pdsf = new PostgisDataStoreFactory();
074: data = pdsf.createDataStore(remote);
075:
076: JDBCFeatureSource featureSource = (JDBCFeatureSource) data
077: .getFeatureSource("bc_hospitals");
078: fc = new PostgisFeatureCollection(featureSource,
079: DefaultQuery.ALL);
080: }
081:
082: protected void tearDown() throws Exception {
083: fc = null;
084: data = null;
085: super .tearDown();
086: }
087:
088: /**
089: * Simple test to ensure unique interval function works on real data
090: * containing nulls.
091: *
092: * @throws Exception
093: */
094: public void testUniqueInterval() throws Exception {
095: ColorBrewer brewer = new ColorBrewer();
096: brewer.loadPalettes();
097:
098: FilterFactory ff = FilterFactoryFinder.createFilterFactory();
099: AttributeExpression expr = ff
100: .createAttributeExpression("authority");
101:
102: String paletteName = "YlGn";
103:
104: //create the classification function
105: ClassificationFunction function = new UniqueIntervalFunction();
106: List params = new ArrayList();
107: params.add(0, expr); //expression
108: params.add(1, ff.literal(7)); //classes
109: function.setParameters(params);
110:
111: Object object = function.evaluate(fc);
112: assertTrue(object instanceof ExplicitClassifier);
113:
114: Classifier classifier = (Classifier) object;
115:
116: Color[] colors = brewer.getPalette(paletteName).getColors(7);
117:
118: //get the fts
119: FeatureTypeStyle fts = StyleGenerator.createFeatureTypeStyle(
120: classifier, expr, colors, "myfts", roadFeatures[0]
121: .getFeatureType().getDefaultGeometry(),
122: StyleGenerator.ELSEMODE_IGNORE, 0.5, null);
123: assertNotNull(fts);
124: }
125: }
|