Search in sources :

Example 1 with PolygonSymbolizer

use of org.opengis.style.PolygonSymbolizer 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;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) LineStyle(org.geotoolkit.data.kml.model.LineStyle) LineSymbolizer(org.opengis.style.LineSymbolizer) Color(java.awt.Color) LabelStyle(org.geotoolkit.data.kml.model.LabelStyle) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PolyStyle(org.geotoolkit.data.kml.model.PolyStyle)

Example 2 with PolygonSymbolizer

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

the class MeridianTest method createFeatureLayer.

private static <T extends Geometry> MapLayers createFeatureLayer(T geometry, Class<T> geomClass) {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test");
    ftb.addAttribute(geomClass).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 PolygonSymbolizer symbol = SF.polygonSymbolizer(SF.stroke(Color.BLACK, 0), SF.fill(Color.RED), null);
    final MutableStyle style = SF.style(symbol);
    final MapLayer layer = MapBuilder.createLayer(col);
    layer.setStyle(style);
    final MapLayers context = MapBuilder.createContext();
    context.getComponents().add(layer);
    return context;
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) MutableStyle(org.geotoolkit.style.MutableStyle) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) MapLayer(org.apache.sis.portrayal.MapLayer) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) Feature(org.opengis.feature.Feature) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 3 with PolygonSymbolizer

use of org.opengis.style.PolygonSymbolizer 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);
    }
}
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 4 with PolygonSymbolizer

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

the class GeometryExpressionTest method bufferTest.

/**
 * Test a buffer expression around geometry.
 */
@Test
public void bufferTest() throws PortrayalException, IOException {
    final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test");
    ftb.addAttribute(Point.class).setName("geom").setCRS(crs).addRole(AttributeRole.DEFAULT_GEOMETRY);
    final FeatureType type = ftb.build();
    final Point point = GO2Utilities.JTS_FACTORY.createPoint(new Coordinate(0, 0));
    JTS.setCRS(point, crs);
    final Feature feature = type.newInstance();
    feature.setPropertyValue("geom", point);
    final Expression geomExp = FF.function("buffer", FF.property("geom"), FF.literal(10));
    final Fill fill = SF.fill(Color.RED);
    final PolygonSymbolizer symbolizer = SF.polygonSymbolizer("", geomExp, DEFAULT_DESCRIPTION, DEFAULT_UOM, null, fill, DEFAULT_DISPLACEMENT, LITERAL_ZERO_FLOAT);
    final MutableStyle style = SF.style(symbolizer);
    final MapLayers context = MapBuilder.createContext();
    final MapLayer fml = MapBuilder.createLayer(FeatureStoreUtilities.collection(feature));
    fml.setStyle(style);
    context.getComponents().add(fml);
    final GeneralEnvelope env = new GeneralEnvelope(crs);
    env.setRange(0, -20, +20);
    env.setRange(1, -20, +20);
    final CanvasDef canvasDef = new CanvasDef();
    canvasDef.setEnvelope(env);
    canvasDef.setDimension(new Dimension(40, 40));
    canvasDef.setBackground(Color.WHITE);
    final SceneDef sceneDef = new SceneDef(context);
    final BufferedImage image = DefaultPortrayalService.portray(canvasDef, sceneDef);
    // we must obtain a red point of 10pixel width at image center
    final int red = Color.RED.getRGB();
    final int white = Color.WHITE.getRGB();
    Assert.assertEquals(white, image.getRGB(20, 9));
    Assert.assertEquals(red, image.getRGB(20, 11));
    Assert.assertEquals(red, image.getRGB(20, 20));
    Assert.assertEquals(red, image.getRGB(20, 29));
    Assert.assertEquals(white, image.getRGB(20, 31));
    Assert.assertEquals(white, image.getRGB(9, 20));
    Assert.assertEquals(red, image.getRGB(11, 20));
    Assert.assertEquals(red, image.getRGB(20, 20));
    Assert.assertEquals(red, image.getRGB(29, 20));
    Assert.assertEquals(white, image.getRGB(31, 20));
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) Fill(org.opengis.style.Fill) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) MapLayer(org.apache.sis.portrayal.MapLayer) Point(org.locationtech.jts.geom.Point) Dimension(java.awt.Dimension) Feature(org.opengis.feature.Feature) BufferedImage(java.awt.image.BufferedImage) Point(org.locationtech.jts.geom.Point) MutableStyle(org.geotoolkit.style.MutableStyle) Coordinate(org.locationtech.jts.geom.Coordinate) Expression(org.opengis.filter.Expression) SceneDef(org.geotoolkit.display2d.service.SceneDef) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 5 with PolygonSymbolizer

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

