use of org.opengis.style.LineSymbolizer in project geotoolkit by Geomatys.
the class KmzContextInterpreter method writeSymbolizer.
/**
* Writes KML color styles mapping SLD Symbolizers.
* Color styles are written into KML Style selector.
*/
private AbstractStyleSelector writeSymbolizer(Symbolizer symbolizer, Style styleSelector) {
if (symbolizer instanceof ExtensionSymbolizer) {
} else // LineSymbolizer mapping
if (symbolizer instanceof LineSymbolizer) {
final LineSymbolizer lineSymbolizer = (LineSymbolizer) symbolizer;
final LineStyle lineStyle = ((styleSelector.getLineStyle() == null) ? KML_FACTORY.createLineStyle() : styleSelector.getLineStyle());
lineStyle.setWidth((Double) this.writeExpression(lineSymbolizer.getStroke().getWidth(), Double.class, null));
lineStyle.setColor((Color) this.writeExpression(lineSymbolizer.getStroke().getColor(), Color.class, null));
styleSelector.setLineStyle(lineStyle);
} else // PointSymbolizezr mapping
if (symbolizer instanceof PointSymbolizer) {
// PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
// IconStyle iconStyle = KML_FACTORY.createIconStyle();
// GraphicalSymbol gs = ((GraphicalSymbol) pointSymbolizer.getGraphic().graphicalSymbols().get(0));
// gs.
} else // PolygonSymbolizer mapping
if (symbolizer instanceof PolygonSymbolizer) {
final PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer;
final PolyStyle polyStyle = KML_FACTORY.createPolyStyle();
// Fill
if (polygonSymbolizer.getFill() == null) {
polyStyle.setFill(false);
} else {
polyStyle.setFill(true);
polyStyle.setColor((Color) this.writeExpression(polygonSymbolizer.getFill().getColor(), Color.class, null));
}
// Outline
if (polygonSymbolizer.getStroke() == null) {
polyStyle.setOutline(false);
} else if (styleSelector.getLineStyle() == null) {
polyStyle.setOutline(true);
final LineStyle lineStyle = KML_FACTORY.createLineStyle();
lineStyle.setColor((Color) this.writeExpression(polygonSymbolizer.getStroke().getColor(), Color.class, null));
lineStyle.setWidth((Double) this.writeExpression(polygonSymbolizer.getStroke().getWidth(), Double.class, null));
styleSelector.setLineStyle(lineStyle);
}
styleSelector.setPolyStyle(polyStyle);
} else if (symbolizer instanceof RasterSymbolizer) {
} else if (symbolizer instanceof TextSymbolizer) {
final TextSymbolizer textSymbolizer = (TextSymbolizer) symbolizer;
final LabelStyle labelStyle = KML_FACTORY.createLabelStyle();
if (textSymbolizer.getFont() != null) {
textSymbolizer.getFont().getSize();
}
if (textSymbolizer.getFill() != null) {
labelStyle.setColor((Color) this.writeExpression(textSymbolizer.getFill().getColor(), Color.class, null));
}
styleSelector.setLabelStyle(labelStyle);
}
return styleSelector;
}
use of org.opengis.style.LineSymbolizer in project geotoolkit by Geomatys.
the class IntervalStyleBuilder method derivateSymbolizer.
/**
* Derivate a symbolizer with a new color.
*/
private 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);
}
}
use of org.opengis.style.LineSymbolizer in project geotoolkit by Geomatys.
the class SEforSLD110Test method testLineSymbolizer.
@Test
public void testLineSymbolizer() throws JAXBException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_SE_SYMBOL_LINE);
assertNotNull(obj);
JAXBElement<org.geotoolkit.se.xml.v110.LineSymbolizerType> jax = (JAXBElement<org.geotoolkit.se.xml.v110.LineSymbolizerType>) obj;
LineSymbolizer lineSymbol = TRANSFORMER_GT.visit(jax.getValue());
assertNotNull(lineSymbol);
assertEquals("the_geom", lineSymbol.getGeometryPropertyName());
assertEquals(Units.METRE, lineSymbol.getUnitOfMeasure());
assertNotNull(lineSymbol.getStroke());
assertEquals(floatValue(lineSymbol.getStroke().getWidth()), 13f, DELTA);
assertEquals(floatValue(lineSymbol.getStroke().getOpacity()), 0.4f, DELTA);
assertEquals(stringValue(lineSymbol.getStroke().getLineJoin()), "bevel");
assertEquals(stringValue(lineSymbol.getStroke().getLineCap()), "butt");
assertEquals(floatValue(lineSymbol.getStroke().getDashOffset()), 2.3f, DELTA);
assertEquals(colorValue(lineSymbol.getStroke().getColor()), ObjectConverters.convert("#FF0000", Color.class));
// Write test
JAXBElement<org.geotoolkit.se.xml.v110.LineSymbolizerType> pvt = TRANSFORMER_OGC.visit(lineSymbol, null);
assertNotNull(pvt);
assertEquals(new PropertyNameType("the_geom"), ((JAXBElement) pvt.getValue().getGeometry().getContent().get(0)).getValue());
assertNotNull(pvt.getValue().getStroke());
MARSHALLER.marshal(pvt, TEST_FILE_SE_SYMBOL_LINE);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
use of org.opengis.style.LineSymbolizer in project geotoolkit by Geomatys.
the class Styles method graphicFillLine.
public static MutableStyle graphicFillLine() throws URISyntaxException {
// general informations
final String name = "mySymbol";
final Description desc = DEFAULT_DESCRIPTION;
// use the default geometry of the feature
final String geometry = null;
final Unit unit = Units.POINT;
final Expression offset = LITERAL_ONE_FLOAT;
// the stroke fill
// a pattern that will be repeated like a mosaic
final Expression size = FF.literal(12);
final Expression opacity = LITERAL_ONE_FLOAT;
final Expression rotation = LITERAL_ONE_FLOAT;
final AnchorPoint anchor = DEFAULT_ANCHOR_POINT;
final Displacement disp = DEFAULT_DISPLACEMENT;
final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
final Stroke fillStroke = SF.stroke(Color.BLACK, 2);
final Fill fill = SF.fill(Color.RED);
final Mark mark = SF.mark(MARK_CIRCLE, fill, fillStroke);
symbols.add(mark);
final GraphicFill graphicfill = SF.graphicFill(symbols, opacity, size, rotation, anchor, disp);
// the visual element
final Expression color = SF.literal(Color.BLUE);
final Expression width = FF.literal(4);
final Expression linecap = STROKE_CAP_ROUND;
final Expression linejoin = STROKE_JOIN_BEVEL;
final float[] dashes = new float[] { 8, 4, 2, 2, 2, 2, 2, 4 };
final Expression dashOffset = LITERAL_ZERO_FLOAT;
final Stroke stroke = SF.stroke(graphicfill, color, opacity, width, linejoin, linecap, dashes, dashOffset);
final LineSymbolizer symbolizer = SF.lineSymbolizer(name, geometry, desc, unit, stroke, offset);
final MutableStyle style = SF.style(symbolizer);
return style;
}
use of org.opengis.style.LineSymbolizer in project geotoolkit by Geomatys.
the class Styles method dashedLine.
public static MutableStyle dashedLine() throws URISyntaxException {
// general informations
final String name = "mySymbol";
final Description desc = DEFAULT_DESCRIPTION;
// use the default geometry of the feature
final String geometry = null;
final Unit unit = Units.POINT;
final Expression offset = LITERAL_ONE_FLOAT;
// the visual element
final Expression color = SF.literal(Color.BLUE);
final Expression width = FF.literal(2);
final Expression opacity = LITERAL_ONE_FLOAT;
final Expression linecap = STROKE_CAP_BUTT;
final Expression linejoin = STROKE_JOIN_ROUND;
final float[] dashes = new float[] { 8, 4, 2, 2, 2, 2, 2, 4 };
final Expression dashOffset = LITERAL_ZERO_FLOAT;
final Stroke stroke = SF.stroke(color, opacity, width, linejoin, linecap, dashes, dashOffset);
final LineSymbolizer symbolizer = SF.lineSymbolizer(name, geometry, desc, unit, stroke, offset);
final MutableStyle style = SF.style(symbolizer);
return style;
}
Aggregations