Search in sources :

Example 21 with FilterFactory

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

the class ExpressionNodeTest method testSetExpression.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.expression.ExpressionNode#setExpression(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testSetExpression() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ExpressionNode node = new ExpressionNode();
    // Test literal expression
    String expressionString = "Literalexpression";
    Expression literal = ff.literal(expressionString);
    node.setExpression(literal);
    String expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.literal") + " " + expressionString;
    String actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test attribute expression
    String propertyName = "testproperty";
    Expression attribute = ff.property(propertyName);
    node.setExpression(attribute);
    expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.attribute") + " [" + attribute + "]";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test attribute expression
    literal = ff.literal(ff.property(propertyName));
    node.setExpression(literal);
    expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.attribute") + " [" + attribute + "]";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test math expression
    Expression maths = ff.multiply(ff.literal(6), ff.literal(7));
    node.setExpression(maths);
    expected = "*";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test function
    FunctionImpl function = new ConcatenateFunction();
    List<Expression> params = new ArrayList<Expression>();
    params.add(ff.literal("world"));
    params.add(ff.literal("dog"));
    function.setParameters(params);
    node.setExpression(function);
    expected = "Concatenate([world], [dog])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test function expression
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    String name = "strConcat";
    List<Expression> parameters = new ArrayList<Expression>();
    parameters.add(ff.literal("cat"));
    parameters.add(ff.literal("dog"));
    Function functionExpression = functionFactory.function(name, parameters, null);
    node.setExpression(functionExpression);
    expected = "strConcat([cat], [dog])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test environment function
    EnvFunction envExpression = (EnvFunction) ff.function("env", ff.literal("foo"), ff.literal(0));
    node.setExpression(envExpression);
    expected = "env([foo], [0])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
}
Also used : EnvFunction(org.geotools.filter.function.EnvFunction) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) Function(org.opengis.filter.expression.Function) EnvFunction(org.geotools.filter.function.EnvFunction) Expression(org.opengis.filter.expression.Expression) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) ExpressionNode(com.sldeditor.filter.v2.expression.ExpressionNode) FunctionImpl(org.geotools.filter.FunctionImpl) ArrayList(java.util.ArrayList) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 22 with FilterFactory

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

the class BatchUpdateFontModelTest method testLoadData.

/**
 * Test method for {@link com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel#loadData(java.util.List)}.
 */
