Search in sources :

Example 61 with FilterFactory

use of org.opengis.filter.FilterFactory in project sldeditor by robward-scisys.

the class VOGeoServerContrastEnhancementNormalizeBlueTest method createChannelSelectionError.

/**
 * Creates the channel selection error object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelectionError(StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("TestStretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1.0"));
    options.put("maxValue", ff.literal("5.0"));
    SelectedChannelType channelType = styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
Also used : SelectedChannelType(org.geotools.styling.SelectedChannelType) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) Expression(org.opengis.filter.expression.Expression) ChannelSelection(org.geotools.styling.ChannelSelection) FilterFactory(org.opengis.filter.FilterFactory)

Example 62 with FilterFactory

use of org.opengis.filter.FilterFactory in project sldeditor by robward-scisys.

the class FieldConfigBaseTest method testPopulateExpressionExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression, org.opengis.filter.expression.Expression)}.
 */
@Test
public void testPopulateExpressionExpression() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false));
    AttributeSelection attributeSelectionPanel = AttributeSelection.createAttributes(String.class, field, false);
    field.testAttributeSelectionPanel(attributeSelectionPanel);
    TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
    field.addDataChangedListener(listener);
    assertFalse(listener.hasBeenCalled());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    // Test function
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    FunctionName functionName = null;
    for (FunctionName func : functionFactory.getFunctionNames()) {
        if (func.getName() == "greaterThan") {
            functionName = func;
            break;
        }
    }
    assertNotNull(functionName);
    Expression testExpression = ff.function(functionName.getFunctionName(), ff.literal(1), ff.literal(2));
    field.populate(testExpression);
    // Updated because the attribute pulldown changed
    assertTrue(listener.hasBeenCalled());
    assertEquals(ExpressionTypeEnum.E_EXPRESSION, field.getExpressionType());
    Expression expression = field.getExpression();
    assertTrue(expression.toString().startsWith(functionName.getName()));
    // Attribute expression wrapped in a literal expression
    String testAttributeName = "test attribute";
    NameImpl name = new NameImpl(testAttributeName);
    AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl(name);
    Expression literalExpression = ff.literal(attributeExpression);
    field.populate(literalExpression);
    assertEquals(ExpressionTypeEnum.E_ATTRIBUTE, field.getExpressionType());
// Process Function
// ProcessFunctionFactory factory = new ProcessFunctionFactory();
// FunctionTableModel functionParameterTableModel = new FunctionTableModel();
// ProcessFunction processFunction = functionParameterTableModel.getExpression(factory);
// field.populate(processFunction);
// assertEquals(ExpressionTypeEnum.E_VALUE, field.getExpressionType());
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) NameImpl(org.geotools.feature.NameImpl) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) AttributeSelection(com.sldeditor.ui.attribute.AttributeSelection) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 63 with FilterFactory

use of org.opengis.filter.FilterFactory in project sldeditor by robward-scisys.

