Search in sources :

Example 51 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class PrepareStyleVisitor method visit.

@Override
public Object visit(PolygonSymbolizer ps, Object o) {
    Displacement disp = ps.getDisplacement();
    Fill fill = ps.getFill();
    Expression offset = ps.getPerpendicularOffset();
    Stroke stroke = ps.getStroke();
    if (disp != null) {
        disp = (Displacement) disp.accept(this, o);
    }
    if (fill != null) {
        fill = (Fill) fill.accept(this, o);
    }
    if (offset != null) {
        offset = (Expression) visit(offset);
    }
    if (stroke != null) {
        stroke = (Stroke) stroke.accept(this, o);
    }
    // recreate symbolizer
    return SF.polygonSymbolizer(ps.getName(), visitGeometryExpression(ps, o), ps.getDescription(), ps.getUnitOfMeasure(), stroke, fill, disp, offset);
}
Also used : GraphicFill(org.opengis.style.GraphicFill) Fill(org.opengis.style.Fill) Stroke(org.opengis.style.Stroke) GraphicStroke(org.opengis.style.GraphicStroke) Expression(org.opengis.filter.Expression) Displacement(org.opengis.style.Displacement)

Example 52 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class PrepareStyleVisitor method visit.

@Override
public Object visit(LineSymbolizer ls, Object o) {
    Expression offset = ls.getPerpendicularOffset();
    Stroke stroke = ls.getStroke();
    if (offset != null) {
        visit(offset);
    }
    if (stroke != null) {
        stroke = (Stroke) stroke.accept(this, o);
    }
    // recreate symbolizer
    return SF.lineSymbolizer(ls.getName(), visitGeometryExpression(ls, o), ls.getDescription(), ls.getUnitOfMeasure(), stroke, offset);
}
Also used : Stroke(org.opengis.style.Stroke) GraphicStroke(org.opengis.style.GraphicStroke) Expression(org.opengis.filter.Expression)

Example 53 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class InterpolateTest method interpolate.