@Test
public void testLoadData() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
    String sldContents = sldWriter.encodeSLD(null, sld);
    String expectedWorkspace = "workspace";
    String expectedStyle = "layer.sld";
    StyleWrapper styleWrapper = new StyleWrapper(expectedWorkspace, expectedStyle);
    SLDData data = new SLDData(styleWrapper, sldContents);
    File testFile = new File("test.sld");
    data.setSLDFile(testFile);
    SLDEditorFile.getInstance().setSldFile(testFile);
    SLDEditorFile.getInstance().setSLDData(data);
    BatchUpdateFontData testObj = new BatchUpdateFontData(sld, data);
    SelectedSymbol.getInstance().setSld(sld);
    testObj.setNamedLayer(expectedNamedLayer);
    testObj.setStyle(expectedStyleLayer);
    testObj.setFeatureTypeStyle(expectedFeatureTypeStyleLayer);
    testObj.setRule(rule);
    testObj.setSymbolizer(symbolizer);
    testObj.setFont(font);
    List<BatchUpdateFontData> dataList = new ArrayList<BatchUpdateFontData>();
    dataList.add(testObj);
    BatchUpdateFontModel model = new BatchUpdateFontModel();
    model.loadData(dataList);
    for (int col = 0; col < model.getColumnCount(); col++) {
        assertFalse(model.hasValueBeenUpdated(0, col));
    }
    assertFalse(model.anyChanges());
    assertFalse(model.saveData(null));
    List<Font> actualFontlist = model.getFontEntries(new int[] { 0 });
    assertEquals(1, actualFontlist.size());
    assertEquals(1, model.getRowCount());
    // Update font
    String originalFontname = "New Font";
    String originalFontStyle = "italic";
    String originalFontWeight = "bold";
    int originalFontSize = 16;
    font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
    model.applyData(new int[] { 0 }, font);
    assertTrue(model.hasValueBeenUpdated(0, 7));
    assertTrue(model.hasValueBeenUpdated(0, 8));
    assertTrue(model.hasValueBeenUpdated(0, 9));
    assertTrue(model.hasValueBeenUpdated(0, 10));
    assertTrue(model.anyChanges());
    assertEquals(originalFontname, model.getValueAt(0, 7));
    assertEquals(originalFontStyle, model.getValueAt(0, 8));
    assertEquals(originalFontWeight, model.getValueAt(0, 9));
    assertEquals(String.valueOf(originalFontSize), model.getValueAt(0, 10));
    model.revertData();
    assertFalse(model.anyChanges());
    int expectedFontSize = 99;
    model.applyData(new int[] { 0 }, expectedFontSize);
    // Font size
    assertTrue(model.hasValueBeenUpdated(0, 10));
    assertEquals(expectedWorkspace, model.getValueAt(0, 0));
    assertEquals(expectedStyle, model.getValueAt(0, 1));
    assertEquals(expectedNamedLayer, model.getValueAt(0, 2));
    assertEquals(expectedStyleLayer, model.getValueAt(0, 3));
    assertEquals(expectedFeatureTypeStyleLayer, model.getValueAt(0, 4));
    assertEquals(expectedRule, model.getValueAt(0, 5));
    assertEquals(expectedSymbolizer, model.getValueAt(0, 6));
    assertEquals("abc", model.getValueAt(0, 7));
    assertEquals("normal", model.getValueAt(0, 8));
    assertEquals("normal", model.getValueAt(0, 9));
    assertEquals(String.valueOf(10 + expectedFontSize), model.getValueAt(0, 10));
    assertNull(model.getValueAt(0, 42));
    assertTrue(model.saveData(null));
    SelectedSymbol.destroyInstance();
    SLDEditorFile.destroyInstance();
    model.setColumnRenderer(null);
    JTable table = new JTable();
    table.setModel(model);
    model.setColumnRenderer(table.getColumnModel());
    assertFalse(model.isCellEditable(0, 0));
    assertEquals(Localisation.getString(BatchUpdateFontModel.class, "BatchUpdateFontModel.workspace"), model.getColumnName(0));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) ArrayList(java.util.ArrayList) BatchUpdateFontModel(com.sldeditor.tool.batchupdatefont.BatchUpdateFontModel) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) StyleWrapper(com.sldeditor.common.data.StyleWrapper) JTable(javax.swing.JTable) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) Rule(org.geotools.styling.Rule) BatchUpdateFontData(com.sldeditor.tool.batchupdatefont.BatchUpdateFontData) NamedLayer(org.geotools.styling.NamedLayer) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.Test)

Example 23 with FilterFactory

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

the class ExpressionPanelv2Test method testExpressionPanelv2.

/**
 * Test method for {@link com.sldeditor.filter.v2.expression.ExpressionPanelv2#ExpressionPanelv2(java.util.List)}.
 */
@Test
public void testExpressionPanelv2() {
    TestExpressionPanelv2 testObj = new TestExpressionPanelv2(null);
    assertNull(testObj.getVendorOptionList());
    testObj.dataSourceAboutToUnloaded(null);
    testObj.populate((String) null);
    testObj.configure("title", String.class, false);
    testObj.testShowExpressionDialog(null, null);
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Expression expectedExpression = ff.add(ff.property("field"), ff.literal(42));
    testObj.populate(expectedExpression);
    testObj.testShowExpressionDialog(Integer.class, expectedExpression);
    assertEquals(testObj.getExpression().toString(), testObj.getExpressionString());
    testObj.dataApplied();
    testObj.testSelection();
}
Also used : Expression(org.opengis.filter.expression.Expression) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 24 with FilterFactory

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

the class FilterNodeTest method testSetFilter.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.expression.FilterNode#setFilter(org.opengis.filter.Filter, com.sldeditor.filter.v2.function.FilterConfigInterface)}.
 */