the class FieldConfigColourTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#generateExpression()}. Test method
 * for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#getColourExpression()}. Test method
 * for {@link com.sldeditor.ui.detail.config.FieldConfigColour#getColourOpacityExpression()}.
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigColour#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    class TestFieldConfigColour extends FieldConfigColour {

        public TestFieldConfigColour(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigColour field = new TestFieldConfigColour(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    Expression actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateExpression(null);
    assertNull(field.getColourExpression());
    assertNull(field.getColourOpacityExpression());
    // Try string values - erroneous
    field.createUI();
    field.populateExpression("");
    String actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo("#000000") == 0);
    String colour1 = "#123456";
    field.populateExpression(colour1);
    actualValue = field.getStringValue();
    assertTrue(colour1.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour1) == 0);
    String colour2 = "#AABBCC";
    field.setTestValue(FieldIdEnum.UNKNOWN, colour2);
    actualValue = field.getStringValue();
    assertTrue(colour2.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour2) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    LiteralExpressionImpl literal = (LiteralExpressionImpl) actualExpression;
    double opacity = (Double) literal.getValue();
    double expectedOpacity = 1.0;
    assertTrue(Math.abs(opacity - expectedOpacity) < 0.0001);
    // Try using FieldConfigBase.populate(colour expression, opacity)
    String colour3 = "#001122";
    expectedOpacity = DefaultSymbols.defaultColourOpacity();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    field.populate(ff.literal(colour3));
    actualValue = field.getStringValue();
    assertTrue(colour3.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour3) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    literal = (LiteralExpressionImpl) actualExpression;
    opacity = (Double) literal.getValue();
    assertTrue(Math.abs(opacity - expectedOpacity) < 0.1);
    AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl("colour");
    field.populate(attributeExpression);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof AttributeExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 64 with FilterFactory

use of org.opengis.filter.FilterFactory in project sldeditor by robward-scisys.

the class VOGeoServerContrastEnhancementNormalizeGreenTest method createChannelSelection.

/**
 * Creates the channel selection object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelection(StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("StretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1"));
    options.put("maxValue", ff.literal("5"));
    SelectedChannelType channelType = styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
Also used : SelectedChannelType(org.geotools.styling.SelectedChannelType) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) Expression(org.opengis.filter.expression.Expression) ChannelSelection(org.geotools.styling.ChannelSelection) FilterFactory(org.opengis.filter.FilterFactory)

Example 65 with FilterFactory

use of org.opengis.filter.FilterFactory in project sldeditor by robward-scisys.

the class VOGeoServerContrastEnhancementNormalizeGreenTest method createChannelSelectionError.

/**
 * Creates the channel selection error object.
 *
 * @param styleFactory the style factory
 * @param contrastMethod the contrast method
 * @return the channel selection
 */
private ChannelSelection createChannelSelectionError(StyleFactoryImpl styleFactory, ContrastMethod contrastMethod) {
    ContrastEnhancement contrastEnhancement = (ContrastEnhancement) styleFactory.contrastEnhancement(null, contrastMethod.name());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Map<String, Expression> options = contrastEnhancement.getOptions();
    options.put("algorithm", ff.literal("TestStretchToMinimumMaximum"));
    options.put("minValue", ff.literal("1.0"));
    options.put("maxValue", ff.literal("5.0"));
    SelectedChannelType channelType = styleFactory.createSelectedChannelType("channel name", contrastEnhancement);
    SelectedChannelType[] channels = new SelectedChannelType[3];
    channels[0] = channelType;
    channels[1] = channelType;
    channels[2] = channelType;
    ChannelSelection channelSelection = styleFactory.createChannelSelection(channels);
    return channelSelection;
}
Also used : SelectedChannelType(org.geotools.styling.SelectedChannelType) ContrastEnhancement(org.geotools.styling.ContrastEnhancement) Expression(org.opengis.filter.expression.Expression) ChannelSelection(org.geotools.styling.ChannelSelection) FilterFactory(org.opengis.filter.FilterFactory)

Aggregations

FilterFactory (org.opengis.filter.FilterFactory)88 Test (org.junit.Test)72 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)42 Filter (org.opengis.filter.Filter)38 QueryImpl (ddf.catalog.operation.impl.QueryImpl)33 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)30 Expression (org.opengis.filter.expression.Expression)24 SourceResponse (ddf.catalog.operation.SourceResponse)21 ArrayList (java.util.ArrayList)18 Metacard (ddf.catalog.data.Metacard)17 SolrProviderTest (ddf.catalog.source.solr.SolrProviderTest)17 ContrastEnhancement (org.geotools.styling.ContrastEnhancement)12 SelectedChannelType (org.geotools.styling.SelectedChannelType)12 Date (java.util.Date)11 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)11 ChannelSelection (org.geotools.styling.ChannelSelection)10 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)8 Result (ddf.catalog.data.Result)8 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 QueryResponse (ddf.catalog.operation.QueryResponse)8