Search in sources :

Example 1 with FeatureStyle

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

the class FilterTest method pointWithScale.

@Test
public void pointWithScale() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    assertTrue(point.visibleIf.get() instanceof ConstantFilter);
    point.visibleIf.createValue(ScaleRangeFilter.defaults(10000, 500000));
    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);
    assertEquals(10000.0d, rule.getMinScaleDenominator(), 0);
    assertEquals(500000.0d, rule.getMaxScaleDenominator(), 0);
    PointSymbolizer sym = (PointSymbolizer) rule.getSymbolizers()[0];
    assertEquals(SLDSerializer2.ff.literal(23.0), sym.getGraphic().getSize());
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) 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) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Example 2 with FeatureStyle

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

the class StyleModelTest method testSimpleLine.

@Test
public void testSimpleLine() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    LineStyle style = fs.members().createElement(LineStyle.defaults);
    assertTrue(style.visibleIf.get() instanceof ConstantFilter);
    style.fill.get().color.createValue(ConstantColor.defaults(0, 0, 0));
    style.fill.get().width.createValue(ConstantNumber.defaults(5.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(2, rule.symbolizers().size());
    assertNull(rule.getFilter());
    LineSymbolizer strokeLine = (LineSymbolizer) rule.symbolizers().get(0);
    assertEqualsLiteral(0.5, strokeLine.getStroke().getOpacity());
    assertEqualsLiteral(15.0, strokeLine.getStroke().getWidth());
    LineSymbolizer fillLine = (LineSymbolizer) rule.symbolizers().get(1);
    assertEqualsLiteral(0.0, fillLine.getStroke().getOpacity());
    assertEqualsLiteral(5.0, fillLine.getStroke().getWidth());
}
Also used : LineStyle(org.polymap.core.style.model.feature.LineStyle) LineSymbolizer(org.geotools.styling.LineSymbolizer) 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) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Example 3 with FeatureStyle

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

the class StyleModelTest method propertyNumberWithMinimumMaximum.

@Ignore
@Test
public void propertyNumberWithMinimumMaximum() {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    point.diameter.createValue(AttributeValue.defaults("foo", new Double(8), new Double(23)));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    Style style = repo.serializedFeatureStyle(fs.id(), Style.class).get();
    PointSymbolizer sym = (PointSymbolizer) style.featureTypeStyles().get(0).rules().get(0).getSymbolizers()[0];
    assertEquals("min([max([foo], [8.0])], [23.0])", sym.getGraphic().getSize().toString());
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class, OutputFormat.OGC));
    style = repo.serializedFeatureStyle(fs.id(), Style.class, OutputFormat.OGC).get();
    List<FeatureTypeStyle> featureTypeStyles = style.featureTypeStyles();
    assertEquals(1, featureTypeStyles.size());
    assertEquals("[ foo <= 8.0 ]", featureTypeStyles.get(0).rules().get(0).getFilter().toString());
    assertEquals("[ foo >= 23.0 ]", featureTypeStyles.get(0).rules().get(1).getFilter().toString());
    assertEquals("[[ foo > 8.0 ] AND [ foo < 23.0 ]]", featureTypeStyles.get(0).rules().get(2).getFilter().toString());
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) 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) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with FeatureStyle

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

the class StyleModelTest method propertyRangeMappedNumbers.

@Ignore
@Test
public void propertyRangeMappedNumbers() {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    point.diameter.createValue(new ValueInitializer<FilterMappedPrimitives<Double>>() {

        @Override
        public FilterMappedPrimitives<Double> initialize(FilterMappedPrimitives<Double> proto) throws Exception {
            proto.add(ff.lessOrEqual(ff.property("foo"), ff.literal("big")), new Double(5));
            proto.add(ff.less(ff.property("foo"), ff.literal("bigger")), new Double(15));
            proto.add(ff.greaterOrEqual(ff.property("foo"), ff.literal("bigger")), new Double(23));
            return proto;
        }
    });
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class, OutputFormat.GEOSERVER));
    Style style = repo.serializedFeatureStyle(fs.id(), Style.class, OutputFormat.GEOSERVER).get();
    List<FeatureTypeStyle> featureTypeStyles = style.featureTypeStyles();
    assertEquals(1, featureTypeStyles.size());
    assertEquals(Filter.INCLUDE, featureTypeStyles.get(0).rules().get(0).getFilter());
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class, OutputFormat.OGC));
    style = repo.serializedFeatureStyle(fs.id(), Style.class, OutputFormat.OGC).get();
    featureTypeStyles = style.featureTypeStyles();
    assertEquals(1, featureTypeStyles.size());
    assertEquals("[ foo <= big ]", featureTypeStyles.get(0).rules().get(0).getFilter().toString());
    assertEquals("[ foo < bigger ]", featureTypeStyles.get(0).rules().get(1).getFilter().toString());
    assertEquals("[ foo >= bigger ]", featureTypeStyles.get(0).rules().get(2).getFilter().toString());
}
Also used : FilterMappedPrimitives(org.polymap.core.style.model.feature.FilterMappedPrimitives) PointStyle(org.polymap.core.style.model.feature.PointStyle) 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) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with FeatureStyle

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

the class StyleModelTest method testSimplePoint.

@Test
public void testSimplePoint() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    PointStyle style = fs.members().createElement(PointStyle.defaults);
    assertTrue(style.visibleIf.get() instanceof ConstantFilter);
    style.diameter.createValue(ConstantNumber.defaults(100.0));
    style.rotation.createValue(ConstantNumber.defaults(45.0));
    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());
    PointSymbolizer sym = (PointSymbolizer) rule.symbolizers().get(0);
    assertEqualsLiteral(100.0, sym.getGraphic().getSize());
    assertEqualsLiteral(45.0, sym.getGraphic().getRotation());
    assertEquals(1, sym.getGraphic().graphicalSymbols().size());
    GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
    Mark mark = (Mark) symbol;
    assertEqualsLiteral(0.0, mark.getFill().getOpacity());
    assertEqualsLiteral(0.5, mark.getStroke().getOpacity());
    assertEqualsLiteral(5.0, mark.getStroke().getWidth());
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) GraphicalSymbol(org.opengis.style.GraphicalSymbol) 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) Mark(org.geotools.styling.Mark) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Aggregations

FeatureStyle (org.polymap.core.style.model.FeatureStyle)18 Test (org.junit.Test)17 PointStyle (org.polymap.core.style.model.feature.PointStyle)14 LineStyle (org.polymap.core.style.model.feature.LineStyle)13 PolygonStyle (org.polymap.core.style.model.feature.PolygonStyle)13 TextStyle (org.polymap.core.style.model.feature.TextStyle)13 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)11 Style (org.geotools.styling.Style)11 ConstantStrokeCapStyle (org.polymap.core.style.model.feature.ConstantStrokeCapStyle)11 ConstantStrokeDashStyle (org.polymap.core.style.model.feature.ConstantStrokeDashStyle)11 ConstantStrokeJoinStyle (org.polymap.core.style.model.feature.ConstantStrokeJoinStyle)11 StrokeDashStyle (org.polymap.core.style.model.feature.StrokeDashStyle)11 Ignore (org.junit.Ignore)8 PointSymbolizer (org.geotools.styling.PointSymbolizer)7 ConstantFilter (org.polymap.core.style.model.feature.ConstantFilter)7 Rule (org.geotools.styling.Rule)6 FilterMappedPrimitives (org.polymap.core.style.model.feature.FilterMappedPrimitives)2 Cloner (com.rits.cloning.Cloner)1 Color (java.awt.Color)1 List (java.util.List)1