Search in sources :

Example 11 with PointSymbolizer

use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.

the class MapfileToSLDProcess method createPointSymbolizer.

private List<Symbolizer> createPointSymbolizer(final Feature style) {
    final String symbolName = (String) style.getPropertyValue(STYLE_SYMBOL.toString());
    Expression expSize = (Expression) style.getPropertyValue(STYLE_SIZE.toString());
    Expression expOpacity = (Expression) style.getPropertyValue(STYLE_OPACITY.toString());
    Expression expFillColor = (Expression) style.getPropertyValue(STYLE_COLOR.toString());
    Expression expStrokeColor = (Expression) style.getPropertyValue(STYLE_OUTLINECOLOR.toString());
    Expression expStrokeWidth = (Expression) style.getPropertyValue(STYLE_WIDTH.toString());
    if (expFillColor == null) {
        expFillColor = DEFAULT_FILL_COLOR;
    }
    if (expStrokeColor == null) {
        expStrokeColor = DEFAULT_STROKE_COLOR;
    }
    if (expStrokeWidth == null) {
        expStrokeWidth = FF.literal(0);
    }
    if (expOpacity == null) {
        expOpacity = DEFAULT_GRAPHIC_OPACITY;
    }
    if (expSize == null) {
        expSize = DEFAULT_GRAPHIC_SIZE;
    }
    final List<Symbolizer> symbolizers = new ArrayList<Symbolizer>();
    final Feature symbol = getSymbol(symbolName);
    if (symbol == null) {
        // no symbol found for this name
        return symbolizers;
    }
    final Stroke stroke = SF.stroke(expStrokeColor, expStrokeWidth);
    final Fill fill = SF.fill(expFillColor);
    final String symbolTypeName = (String) symbol.getPropertyValue(SYMBOL_TYPE.toString());
    final Mark mark;
    if ("ellipse".equals(symbolTypeName)) {
        mark = SF.mark(MARK_CIRCLE, fill, stroke);
    } else if ("hatch".equals(symbolTypeName)) {
        // TODO
        mark = SF.mark(MARK_SQUARE, fill, stroke);
    } else if ("pixmap".equals(symbolTypeName)) {
        // TODO
        mark = SF.mark(MARK_SQUARE, fill, stroke);
    } else if ("simple".equals(symbolTypeName)) {
        // TODO
        mark = SF.mark(MARK_SQUARE, fill, stroke);
    } else if ("truetype".equals(symbolTypeName)) {
        // TODO
        mark = SF.mark(MARK_SQUARE, fill, stroke);
    } else if ("vector".equals(symbolTypeName)) {
        // TODO
        mark = SF.mark(MARK_SQUARE, fill, stroke);
    } else {
        // can not build symbol
        return symbolizers;
    }
    // general informations
    final String name = "";
    final Description desc = DEFAULT_DESCRIPTION;
    // use the default geometry of the feature
    final String geometry = null;
    final Unit unit = Units.POINT;
    // the visual element
    final Expression opacity = LITERAL_ONE_FLOAT;
    final Expression rotation = LITERAL_ZERO_FLOAT;
    final AnchorPoint anchor = DEFAULT_ANCHOR_POINT;
    final Displacement disp = DEFAULT_DISPLACEMENT;
    final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    symbols.add(mark);
    final Graphic graphic = SF.graphic(symbols, opacity, expSize, rotation, anchor, disp);
    final PointSymbolizer symbolizer = SF.pointSymbolizer(name, geometry, desc, unit, graphic);
    symbolizers.add(symbolizer);
    return symbolizers;
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Stroke(org.opengis.style.Stroke) Fill(org.opengis.style.Fill) Description(org.opengis.style.Description) Graphic(org.opengis.style.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) Mark(org.opengis.style.Mark) Unit(javax.measure.Unit) Feature(org.opengis.feature.Feature) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer) Displacement(org.opengis.style.Displacement) AnchorPoint(org.opengis.style.AnchorPoint) Expression(org.opengis.filter.Expression)

Example 12 with PointSymbolizer

use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.

the class GTtoSE100Transformer method visit.

/**
 * Transform a GT rule in jaxb rule or OnlineResource
 */