@Test
public void interpolate() {
    final String attribut = "att_value";
    final FilterFactory ff = FilterUtilities.FF;
    final MutableStyleFactory sf = new DefaultStyleFactory();
    final FeatureTypeBuilder sftb = new FeatureTypeBuilder();
    sftb.setName("test");
    sftb.addAttribute(Double.class).setName(attribut);
    final FeatureType sft = sftb.build();
    final Feature f1 = sft.newInstance();
    f1.setPropertyValue(attribut, 0d);
    final Feature f2 = sft.newInstance();
    f2.setPropertyValue(attribut, 5d);
    final Feature f3 = sft.newInstance();
    f3.setPropertyValue(attribut, 10d);
    final Feature f4 = sft.newInstance();
    f4.setPropertyValue(attribut, 15d);
    final Expression Lookup = ff.property(attribut);
    final List<InterpolationPoint> values = new ArrayList<>();
    // test color interpolation ---------------------------------------------
    values.clear();
    values.add(new DefaultInterpolationPoint(0d, ff.literal(BLACK)));
    values.add(new DefaultInterpolationPoint(10d, ff.literal(RED)));
    values.add(new DefaultInterpolationPoint(20d, ff.literal(BLUE)));
    Interpolate interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
    Color c = (Color) interpolate.apply(f1);
    assertEquals(c, BLACK);
    c = (Color) interpolate.apply(f2);
    assertEquals(c.getAlpha(), 255);
    assertEquals(c.getRed(), 127);
    assertEquals(c.getGreen(), 0);
    assertEquals(c.getBlue(), 0);
    c = (Color) interpolate.apply(f3);
    assertEquals(c, RED);
    // test color interpolation ---------------------------------------------
    values.clear();
    values.add(new DefaultInterpolationPoint(0d, sf.literal(BLACK)));
    values.add(new DefaultInterpolationPoint(10d, sf.literal(RED)));
    values.add(new DefaultInterpolationPoint(20d, sf.literal(BLUE)));
    interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
    c = (Color) interpolate.apply(f1);
    assertEquals(c, BLACK);
    c = (Color) interpolate.apply(f2);
    assertEquals(c.getAlpha(), 255);
    assertEquals(c.getRed(), 127);
    assertEquals(c.getGreen(), 0);
    assertEquals(c.getBlue(), 0);
    c = (Color) interpolate.apply(f3);
    assertEquals(c, RED);
    // test number interpolation --------------------------------------------
    values.clear();
    values.add(new DefaultInterpolationPoint(0d, ff.literal(0d)));
    values.add(new DefaultInterpolationPoint(10d, ff.literal(100d)));
    values.add(new DefaultInterpolationPoint(20d, ff.literal(50d)));
    interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
    Double d = (Double) interpolate.apply(f1);
    assertEquals(d.doubleValue(), 0d, 0d);
    d = (Double) interpolate.apply(f2);
    assertEquals(d.doubleValue(), 50d, 0d);
    d = (Double) interpolate.apply(f3);
    assertEquals(d.doubleValue(), 100d, 0d);
    d = (Double) interpolate.apply(f4);
    assertEquals(d.doubleValue(), 75d, 0d);
    // test get lookup property
    Collection<String> requieredAttributs = new HashSet<String>();
    ListingPropertyVisitor.VISITOR.visit(interpolate, requieredAttributs);
    assertEquals(requieredAttributs.size(), 1);
    assertEquals(requieredAttributs.iterator().next(), attribut);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) Color(java.awt.Color) ArrayList(java.util.ArrayList) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) Feature(org.opengis.feature.Feature) FilterFactory(org.opengis.filter.FilterFactory) Expression(org.opengis.filter.Expression) DefaultStyleFactory(org.geotoolkit.style.DefaultStyleFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 54 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class RandomStyleBuilder method createRandomLineSymbolizer.

public static LineSymbolizer createRandomLineSymbolizer() {
    final Unit uom = Units.POINT;
    final String geom = StyleConstants.DEFAULT_GEOM;
    final String name = null;
    final Stroke stroke = SF.stroke(randomColor(), 1);
    final Expression offset = FF.literal(0);
    return SF.lineSymbolizer(name, geom, StyleConstants.DEFAULT_DESCRIPTION, uom, stroke, offset);
}
Also used : Expression(org.opengis.filter.Expression) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Unit(javax.measure.Unit)

Example 55 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class RandomStyleBuilder method createRandomPolygonSymbolizer.

public static PolygonSymbolizer createRandomPolygonSymbolizer() {
    final Unit uom = Units.POINT;
    final String geom = StyleConstants.DEFAULT_GEOM;
    final String name = null;
    final Fill fill = SF.fill(SF.literal(randomColor()), FF.literal(0.6f));
    final Stroke stroke = SF.stroke(randomColor(), 1);
    final Displacement displacement = SF.displacement(0, 0);
    final Expression offset = FF.literal(0);
    return SF.polygonSymbolizer(name, geom, StyleConstants.DEFAULT_DESCRIPTION, uom, stroke, fill, displacement, offset);
}
Also used : Expression(org.opengis.filter.Expression) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Unit(javax.measure.Unit)

Aggregations

Expression (org.opengis.filter.Expression)325 Test (org.junit.Test)112 LineString (org.locationtech.jts.geom.LineString)73 Literal (org.opengis.filter.Literal)65 ArrayList (java.util.ArrayList)47 MultiLineString (org.locationtech.jts.geom.MultiLineString)46 Unit (javax.measure.Unit)45 Description (org.opengis.style.Description)40 Fill (org.opengis.style.Fill)38 GraphicFill (org.opengis.style.GraphicFill)38 Stroke (org.opengis.style.Stroke)35 Geometry (org.locationtech.jts.geom.Geometry)31 Displacement (org.opengis.style.Displacement)29 GraphicStroke (org.opengis.style.GraphicStroke)29 ValueReference (org.opengis.filter.ValueReference)27 JAXBElement (javax.xml.bind.JAXBElement)22 LineSymbolizer (org.opengis.style.LineSymbolizer)22 PointSymbolizer (org.opengis.style.PointSymbolizer)22 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)22 MutableStyle (org.geotoolkit.style.MutableStyle)21