use of org.opengis.style.PointSymbolizer 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.PointSymbolizer in project geotoolkit by Geomatys.
the class ProjectedGeometryTest method createProjectedGeometry.
private static ProjectedGeometry createProjectedGeometry(Geometry geometry, Dimension canvasBounds, AffineTransform objToDisp) throws NoninvertibleTransformException, TransformException, FactoryException {
final int canvasWidth = canvasBounds.width;
final int canvasHeight = canvasBounds.height;
// build a maplayer
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("test");
ftb.addAttribute(Geometry.class).setName("geom").setCRS(CommonCRS.WGS84.normalizedGeographic());
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.BLACK), 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);
// build a rendering canvas
final J2DCanvasBuffered canvas = new J2DCanvasBuffered(CommonCRS.WGS84.normalizedGeographic(), new Dimension(canvasWidth, canvasHeight));
canvas.applyTransform(objToDisp);
final RenderingContext2D context = canvas.prepareContext(new BufferedImage(canvasWidth, canvasHeight, BufferedImage.TYPE_INT_ARGB).createGraphics());
final ProjectedGeometry pg = new ProjectedGeometry(context);
pg.setDataGeometry(geometry, CommonCRS.WGS84.normalizedGeographic());
Envelope env = canvas.getVisibleEnvelope();
System.out.println(env.getMinimum(0) + " " + env.getMaximum(0));
System.out.println(env.getMinimum(1) + " " + env.getMaximum(1));
return pg;
}
use of org.opengis.style.PointSymbolizer in project geotoolkit by Geomatys.
the class CachedPointSymbolizerTest method testMargin.
@Test
public void testMargin() throws FactoryException {
final GridGeometry grid = new GridGeometry(new GridExtent(1, 1), CRS.getDomainOfValidity(CommonCRS.WGS84.normalizedGeographic()), GridOrientation.HOMOTHETY);
final RenderingContext2D ctx = new RenderingContext2D(grid, null);
{
// NO ANCHOR, NO DISPLACEMENT
final List<GraphicalSymbol> symbols = new ArrayList<>();
final Stroke stroke = SF.stroke(Color.BLACK, 2);
final Fill fill = SF.fill(Color.RED);
final Mark mark = SF.mark(MARK_CIRCLE, fill, stroke);
symbols.add(mark);
final Graphic graphic = SF.graphic(symbols, LITERAL_ONE_FLOAT, FF.literal(12), LITERAL_ONE_FLOAT, DEFAULT_ANCHOR_POINT, DEFAULT_DISPLACEMENT);
final PointSymbolizer symbolizer = SF.pointSymbolizer("mySymbol", (String) null, DEFAULT_DESCRIPTION, Units.POINT, graphic);
final CachedSymbolizer cached = GO2Utilities.getCached(symbolizer, null);
final float margin = cached.getMargin(null, ctx);
// 12/2 + 2*2(stroke width)
assertEquals(8f, margin, DELTA);
}
{
// NO ANCHOR
final List<GraphicalSymbol> symbols = new ArrayList<>();
final Stroke stroke = SF.stroke(Color.BLACK, 2);
final Fill fill = SF.fill(Color.RED);
final Mark mark = SF.mark(MARK_CIRCLE, fill, stroke);
symbols.add(mark);
final Graphic graphic = SF.graphic(symbols, LITERAL_ONE_FLOAT, FF.literal(12), LITERAL_ONE_FLOAT, DEFAULT_ANCHOR_POINT, SF.displacement(10, 15));
final PointSymbolizer symbolizer = SF.pointSymbolizer("mySymbol", (String) null, DEFAULT_DESCRIPTION, Units.POINT, graphic);
final CachedSymbolizer cached = GO2Utilities.getCached(symbolizer, null);
final float margin = cached.getMargin(null, ctx);
// 12/2 + 2*2(stroke width) + 15(disp)
assertEquals(23f, margin, DELTA);
}
{
final List<GraphicalSymbol> symbols = new ArrayList<>();
final Stroke stroke = SF.stroke(Color.BLACK, 2);
final Fill fill = SF.fill(Color.RED);
final Mark mark = SF.mark(MARK_CIRCLE, fill, stroke);
symbols.add(mark);
final Graphic graphic = SF.graphic(symbols, LITERAL_ONE_FLOAT, FF.literal(12), LITERAL_ONE_FLOAT, SF.anchorPoint(0, 1.7), SF.displacement(10, 15));
final PointSymbolizer symbolizer = SF.pointSymbolizer("mySymbol", (String) null, DEFAULT_DESCRIPTION, Units.POINT, graphic);
final CachedSymbolizer cached = GO2Utilities.getCached(symbolizer, null);
final float margin = cached.getMargin(null, ctx);
// 12/2 + 2*2(stroke width) + 15(disp) + 16*(1.7-0.5)
assertEquals(23f + 19.2f, margin, DELTA);
}
}
use of org.opengis.style.PointSymbolizer 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.PointSymbolizer in project geotoolkit by Geomatys.
the class ColorModelTest method createStyle.
private static MutableStyle createStyle(final Color... colors) {
final MutableStyle style = SF.style();
for (Color c : colors) {
final MutableFeatureTypeStyle fts = SF.featureTypeStyle();
final GraphicalSymbol gs = SF.mark(MARK_CIRCLE, SF.fill(c), SF.stroke(c, 1));
final PointSymbolizer symbol = SF.pointSymbolizer(SF.graphic(Collections.singletonList(gs), LITERAL_ONE_FLOAT, LITERAL_ONE_FLOAT, LITERAL_ZERO_FLOAT, DEFAULT_ANCHOR_POINT, DEFAULT_DISPLACEMENT), null);
fts.rules().add(SF.rule(symbol));
style.featureTypeStyles().add(fts);
}
return style;
}
Aggregations