@Override
public org.geotoolkit.sld.xml.v100.Rule visit(final Rule rule, final Object data) {
    final org.geotoolkit.sld.xml.v100.Rule rt = sld_factory_v100.createRule();
    rt.setName(rule.getName());
    if (rule.getDescription() != null) {
        if (rule.getDescription().getAbstract() != null)
            rt.setAbstract(rule.getDescription().getAbstract().toString());
        if (rule.getDescription().getTitle() != null)
            rt.setTitle(rule.getDescription().getTitle().toString());
    }
    if (rule.isElseFilter()) {
        rt.setElseFilter(sld_factory_v100.createElseFilter());
    } else if (rule.getFilter() != null) {
        rt.setFilter(apply(rule.getFilter()));
    }
    if (rule.getLegend() != null) {
        rt.setLegendGraphic(visit(rule.getLegend(), null));
    }
    rt.setMaxScaleDenominator(rule.getMaxScaleDenominator());
    rt.setMinScaleDenominator(rule.getMinScaleDenominator());
    for (final Symbolizer symbol : rule.symbolizers()) {
        if (symbol instanceof LineSymbolizer) {
            rt.getSymbolizer().add(visit((LineSymbolizer) symbol, null));
        } else if (symbol instanceof PolygonSymbolizer) {
            rt.getSymbolizer().add(visit((PolygonSymbolizer) symbol, null));
        } else if (symbol instanceof PointSymbolizer) {
            rt.getSymbolizer().add(visit((PointSymbolizer) symbol, null));
        } else if (symbol instanceof RasterSymbolizer) {
            rt.getSymbolizer().add(visit((RasterSymbolizer) symbol, null));
        } else if (symbol instanceof TextSymbolizer) {
            rt.getSymbolizer().add(visit((TextSymbolizer) symbol, null));
        } else if (symbol instanceof ExtensionSymbolizer) {
        // TODO provide jaxb parsing for unknowned symbolizers
        // rt.getSymbolizer().add( visit((ExtensionSymbolizer)symbol,null));
        }
    }
    return rt;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer)

Example 13 with PointSymbolizer

use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.

the class SEforSLD110Test method testPointSymbolizer.

@Test
public void testPointSymbolizer() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_SYMBOL_POINT);
    assertNotNull(obj);
    JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType> jax = (JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType>) obj;
    PointSymbolizer pointSymbol = TRANSFORMER_GT.visit(jax.getValue());
    assertNotNull(pointSymbol);
    assertEquals(pointSymbol.getGeometryPropertyName(), valueGeom);
    assertEquals(Units.POINT, pointSymbol.getUnitOfMeasure());
    assertNotNull(pointSymbol.getGraphic());
    assertEquals(floatValue(pointSymbol.getGraphic().getOpacity()), 0.7f, DELTA);
    assertEquals(floatValue(pointSymbol.getGraphic().getRotation()), 110f, DELTA);
    assertEquals(floatValue(pointSymbol.getGraphic().getSize()), 32f, DELTA);
    Mark mark = (Mark) pointSymbol.getGraphic().graphicalSymbols().get(0);
    assertEquals(stringValue(mark.getWellKnownName()), "square");
    assertEquals(floatValue(mark.getStroke().getWidth()), 13f, DELTA);
    assertEquals(floatValue(mark.getStroke().getOpacity()), 0.4f, DELTA);
    assertEquals(stringValue(mark.getStroke().getLineJoin()), "bevel");
    assertEquals(stringValue(mark.getStroke().getLineCap()), "butt");
    assertEquals(floatValue(mark.getStroke().getDashOffset()), 2.3f, DELTA);
    assertEquals(colorValue(mark.getStroke().getColor()), ObjectConverters.convert("#404040", Color.class));
    assertEquals(floatValue(mark.getFill().getOpacity()), 1.0f, DELTA);
    assertEquals(colorValue(mark.getFill().getColor()), ObjectConverters.convert("#808080", Color.class));
    // Write test
    JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType> pvt = TRANSFORMER_OGC.visit(pointSymbol, null);
    assertNotNull(pvt);
    assertEquals(pvt.getValue().getGeometry(), null);
    org.geotoolkit.se.xml.v110.GraphicType gra = pvt.getValue().getGraphic();
    assertNotNull(gra.getOpacity());
    assertNotNull(gra.getRotation());
    assertNotNull(gra.getSize());
    assertEquals(gra.getExternalGraphicOrMark().size(), 1);
    assertNotNull(pvt.getValue().getGraphic());
    MARSHALLER.marshal(pvt, TEST_FILE_SE_SYMBOL_POINT);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Marshaller(javax.xml.bind.Marshaller) Color(java.awt.Color) Mark(org.opengis.style.Mark) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 14 with PointSymbolizer

use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.

the class CategoryStyleBuilder method derivateSymbolizer.

/**
 * Derivate a symbolizer with a new color.
 */
