Search in sources :

Example 36 with PointSymbolizer

use of org.geotools.styling.PointSymbolizer 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 37 with PointSymbolizer

use of org.geotools.styling.PointSymbolizer 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 38 with PointSymbolizer

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

Example 39 with PointSymbolizer

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

the class StyledInstanceMarker method strokeStyle.

/**
 * retrieves the stroke for the map marker
 *
 * @param rule a certain rule to apply, maybe null
 * @param context the InstanceWayPoint, wich gets marked
 */
private synchronized void strokeStyle(Rule rule, InstanceWaypoint context) {
    // retrieve stroke
    Stroke stroke = null;
    for (int i = 0; rule != null && stroke == null && i < rule.getSymbolizers().length; i++) {
        if (rule.getSymbolizers()[i] instanceof LineSymbolizer) {
            stroke = SLD.stroke((LineSymbolizer) rule.getSymbolizers()[i]);
        } else if (rule.getSymbolizers()[i] instanceof PolygonSymbolizer) {
            stroke = SLD.stroke((PolygonSymbolizer) rule.getSymbolizers()[i]);
        } else if (rule.getSymbolizers()[i] instanceof PointSymbolizer) {
            stroke = SLD.stroke((PointSymbolizer) rule.getSymbolizers()[i]);
        }
    }
    // if we have a stroke now
    if (stroke != null) {
        // XXX is there any Geotools stroke to AWT stroke lib/code
        // somewhere?!
        // XXX have a look at the renderer code (StreamingRenderer)
        // stroke color
        Color sldColor = SLD.color(stroke);
        double opacity = SLD.opacity(stroke);
        if (Double.isNaN(opacity)) {
            // fall back to default opacity
            opacity = StyleHelper.DEFAULT_FILL_OPACITY;
        }
        if (sldColor != null) {
            styleStrokeColor = new Color(sldColor.getRed(), sldColor.getGreen(), sldColor.getBlue(), (int) (opacity * 255));
        } else {
            styleStrokeColor = super.getBorderColor(context);
        }
        // stroke width
        int strokeWidth = SLD.width(stroke);
        if (strokeWidth == SLD.NOTFOUND) {
            // fall back to default width
            strokeWidth = StylePreferences.getDefaultWidth();
        }
        styleStroke = new BasicStroke(strokeWidth);
    } else {
        styleStroke = null;
        styleStrokeColor = null;
    }
}
Also used : BasicStroke(java.awt.BasicStroke) PointSymbolizer(org.geotools.styling.PointSymbolizer) BasicStroke(java.awt.BasicStroke) Stroke(org.geotools.styling.Stroke) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Color(java.awt.Color) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 40 with PointSymbolizer

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

the class SLDUtilsTest method testCreateSLDFromStringGeoServer.

@Test
public void testCreateSLDFromStringGeoServer() {
    SLDData sldData = new SLDData(null, expectedSld);
    String geoserverUrl = "http://localhost:8080/geoserver";
    GeoServerConnection connectionData = new GeoServerConnection();
    try {
        connectionData.setUrl(new URL(geoserverUrl));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    sldData.setConnectionData(connectionData);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(null);
    assertNull(sld);
    sld = SLDUtils.createSLDFromString(sldData);
    StyledLayer[] styledLayers = sld.getStyledLayers();
    NamedLayer namedLayer = (NamedLayer) styledLayers[0];
    Style[] actualStyles = namedLayer.getStyles();
    PointSymbolizer pointSymbolizer = (PointSymbolizer) actualStyles[0].featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
    MarkImpl mark = (MarkImpl) pointSymbolizer.getGraphic().graphicalSymbols().get(0);
    assertEquals("circle", mark.getWellKnownName().toString());
    // Check resource locator
    geoserverUrl = geoserverUrl + "/styles/";
    assertTrue(geoserverUrl.compareTo(sldData.getResourceLocator().toExternalForm()) == 0);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) PointSymbolizer(org.geotools.styling.PointSymbolizer) MalformedURLException(java.net.MalformedURLException) StyledLayer(org.geotools.styling.StyledLayer) MarkImpl(org.geotools.styling.MarkImpl) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) URL(java.net.URL) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) NamedLayer(org.geotools.styling.NamedLayer) Test(org.junit.Test)

Aggregations

PointSymbolizer (org.geotools.styling.PointSymbolizer)67 Test (org.junit.Test)32 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)25 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)23 LineSymbolizer (org.geotools.styling.LineSymbolizer)23 Style (org.geotools.styling.Style)22 Rule (org.geotools.styling.Rule)19 Graphic (org.geotools.styling.Graphic)16 NamedLayer (org.geotools.styling.NamedLayer)13 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)13 Symbolizer (org.geotools.styling.Symbolizer)12 TextSymbolizer (org.geotools.styling.TextSymbolizer)10 GraphicalSymbol (org.opengis.style.GraphicalSymbol)9 SLDTreeLeafPoint (com.sldeditor.common.tree.leaf.SLDTreeLeafPoint)8 MarkImpl (org.geotools.styling.MarkImpl)8 Point (com.vividsolutions.jts.geom.Point)7 FeatureStyle (org.polymap.core.style.model.FeatureStyle)7 PointStyle (org.polymap.core.style.model.feature.PointStyle)7 Fill (org.geotools.styling.Fill)6 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)6