Search in sources :

Example 6 with ConstantFilter

use of org.polymap.core.style.model.feature.ConstantFilter in project polymap4-core by Polymap4.

the class FilterTest method visiblePoint.

@Test
public void visiblePoint() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    assertTrue(point.visibleIf.get() instanceof ConstantFilter);
    point.visibleIf.createValue(initializeFilter(ff.equals(ff.property("prop"), ff.literal("literal"))));
    point.diameter.createValue(ConstantNumber.defaults(23.0));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    org.geotools.styling.Style style = repo.serializedFeatureStyle(fs.id(), org.geotools.styling.Style.class).get();
    Rule rule = style.featureTypeStyles().get(0).rules().get(0);
    assertTrue(rule.getFilter() instanceof PropertyIsEqualTo);
    PropertyIsEqualTo filter = (PropertyIsEqualTo) rule.getFilter();
    assertTrue(filter.getExpression1() instanceof PropertyName);
    assertEquals("prop", ((PropertyName) filter.getExpression1()).getPropertyName());
    assertTrue(filter.getExpression2() instanceof Literal);
    assertEquals("literal", ((Literal) filter.getExpression2()).getValue());
    PointSymbolizer sym = (PointSymbolizer) rule.getSymbolizers()[0];
    assertEquals(SLDSerializer2.ff.literal(23.0), sym.getGraphic().getSize());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Literal(org.opengis.filter.expression.Literal) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) Rule(org.geotools.styling.Rule) Test(org.junit.Test)

Example 7 with ConstantFilter

use of org.polymap.core.style.model.feature.ConstantFilter in project polymap4-core by Polymap4.

the class StyleModelTest method testPolygon.

@Ignore
@Test
public void testPolygon() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PolygonStyle polygon = fs.members().createElement(PolygonStyle.defaults);
    assertTrue(polygon.visibleIf.get() instanceof ConstantFilter);
    polygon.fill.get().color.createValue(ConstantColor.defaults(1, 2, 3));
    polygon.stroke.get().color.createValue(ConstantColor.defaults(100, 100, 100));
    polygon.stroke.get().width.createValue(ConstantNumber.defaults(5.0));
    polygon.stroke.get().opacity.createValue(FilterMappedPrimitives.defaults()).add(ff.equals(ff.literal(1), ff.literal(1)), 0.1).add(ff.equals(ff.literal(2), ff.literal(2)), 0.2);
    polygon.stroke.get().strokeStyle.get().capStyle.createValue(ConstantStrokeCapStyle.defaults());
    polygon.stroke.get().strokeStyle.get().dashStyle.createValue(ConstantStrokeDashStyle.defaults());
    polygon.stroke.get().strokeStyle.get().joinStyle.createValue(ConstantStrokeJoinStyle.defaults());
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
}
Also used : ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with ConstantFilter

use of org.polymap.core.style.model.feature.ConstantFilter in project polymap4-core by Polymap4.

the class StyleModelTest method testSimplePolygon.

@Test
public void testSimplePolygon() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    PolygonStyle style = fs.members().createElement(PolygonStyle.defaults);
    assertTrue(style.visibleIf.get() instanceof ConstantFilter);
    style.fill.get().color.createValue(ConstantColor.defaults(0, 0, 0));
    style.fill.get().opacity.createValue(ConstantNumber.defaults(0.0));
    style.stroke.get().color.createValue(ConstantColor.defaults(100, 100, 100));
    style.stroke.get().width.createValue(ConstantNumber.defaults(5.0));
    style.stroke.get().opacity.createValue(ConstantNumber.defaults(0.5));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    Style result = repo.serializedFeatureStyle(fs.id(), Style.class).get();
    assertEquals(1, result.featureTypeStyles().size());
    FeatureTypeStyle fts = result.featureTypeStyles().get(0);
    assertEquals(1, fts.rules().size());
    Rule rule = fts.rules().get(0);
    assertEquals(0, rule.getMinScaleDenominator(), 0);
    assertEquals(Double.POSITIVE_INFINITY, rule.getMaxScaleDenominator(), 0);
    assertEquals(1, rule.symbolizers().size());
    assertNull(rule.getFilter());
    PolygonSymbolizer polygon = (PolygonSymbolizer) rule.symbolizers().get(0);
    assertEqualsLiteral(0.5, polygon.getStroke().getOpacity());
    assertEqualsLiteral(5.0, polygon.getStroke().getWidth());
    assertEqualsLiteral(0.0, polygon.getFill().getOpacity());
}
Also used : PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Style(org.geotools.styling.Style) ConstantStrokeDashStyle(org.polymap.core.style.model.feature.ConstantStrokeDashStyle) ConstantStrokeJoinStyle(org.polymap.core.style.model.feature.ConstantStrokeJoinStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) ConstantStrokeCapStyle(org.polymap.core.style.model.feature.ConstantStrokeCapStyle) StrokeDashStyle(org.polymap.core.style.model.feature.StrokeDashStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Aggregations

ConstantFilter (org.polymap.core.style.model.feature.ConstantFilter)8 Test (org.junit.Test)7 FeatureStyle (org.polymap.core.style.model.FeatureStyle)7 Rule (org.geotools.styling.Rule)6 PointStyle (org.polymap.core.style.model.feature.PointStyle)6 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 PolygonStyle (org.polymap.core.style.model.feature.PolygonStyle)5 PointSymbolizer (org.geotools.styling.PointSymbolizer)4 Style (org.geotools.styling.Style)4 ConstantStrokeCapStyle (org.polymap.core.style.model.feature.ConstantStrokeCapStyle)4 ConstantStrokeDashStyle (org.polymap.core.style.model.feature.ConstantStrokeDashStyle)4 ConstantStrokeJoinStyle (org.polymap.core.style.model.feature.ConstantStrokeJoinStyle)4 LineStyle (org.polymap.core.style.model.feature.LineStyle)4 StrokeDashStyle (org.polymap.core.style.model.feature.StrokeDashStyle)4 TextStyle (org.polymap.core.style.model.feature.TextStyle)4 Ignore (org.junit.Ignore)2 LineSymbolizer (org.geotools.styling.LineSymbolizer)1 Mark (org.geotools.styling.Mark)1 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)1 Symbolizer (org.geotools.styling.Symbolizer)1