Search in sources :

Example 1 with PolygonStyle

use of org.polymap.core.style.model.feature.PolygonStyle 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 2 with PolygonStyle

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

the class SLDSerializer2 method serialize.

@Override
public org.geotools.styling.Style serialize(Context context) {
    FeatureStyle featureStyle = context.featureStyle.get();
    List<Style> sorted = featureStyle.members().stream().sorted((s1, s2) -> s1.zPriority.get().compareTo(s2.zPriority.get())).collect(Collectors.toList());
    org.geotools.styling.Style result = sf.createStyle();
    for (Style style : sorted) {
        if (style.active.get()) {
            StyleSerializer serializer = null;
            if (style instanceof PointStyle) {
                serializer = new PointStyleSerializer(context);
            } else if (style instanceof PolygonStyle) {
                serializer = new PolygonStyleSerializer(context);
            } else if (style instanceof TextStyle) {
                serializer = new TextStyleSerializer(context);
            } else if (style instanceof LineStyle) {
                serializer = new LineStyleSerializer(context);
            } else if (style instanceof RasterGrayStyle) {
                serializer = new RasterSerializer.GraySerializer(context);
            } else if (style instanceof RasterRGBStyle) {
                serializer = new RasterSerializer.RGBSerializer(context);
            } else if (style instanceof RasterColorMapStyle) {
                serializer = new RasterSerializer.ColorMapSerializer(context);
            } else {
                throw new RuntimeException("Unhandled Style type: " + style.getClass().getName());
            }
            serializer.serialize(style, result);
        }
    }
    return result;
}
Also used : PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) RasterColorMapStyle(org.polymap.core.style.model.raster.RasterColorMapStyle) Cloner(com.rits.cloning.Cloner) SLD(org.geotools.styling.SLD) FeatureStyleSerializer(org.polymap.core.style.serialize.FeatureStyleSerializer) CommonFactoryFinder(org.geotools.factory.CommonFactoryFinder) Collectors(java.util.stream.Collectors) StyleFactory(org.geotools.styling.StyleFactory) StringUtils(org.apache.commons.lang3.StringUtils) SLDTransformer(org.geotools.styling.SLDTransformer) Style(org.polymap.core.style.model.Style) RasterRGBStyle(org.polymap.core.style.model.raster.RasterRGBStyle) List(java.util.List) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FilterFactory2(org.opengis.filter.FilterFactory2) Log(org.apache.commons.logging.Log) FeatureStyle(org.polymap.core.style.model.FeatureStyle) LogFactory(org.apache.commons.logging.LogFactory) RasterGrayStyle(org.polymap.core.style.model.raster.RasterGrayStyle) DataPlugin(org.polymap.core.data.DataPlugin) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FeatureStyleSerializer(org.polymap.core.style.serialize.FeatureStyleSerializer) RasterColorMapStyle(org.polymap.core.style.model.raster.RasterColorMapStyle) RasterGrayStyle(org.polymap.core.style.model.raster.RasterGrayStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) RasterRGBStyle(org.polymap.core.style.model.raster.RasterRGBStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) RasterColorMapStyle(org.polymap.core.style.model.raster.RasterColorMapStyle) Style(org.polymap.core.style.model.Style) RasterRGBStyle(org.polymap.core.style.model.raster.RasterRGBStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) RasterGrayStyle(org.polymap.core.style.model.raster.RasterGrayStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle)

Example 3 with PolygonStyle

use of org.polymap.core.style.model.feature.PolygonStyle 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 4 with PolygonStyle

use of org.polymap.core.style.model.feature.PolygonStyle 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)

Example 5 with PolygonStyle

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

the class DefaultStyle method fillPolygonStyle.

public static PolygonStyle fillPolygonStyle(FeatureStyle fs) {
    PolygonStyle polygon = fs.members().createElement(PolygonStyle.defaults);
    polygon.fill.get().color.createValue(ConstantColor.defaults(randomColor()));
    polygon.fill.get().opacity.createValue(ConstantNumber.defaults(0.5));
    polygon.stroke.get().color.createValue(ConstantColor.defaults(randomColor()));
    polygon.stroke.get().width.createValue(ConstantNumber.defaults(1.0));
    polygon.stroke.get().opacity.createValue(ConstantNumber.defaults(1.0));
    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());
    return polygon;
}
Also used : PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle)

Aggregations

PolygonStyle (org.polymap.core.style.model.feature.PolygonStyle)5 FeatureStyle (org.polymap.core.style.model.FeatureStyle)3 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)2 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)2 Style (org.geotools.styling.Style)2 Test (org.junit.Test)2 ConstantFilter (org.polymap.core.style.model.feature.ConstantFilter)2 LineStyle (org.polymap.core.style.model.feature.LineStyle)2 PointStyle (org.polymap.core.style.model.feature.PointStyle)2 TextStyle (org.polymap.core.style.model.feature.TextStyle)2 Cloner (com.rits.cloning.Cloner)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 CommonFactoryFinder (org.geotools.factory.CommonFactoryFinder)1 Rule (org.geotools.styling.Rule)1 SLD (org.geotools.styling.SLD)1 SLDTransformer (org.geotools.styling.SLDTransformer)1