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;
}
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());
}
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);
}
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;
}
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;
}
Aggregations