Search in sources :

Example 26 with LineSymbolizer

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

the class StyleModelTest method testSimpleLine.

@Test
public void testSimpleLine() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    LineStyle style = fs.members().createElement(LineStyle.defaults);
    assertTrue(style.visibleIf.get() instanceof ConstantFilter);
    style.fill.get().color.createValue(ConstantColor.defaults(0, 0, 0));
    style.fill.get().width.createValue(ConstantNumber.defaults(5.0));
    style.fill.get().opacity.createValue(ConstantNumber.defaults(0.0));
    style.stroke.get().color.createValue(ConstantColor.defaults(100, 100, 100));
    style.stroke.get().width.createValue(ConstantNumber.defaults(5.0));
    style.stroke.get().opacity.createValue(ConstantNumber.defaults(0.5));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    Style result = repo.serializedFeatureStyle(fs.id(), Style.class).get();
    assertEquals(1, result.featureTypeStyles().size());
    FeatureTypeStyle fts = result.featureTypeStyles().get(0);
    assertEquals(1, fts.rules().size());
    Rule rule = fts.rules().get(0);
    assertEquals(0, rule.getMinScaleDenominator(), 0);
    assertEquals(Double.POSITIVE_INFINITY, rule.getMaxScaleDenominator(), 0);
    assertEquals(2, rule.symbolizers().size());
    assertNull(rule.getFilter());
    LineSymbolizer strokeLine = (LineSymbolizer) rule.symbolizers().get(0);
    assertEqualsLiteral(0.5, strokeLine.getStroke().getOpacity());
    assertEqualsLiteral(15.0, strokeLine.getStroke().getWidth());
    LineSymbolizer fillLine = (LineSymbolizer) rule.symbolizers().get(1);
    assertEqualsLiteral(0.0, fillLine.getStroke().getOpacity());
    assertEqualsLiteral(5.0, fillLine.getStroke().getWidth());
}
Also used : LineStyle(org.polymap.core.style.model.feature.LineStyle) LineSymbolizer(org.geotools.styling.LineSymbolizer) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Style(org.geotools.styling.Style) ConstantStrokeDashStyle(org.polymap.core.style.model.feature.ConstantStrokeDashStyle) ConstantStrokeJoinStyle(org.polymap.core.style.model.feature.ConstantStrokeJoinStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) ConstantStrokeCapStyle(org.polymap.core.style.model.feature.ConstantStrokeCapStyle) StrokeDashStyle(org.polymap.core.style.model.feature.StrokeDashStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Example 27 with LineSymbolizer

use of org.geotools.styling.LineSymbolizer 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)

Example 28 with LineSymbolizer

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

the class SimpleLineStylePage method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    // create new controls
    Composite page = new Composite(parent, SWT.NONE);
    RowLayout layout = new RowLayout(SWT.HORIZONTAL);
    page.setLayout(layout);
    Style style = getParent().getStyle();
    LineSymbolizer line = null;
    try {
        Symbolizer[] symbolizers = SLD.symbolizers(style);
        for (Symbolizer symbol : symbolizers) {
            if (symbol instanceof LineSymbolizer) {
                line = (LineSymbolizer) symbol;
                break;
            }
        }
    } catch (Exception e) {
    // ignore
    }
    if (line == null) {
        line = styleBuilder.createLineSymbolizer();
    }
    lineEditor = new LineSymbolizerEditor(page, line);
    setControl(page);
}
Also used : LineSymbolizerEditor(eu.esdihumboldt.hale.ui.style.editors.LineSymbolizerEditor) Composite(org.eclipse.swt.widgets.Composite) RowLayout(org.eclipse.swt.layout.RowLayout) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer)

Example 29 with LineSymbolizer

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

the class SimplePointStylePage method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    // create new controls
    Composite page = new Composite(parent, SWT.NONE);
    RowLayout layout = new RowLayout(SWT.HORIZONTAL);
    page.setLayout(layout);
    Style style = getParent().getStyle();
    PointSymbolizer point = null;
    try {
        Symbolizer[] symbolizers = SLD.symbolizers(style);
        for (Symbolizer symbol : symbolizers) {
            if (symbol instanceof LineSymbolizer) {
                point = (PointSymbolizer) symbol;
                break;
            }
        }
    } catch (Exception e) {
    // ignore
    }
    if (point == null) {
        point = styleBuilder.createPointSymbolizer();
    }
    pointEditor = new PointSymbolizerEditor(page, point);
    setControl(page);
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Composite(org.eclipse.swt.widgets.Composite) PointSymbolizerEditor(eu.esdihumboldt.hale.ui.style.editors.PointSymbolizerEditor) RowLayout(org.eclipse.swt.layout.RowLayout) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer)

Example 30 with LineSymbolizer

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

the class StyleServiceImpl method getSelectionSymbolizers.

/**
 * Get the symbolizers representing the given symbolizer for a selection
 *
 * @param symbolizer the symbolizer
 *
 * @return the selection symbolizers
 */
private List<Symbolizer> getSelectionSymbolizers(Symbolizer symbolizer) {
    List<Symbolizer> result = new ArrayList<Symbolizer>();
    Color color = StylePreferences.getSelectionColor();
    int width = StylePreferences.getSelectionWidth();
    if (symbolizer instanceof PolygonSymbolizer) {
        result.add(StyleHelper.createPolygonSymbolizer(color, width));
    } else if (symbolizer instanceof LineSymbolizer) {
        result.add(StyleHelper.createLineSymbolizer(color, width));
    } else if (symbolizer instanceof PointSymbolizer) {
        result.add(StyleHelper.mutatePointSymbolizer((PointSymbolizer) symbolizer, color, width));
    // result.add(createPointSymbolizer(color, width));
    } else {
    // do not fall-back to original symbolizer cause we are painting
    // over it
    // result.add(symbolizer);
    }
    return result;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Color(java.awt.Color) LineSymbolizer(org.geotools.styling.LineSymbolizer) ArrayList(java.util.ArrayList) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer)

Aggregations

LineSymbolizer (org.geotools.styling.LineSymbolizer)51 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)24 PointSymbolizer (org.geotools.styling.PointSymbolizer)23 Test (org.junit.Test)18 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)17 Style (org.geotools.styling.Style)17 Rule (org.geotools.styling.Rule)16 Symbolizer (org.geotools.styling.Symbolizer)15 Stroke (org.geotools.styling.Stroke)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)10 TextSymbolizer (org.geotools.styling.TextSymbolizer)10 NamedLayer (org.geotools.styling.NamedLayer)9 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)7 StyledLayer (org.geotools.styling.StyledLayer)5 JsonObject (com.google.gson.JsonObject)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 Graphic (org.geotools.styling.Graphic)4 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)4 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)3 SLDTreeLeafLine (com.sldeditor.common.tree.leaf.SLDTreeLeafLine)3