@Test
public void testSetFilter() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    FilterNode node = new FilterNode();
    // BinaryComparisonAbstract
    Filter filter = ff.greaterOrEqual(ff.literal(45), ff.literal(23));
    node.setFilter(filter, null);
    node.addFilter();
    String actual = node.toString();
    String expected = "Filter : " + Localisation.getString(ExpressionPanelv2.class, "FilterNode.filterNotSet");
    assertTrue(actual.compareTo(expected) == 0);
    assertEquals(filter, node.getFilter());
    FilterConfigInterface filterConfig = new IsGreaterThan();
    node.setFilter(filter, filterConfig);
    assertEquals(filterConfig, node.getFilterConfig());
    expected = "Filter : PropertyIsGreaterThan";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // PropertyIsLike
    filter = ff.like(ff.literal("abc def ghi"), "abc");
    filterConfig = new IsLike();
    node.setFilter(filter, filterConfig);
    expected = "Filter : Like";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // BinarySpatialOperator
    Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84);
    PositionFactory positionFactory = GeometryFactoryFinder.getPositionFactory(hints);
    GeometryFactory geometryFactory = GeometryFactoryFinder.getGeometryFactory(hints);
    PrimitiveFactory primitiveFactory = GeometryFactoryFinder.getPrimitiveFactory(hints);
    AggregateFactory aggregateFactory = GeometryFactoryFinder.getAggregateFactory(hints);
    WKTParser wktParser = new WKTParser(geometryFactory, primitiveFactory, positionFactory, aggregateFactory);
    Geometry geometry = null;
    try {
        geometry = wktParser.parse("POINT( 48.44 -123.37)");
    } catch (ParseException e) {
        e.printStackTrace();
        fail();
    }
    filter = ff.overlaps("property", geometry);
    filterConfig = new Overlaps();
    node.setFilter(filter, filterConfig);
    expected = "Filter : Overlaps";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Is Between
    filter = ff.between(ff.literal(25), ff.literal(5), ff.literal(50));
    filterConfig = new IsBetween();
    node.setFilter(filter, filterConfig);
    expected = "Filter : PropertyIsBetween";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Is Null
    filter = ff.isNull(ff.literal(12));
    filterConfig = new IsNull();
    node.setFilter(filter, filterConfig);
    expected = "Filter : IsNull";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // BinaryTemporalOperator
    filter = ff.after(ff.literal(12), ff.literal(312));
    filterConfig = new After();
    node.setFilter(filter, filterConfig);
    expected = "Filter : After";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Logic filter
    filter = ff.and(ff.after(ff.literal(12), ff.literal(312)), ff.between(ff.literal(25), ff.literal(5), ff.literal(50)));
    filterConfig = new And();
    node.setFilter(filter, filterConfig);
    expected = "Filter : And";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    node.addFilter();
}
Also used : ExpressionPanelv2(com.sldeditor.filter.v2.expression.ExpressionPanelv2) Overlaps(com.sldeditor.filter.v2.function.geometry.Overlaps) GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) Hints(org.geotools.factory.Hints) PositionFactory(org.opengis.geometry.PositionFactory) FilterNode(com.sldeditor.filter.v2.expression.FilterNode) IsBetween(com.sldeditor.filter.v2.function.property.IsBetween) FilterConfigInterface(com.sldeditor.filter.v2.function.FilterConfigInterface) IsGreaterThan(com.sldeditor.filter.v2.function.property.IsGreaterThan) WKTParser(org.geotools.geometry.text.WKTParser) IsLike(com.sldeditor.filter.v2.function.misc.IsLike) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory) FilterFactory(org.opengis.filter.FilterFactory) Geometry(org.opengis.geometry.Geometry) Filter(org.opengis.filter.Filter) And(com.sldeditor.filter.v2.function.logic.And) After(com.sldeditor.filter.v2.function.temporal.After) IsNull(com.sldeditor.filter.v2.function.misc.IsNull) AggregateFactory(org.opengis.geometry.aggregate.AggregateFactory) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 25 with FilterFactory

use of org.opengis.filter.FilterFactory in project incubator-rya by apache.

the class GeoMesaGeoIndexer method deleteStatements.

private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
    // create a feature collection
    final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    for (final RyaStatement ryaStatement : ryaStatements) {
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        // if the predicate list is empty, accept all predicates.
        // Otherwise, make sure the predicate is on the "valid" list
        final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
        if (isValidPredicate && (statement.getObject() instanceof Literal)) {
            try {
                final SimpleFeature feature = createFeature(featureType, statement);
                featureCollection.add(feature);
            } catch (final ParseException e) {
                logger.warn("Error getting geo from statement: " + statement.toString(), e);
            }
        }
    }
    // remove this feature collection from the store
    if (!featureCollection.isEmpty()) {
        final Set<Identifier> featureIds = new HashSet<Identifier>();
        final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
        final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
        for (final String id : stringIds) {
            featureIds.add(filterFactory.featureId(id));
        }
        final Filter filter = filterFactory.id(featureIds);
        featureStore.removeFeatures(filter);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Identifier(org.opengis.filter.identity.Identifier) Filter(org.opengis.filter.Filter) Literal(org.openrdf.model.Literal) ParseException(com.vividsolutions.jts.io.ParseException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashSet(java.util.HashSet)

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