the class SEforSLD100Test method testPolygonSymbolizer.

@Test
public void testPolygonSymbolizer() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_SYMBOL_POLYGON);
    assertNotNull(obj);
    JAXBElement<org.geotoolkit.sld.xml.v100.PolygonSymbolizer> jax = (JAXBElement<org.geotoolkit.sld.xml.v100.PolygonSymbolizer>) obj;
    PolygonSymbolizer polySymbol = TRANSFORMER_GT.visit(jax.getValue());
    assertNotNull(polySymbol);
    assertEquals(polySymbol.getGeometryPropertyName(), valueGeom);
    assertEquals(Units.POINT, polySymbol.getUnitOfMeasure());
    assertNotNull(polySymbol.getStroke());
    assertEquals(floatValue(polySymbol.getStroke().getWidth()), 13f, DELTA);
    assertEquals(floatValue(polySymbol.getStroke().getOpacity()), 0.4f, DELTA);
    assertEquals(stringValue(polySymbol.getStroke().getLineJoin()), "bevel");
    assertEquals(stringValue(polySymbol.getStroke().getLineCap()), "butt");
    assertEquals(floatValue(polySymbol.getStroke().getDashOffset()), 2.3f, DELTA);
    assertEquals(stringValue(polySymbol.getStroke().getColor()), "#404040");
    assertEquals(floatValue(polySymbol.getFill().getOpacity()), 1.0f, DELTA);
    assertEquals(stringValue(polySymbol.getFill().getColor()), "#808080");
    // Write test
    JAXBElement<org.geotoolkit.sld.xml.v100.PolygonSymbolizer> pvt = TRANSFORMER_OGC.visit(polySymbol, null);
    assertNotNull(pvt);
    assertEquals(pvt.getValue().getGeometry().getPropertyName().getContent(), "");
    assertNotNull(pvt.getValue().getStroke());
    assertNotNull(pvt.getValue().getFill());
    MARSHALLER.marshal(pvt, TEST_FILE_SE_SYMBOL_POLYGON);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Aggregations

PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)20 LineSymbolizer (org.opengis.style.LineSymbolizer)9 MutableStyle (org.geotoolkit.style.MutableStyle)8 Fill (org.opengis.style.Fill)8 PointSymbolizer (org.opengis.style.PointSymbolizer)7 Stroke (org.opengis.style.Stroke)7 Expression (org.opengis.filter.Expression)6 RasterSymbolizer (org.opengis.style.RasterSymbolizer)5 TextSymbolizer (org.opengis.style.TextSymbolizer)5 ArrayList (java.util.ArrayList)4 MapLayer (org.apache.sis.portrayal.MapLayer)4 MapLayers (org.apache.sis.portrayal.MapLayers)4 Test (org.junit.Test)4 Symbolizer (org.opengis.style.Symbolizer)4 Unit (javax.measure.Unit)3 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)3 CanvasDef (org.geotoolkit.display2d.service.CanvasDef)3 SceneDef (org.geotoolkit.display2d.service.SceneDef)3 Feature (org.opengis.feature.Feature)3 FeatureType (org.opengis.feature.FeatureType)3