Search in sources :

Example 61 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle 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)

Example 62 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project polymap4-core by Polymap4.

the class StyleModelTest method testFilterMappedNumbers.

@Test
public void testFilterMappedNumbers() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    point.rotation.createValue(FilterMappedPrimitives.defaults()).add(ff.equals(ff.literal(1), ff.literal(1)), 45d).add(ff.equals(ff.literal(2), ff.literal(2)), 90d);
    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(2, fts.rules().size());
    assertEqualsLiteral(45.0, ((PointSymbolizer) fts.rules().get(0).symbolizers().get(0)).getGraphic().getRotation());
    assertEqualsLiteral(90.0, ((PointSymbolizer) fts.rules().get(1).symbolizers().get(0)).getGraphic().getRotation());
}
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) Test(org.junit.Test)

Example 63 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project polymap4-core by Polymap4.

the class StyleModelTest method propertyMappedNumbers.

@Ignore
@Test
public void propertyMappedNumbers() {
    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.equals(ff.property("foo"), ff.literal("big")), new Double(5));
            proto.add(ff.equals(ff.property("foo"), ff.literal("bigger")), new Double(15));
            proto.add(ff.and(ff.notEqual(ff.property("foo"), ff.literal("big")), ff.notEqual(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 != big ] AND [ 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 64 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project polymap4-core by Polymap4.

the class PolygonStyleSerializer method serialize.

@Override
public void serialize(PolygonStyle style, Style result) {
    // default symbolizer
    PolygonSymbolizer polygon = sf.createPolygonSymbolizer();
    polygon.setFill(sf.getDefaultFill());
    polygon.setStroke(sf.getDefaultStroke());
    FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, polygon);
    fts.setName(style.title.opt().orElse("PolygonStyle"));
    fts.getDescription().setTitle(style.title.opt().orElse("PolygonStyle"));
    accessor.set(rule -> (PolygonSymbolizer) rule.symbolizers().get(0));
    // fill
    style.fill.opt().ifPresent(fill -> {
        new FillCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).getFill()).serialize(fill, fts);
    });
    // stroke
    style.stroke.opt().ifPresent(stroke -> {
        new StrokeCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).getStroke()).serialize(stroke, fts);
    });
}
Also used : PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) Style(org.geotools.styling.Style) Context(org.polymap.core.style.serialize.FeatureStyleSerializer.Context) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 65 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.

the class StyleHelper method getRandomStyles.

/**
 * Returns a default style for the given type.
 *
 * @param dataSetTypes type definitions associated to their data set
 * @return the style
 */
public static Style getRandomStyles(SetMultimap<DataSet, TypeDefinition> dataSetTypes) {
    int defWidth = StylePreferences.getDefaultWidth();
    Style style = styleFactory.createStyle();
    for (Entry<DataSet, TypeDefinition> entry : dataSetTypes.entries()) {
        DataSet dataSet = entry.getKey();
        TypeDefinition typeDef = entry.getValue();
        FeatureTypeStyle fts;
        // TODO based on default geometry?
        // polygon is always OK as it contains stroke and fill
        // Color color = generateRandomColor(Color.WHITE);
        float saturation;
        float brightness;
        switch(dataSet) {
            case TRANSFORMED:
                saturation = 0.8f;
                brightness = 0.6f;
                break;
            case SOURCE:
            default:
                saturation = 0.75f;
                brightness = 0.8f;
                break;
        }
        Color color = generateRandomColor(saturation, brightness);
        fts = createPolygonStyle(color, defWidth);
        fts.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
        style.featureTypeStyles().add(fts);
    }
    return style;
}
Also used : NameImpl(org.geotools.feature.NameImpl) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Color(java.awt.Color) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)110 Style (org.geotools.styling.Style)81 Rule (org.geotools.styling.Rule)65 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)43 Test (org.junit.Test)42 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)24 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)21 LineSymbolizer (org.geotools.styling.LineSymbolizer)20 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)17 Symbolizer (org.geotools.styling.Symbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)14 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)12 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)12 TextSymbolizer (org.geotools.styling.TextSymbolizer)12 UserLayerImpl (org.geotools.styling.UserLayerImpl)12 ArrayList (java.util.ArrayList)11 LineStyle (org.polymap.core.style.model.feature.LineStyle)11