Search in sources :

Example 61 with PointSymbolizer

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

the class DefaultStyles method createPointStyle.

/**
 * Create a Style to draw point features as circles with blue outlines
 * and cyan fill
 */
public static Style createPointStyle(Style style) {
    Graphic gr = sf.createDefaultGraphic();
    Mark mark = sf.getCircleMark();
    mark.setStroke(sf.createStroke(ff.literal(Color.RED), ff.literal(1.5)));
    mark.setFill(sf.createFill(ff.literal(Color.YELLOW)));
    gr.graphicalSymbols().clear();
    gr.graphicalSymbols().add(mark);
    gr.setSize(ff.literal(8));
    /*
         * Setting the geometryPropertyName arg to null signals that we want to draw
         * the default geometry of features
         */
    PointSymbolizer sym = sf.createPointSymbolizer(gr, null);
    Rule rule = sf.createRule();
    rule.symbolizers().add(sym);
    rule.setName("Rule for PointSymbolizer");
    style.featureTypeStyles().get(0).rules().add(rule);
    return style;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Graphic(org.geotools.styling.Graphic) Mark(org.geotools.styling.Mark) Rule(org.geotools.styling.Rule)

Example 62 with PointSymbolizer

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

the class FilterTest method visiblePoint.

@Test
public void visiblePoint() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    assertTrue(point.visibleIf.get() instanceof ConstantFilter);
    point.visibleIf.createValue(initializeFilter(ff.equals(ff.property("prop"), ff.literal("literal"))));
    point.diameter.createValue(ConstantNumber.defaults(23.0));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    org.geotools.styling.Style style = repo.serializedFeatureStyle(fs.id(), org.geotools.styling.Style.class).get();
    Rule rule = style.featureTypeStyles().get(0).rules().get(0);
    assertTrue(rule.getFilter() instanceof PropertyIsEqualTo);
    PropertyIsEqualTo filter = (PropertyIsEqualTo) rule.getFilter();
    assertTrue(filter.getExpression1() instanceof PropertyName);
    assertEquals("prop", ((PropertyName) filter.getExpression1()).getPropertyName());
    assertTrue(filter.getExpression2() instanceof Literal);
    assertEquals("literal", ((Literal) filter.getExpression2()).getValue());
    PointSymbolizer sym = (PointSymbolizer) rule.getSymbolizers()[0];
    assertEquals(SLDSerializer2.ff.literal(23.0), sym.getGraphic().getSize());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Literal(org.opengis.filter.expression.Literal) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) Rule(org.geotools.styling.Rule) Test(org.junit.Test)

Example 63 with PointSymbolizer

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

the class StyleModelTest method testScaleMappedNumbers.

@Test
public void testScaleMappedNumbers() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    point.diameter.createValue(ScaleMappedPrimitives.defaults()).add(0, 1, new Double(1)).add(1, 2, new Double(2)).add(2, Double.POSITIVE_INFINITY, new Double(3));
    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(3, fts.rules().size());
    assertEqualsLiteral(1.0, ((PointSymbolizer) fts.rules().get(0).symbolizers().get(0)).getGraphic().getSize());
    assertEqualsLiteral(2.0, ((PointSymbolizer) fts.rules().get(1).symbolizers().get(0)).getGraphic().getSize());
    assertEqualsLiteral(3.0, ((PointSymbolizer) fts.rules().get(2).symbolizers().get(0)).getGraphic().getSize());
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) 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) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Example 64 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.map.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 65 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)

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 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 ArrayList (java.util.ArrayList)5