public Symbolizer derivateSymbolizer(final Symbolizer symbol, final Color color) {
    if (symbol instanceof PolygonSymbolizer) {
        PolygonSymbolizer ps = (PolygonSymbolizer) symbol;
        Fill fill = sf.fill(sf.literal(color), ps.getFill().getOpacity());
        return sf.polygonSymbolizer(ps.getName(), ps.getGeometryPropertyName(), ps.getDescription(), ps.getUnitOfMeasure(), ps.getStroke(), fill, ps.getDisplacement(), ps.getPerpendicularOffset());
    } else if (symbol instanceof LineSymbolizer) {
        LineSymbolizer ls = (LineSymbolizer) symbol;
        Stroke oldStroke = ls.getStroke();
        Stroke stroke = sf.stroke(sf.literal(color), oldStroke.getOpacity(), oldStroke.getWidth(), oldStroke.getLineJoin(), oldStroke.getLineCap(), oldStroke.getDashArray(), oldStroke.getDashOffset());
        return sf.lineSymbolizer(ls.getName(), ls.getGeometryPropertyName(), ls.getDescription(), ls.getUnitOfMeasure(), stroke, ls.getPerpendicularOffset());
    } else if (symbol instanceof PointSymbolizer) {
        PointSymbolizer ps = (PointSymbolizer) symbol;
        Graphic oldGraphic = ps.getGraphic();
        Mark oldMark = (Mark) oldGraphic.graphicalSymbols().get(0);
        Fill fill = sf.fill(sf.literal(color), oldMark.getFill().getOpacity());
        List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
        symbols.add(sf.mark(oldMark.getWellKnownName(), fill, oldMark.getStroke()));
        Graphic graphic = sf.graphic(symbols, oldGraphic.getOpacity(), oldGraphic.getSize(), oldGraphic.getRotation(), oldGraphic.getAnchorPoint(), oldGraphic.getDisplacement());
        return sf.pointSymbolizer(graphic, ps.getGeometryPropertyName());
    } else {
        throw new IllegalArgumentException("unexpected symbolizer type : " + symbol);
    }
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Fill(org.opengis.style.Fill) Stroke(org.opengis.style.Stroke) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) Graphic(org.opengis.style.Graphic) LineSymbolizer(org.opengis.style.LineSymbolizer) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) Mark(org.opengis.style.Mark)

Example 15 with PointSymbolizer

use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.

the class MeridianTest method createFeatureLayer.

private static MapLayers createFeatureLayer(MultiPoint geometry) {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test");
    ftb.addAttribute(MultiPoint.class).setName("geom").setCRS(CommonCRS.WGS84.normalizedGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY);
    final FeatureType type = ftb.build();
    final Feature feature = type.newInstance();
    JTS.setCRS(geometry, CommonCRS.WGS84.normalizedGeographic());
    feature.setPropertyValue("geom", geometry);
    final FeatureSet col = new InMemoryFeatureSet(type, Arrays.asList(feature));
    final List<GraphicalSymbol> symbols = new ArrayList<>();
    symbols.add(SF.mark(StyleConstants.MARK_SQUARE, SF.fill(Color.RED), SF.stroke(Color.BLACK, 0)));
    final Graphic graphic = SF.graphic(symbols, StyleConstants.LITERAL_ONE_FLOAT, FF.literal(2), StyleConstants.LITERAL_ZERO_FLOAT, null, null);
    final PointSymbolizer ps = SF.pointSymbolizer(graphic, null);
    final MutableStyle style = SF.style(ps);
    final MapLayer layer = MapBuilder.createLayer(col);
    layer.setStyle(style);
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(layer);
    return context;
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) PointSymbolizer(org.opengis.style.PointSymbolizer) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) Graphic(org.opengis.style.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) MapLayer(org.apache.sis.portrayal.MapLayer) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) MutableStyle(org.geotoolkit.style.MutableStyle) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) MapLayers(org.apache.sis.portrayal.MapLayers)

Aggregations

PointSymbolizer (org.opengis.style.PointSymbolizer)21 Graphic (org.opengis.style.Graphic)12 GraphicalSymbol (org.opengis.style.GraphicalSymbol)12 ArrayList (java.util.ArrayList)11 Mark (org.opengis.style.Mark)10 MutableStyle (org.geotoolkit.style.MutableStyle)9 Fill (org.opengis.style.Fill)7 LineSymbolizer (org.opengis.style.LineSymbolizer)7 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)7 Stroke (org.opengis.style.Stroke)7 Test (org.junit.Test)6 Expression (org.opengis.filter.Expression)6 Unit (javax.measure.Unit)5 AnchorPoint (org.opengis.style.AnchorPoint)5 Description (org.opengis.style.Description)5 Displacement (org.opengis.style.Displacement)5 TextSymbolizer (org.opengis.style.TextSymbolizer)5 RasterSymbolizer (org.opengis.style.RasterSymbolizer)4 Color (java.awt.Color)3 BufferedImage (java.awt.image.BufferedImage)3