Search in sources :

Example 6 with PointStyle

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

the class StyleModelTest method testFeatureBasedPoint.

@Ignore
@Test
public void testFeatureBasedPoint() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    assertTrue(point.visibleIf.get() instanceof ConstantFilter);
    point.diameter.createValue(ConstantNumber.defaults(23.0));
    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).symbolizers().get(0);
    assertEquals(ff.literal(23.0), sym.getGraphic().getSize());
    point.diameter.createValue(AttributeValue.defaults("foo", null, null));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    style = repo.serializedFeatureStyle(fs.id(), Style.class).get();
    sym = (PointSymbolizer) style.featureTypeStyles().get(0).rules().get(0).getSymbolizers()[0];
    assertEquals(ff.property("foo"), sym.getGraphic().getSize());
    point.diameter.createValue(ConstantNumber.defaults(42.0));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    style = repo.serializedFeatureStyle(fs.id(), Style.class).get();
    sym = (PointSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
    assertEquals(ff.literal(42.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) 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) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with PointStyle

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

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

the class DefaultStyle method fillPointStyle.

public static PointStyle fillPointStyle(FeatureStyle fs) {
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    point.diameter.createValue(ConstantNumber.defaults(18.0));
    point.fill.get().color.createValue(ConstantColor.defaults(randomColor()));
    point.fill.get().opacity.createValue(ConstantNumber.defaults(1.0));
    point.stroke.get().color.createValue(ConstantColor.defaults(randomColor()));
    point.stroke.get().width.createValue(ConstantNumber.defaults(1.0));
    point.stroke.get().opacity.createValue(ConstantNumber.defaults(1.0));
    point.stroke.get().strokeStyle.get().capStyle.createValue(ConstantStrokeCapStyle.defaults());
    point.stroke.get().strokeStyle.get().dashStyle.createValue(ConstantStrokeDashStyle.defaults());
    point.stroke.get().strokeStyle.get().joinStyle.createValue(ConstantStrokeJoinStyle.defaults());
    return point;
}
Also used : PointStyle(org.polymap.core.style.model.feature.PointStyle)

Example 9 with PointStyle

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

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

Aggregations

PointStyle (org.polymap.core.style.model.feature.PointStyle)12 FeatureStyle (org.polymap.core.style.model.FeatureStyle)11 Test (org.junit.Test)10 LineStyle (org.polymap.core.style.model.feature.LineStyle)9 PolygonStyle (org.polymap.core.style.model.feature.PolygonStyle)9 TextStyle (org.polymap.core.style.model.feature.TextStyle)9 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)8 Style (org.geotools.styling.Style)8 ConstantStrokeCapStyle (org.polymap.core.style.model.feature.ConstantStrokeCapStyle)8 ConstantStrokeDashStyle (org.polymap.core.style.model.feature.ConstantStrokeDashStyle)8 ConstantStrokeJoinStyle (org.polymap.core.style.model.feature.ConstantStrokeJoinStyle)8 StrokeDashStyle (org.polymap.core.style.model.feature.StrokeDashStyle)8 PointSymbolizer (org.geotools.styling.PointSymbolizer)7 Ignore (org.junit.Ignore)5 ConstantFilter (org.polymap.core.style.model.feature.ConstantFilter)4 Rule (org.geotools.styling.Rule)3 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