Search in sources :

Example 31 with PolygonSymbolizer

use of org.geotools.styling.PolygonSymbolizer in project sldeditor by robward-scisys.

the class SLDTreeLeafPolygonTest method testRemoveStroke.

/**
 * Test method for {@link com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon#removeStroke(org.opengis.style.Symbolizer)}.
 */
@Test
public void testRemoveStroke() {
    SLDTreeLeafPolygon leaf = new SLDTreeLeafPolygon();
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    leaf.removeStroke(polygonSymbolizer);
    assertNull(polygonSymbolizer.getStroke());
}
Also used : PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) SLDTreeLeafPolygon(com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon) Test(org.junit.Test)

Example 32 with PolygonSymbolizer

use of org.geotools.styling.PolygonSymbolizer in project sldeditor by robward-scisys.

the class SLDTreeLeafPolygonTest method testHasStroke.

/**
 * Test method for {@link com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon#hasStroke(org.opengis.style.Symbolizer)}.
 */
@Test
public void testHasStroke() {
    SLDTreeLeafPolygon leaf = new SLDTreeLeafPolygon();
    assertFalse(leaf.hasStroke(null));
    assertFalse(leaf.hasStroke(DefaultSymbols.createDefaultPointSymbolizer()));
    PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    assertTrue(leaf.hasStroke(polygonSymbolizer));
    polygonSymbolizer.setStroke(null);
    assertFalse(leaf.hasStroke(polygonSymbolizer));
}
Also used : PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) SLDTreeLeafPolygon(com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon) Test(org.junit.Test)

Example 33 with PolygonSymbolizer

use of org.geotools.styling.PolygonSymbolizer in project polymap4-core by Polymap4.

the class DefaultStyles method createPolygonStyle.

/**
 * Create a Style to draw polygon features with a thin blue outline and
 * a cyan fill
 */
public static Style createPolygonStyle(Style style) {
    // create a partially opaque outline stroke
    Stroke stroke = sf.createStroke(ff.literal(Color.DARK_GRAY), ff.literal(0.5), ff.literal(0.5));
    // create a partial opaque fill
    Fill fill = sf.createFill(ff.literal(Color.CYAN), ff.literal(0.5));
    /*
         * Setting the geometryPropertyName arg to null signals that we want to
         * draw the default geometry of features
         */
    PolygonSymbolizer sym = sf.createPolygonSymbolizer(stroke, fill, null);
    Rule rule = sf.createRule();
    rule.setName("Rule for PolygonSymbolizer");
    rule.symbolizers().add(sym);
    style.featureTypeStyles().get(0).rules().add(rule);
    return style;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Rule(org.geotools.styling.Rule)

Example 34 with PolygonSymbolizer

use of org.geotools.styling.PolygonSymbolizer in project polymap4-core by Polymap4.

the class PolygonStyleSerializer method serialize.

@Override
public void serialize(PolygonStyle style, Style result) {
    // default symbolizer
    PolygonSymbolizer polygon = sf.createPolygonSymbolizer();
    polygon.setFill(sf.getDefaultFill());
    polygon.setStroke(sf.getDefaultStroke());
    FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, polygon);
    fts.setName(style.title.opt().orElse("PolygonStyle"));
    fts.getDescription().setTitle(style.title.opt().orElse("PolygonStyle"));
    accessor.set(rule -> (PolygonSymbolizer) rule.symbolizers().get(0));
    // fill
    style.fill.opt().ifPresent(fill -> {
        new FillCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).getFill()).serialize(fill, fts);
    });
    // stroke
    style.stroke.opt().ifPresent(stroke -> {
        new StrokeCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).getStroke()).serialize(stroke, fts);
    });
}
Also used : PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) Style(org.geotools.styling.Style) Context(org.polymap.core.style.serialize.FeatureStyleSerializer.Context) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 35 with PolygonSymbolizer

use of org.geotools.styling.PolygonSymbolizer in project hale by halestudio.

the class DefinitionImages method getLegendImage.

/**
 * Get a legend image for a given type definition
 *
 * @param type the type definition
 * @param dataSet the data set the type definition belongs to
 * @param definedOnly if only for defined styles a image shall be created
 * @return the legend image or <code>null</code>
 */
protected BufferedImage getLegendImage(TypeDefinition type, DataSet dataSet, boolean definedOnly) {
    StyleService ss = PlatformUI.getWorkbench().getService(StyleService.class);
    Style style = (definedOnly) ? (ss.getDefinedStyle(type)) : (ss.getStyle(type, dataSet));
    if (style == null) {
        return null;
    }
    // create a dummy feature based on the style
    Drawer d = Drawer.create();
    SimpleFeature feature = null;
    Symbolizer[] symbolizers = SLD.symbolizers(style);
    if (symbolizers.length > 0) {
        Symbolizer symbolizer = symbolizers[0];
        if (symbolizer instanceof LineSymbolizer) {
            feature = d.feature(d.line(LINE_POINTS));
        } else if (symbolizer instanceof PointSymbolizer) {
            feature = d.feature(d.point(WIDTH / 2, HEIGHT / 2));
        }
        if (symbolizer instanceof PolygonSymbolizer) {
            feature = d.feature(d.polygon(POLY_POINTS));
        }
    }
    if (feature != null) {
        BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
        // GraphicsEnvironment.getLocalGraphicsEnvironment().
        // getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(WIDTH, HEIGHT,
        // Transparency.TRANSLUCENT);
        // use white background to have a neutral color even if selected
        Color bg = Color.WHITE;
        Graphics2D g = image.createGraphics();
        try {
            g.setColor(bg);
            g.fillRect(0, 0, WIDTH, HEIGHT);
        } finally {
            g.dispose();
        }
        d.drawDirect(image, feature, style);
        return image;
    }
    return null;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) StyleService(eu.esdihumboldt.hale.ui.common.service.style.StyleService) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Color(java.awt.Color) Style(org.geotools.styling.Style) Drawer(org.geotools.legend.Drawer) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)65 Test (org.junit.Test)28 PointSymbolizer (org.geotools.styling.PointSymbolizer)25 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)19 Rule (org.geotools.styling.Rule)18 Style (org.geotools.styling.Style)18 Symbolizer (org.geotools.styling.Symbolizer)15 Fill (org.geotools.styling.Fill)14 NamedLayer (org.geotools.styling.NamedLayer)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 Stroke (org.geotools.styling.Stroke)10 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)9 TextSymbolizer (org.geotools.styling.TextSymbolizer)9 SLDTreeLeafPolygon (com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon)8 Graphic (org.geotools.styling.Graphic)8 ArrayList (java.util.ArrayList)7 Expression (org.opengis.filter.expression.Expression)7 JsonObject (com.google.gson.JsonObject)5 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)5