Java Code Examples for org.geotools.styling.StyleFactory#createFeatureTypeStyle()

The following examples show how to use org.geotools.styling.StyleFactory#createFeatureTypeStyle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureLayerConfigurationPersistencyTest.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({"deprecation"})
private static Style createStyle() {
    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
    FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
    PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
    Fill fill = styleFactory.createFill(
            filterFactory.literal("#FFAA00"),
            filterFactory.literal(0.5)
    );
    symbolizer.setFill(fill);
    Rule rule = styleFactory.createRule();
    rule.setSymbolizers(new Symbolizer[]{symbolizer});
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    fts.setRules(new Rule[]{rule});

    Style style = styleFactory.createStyle();
    style.addFeatureTypeStyle(fts);
    return style;
}
 
Example 2
Source File: DistributedRenderCallback.java    From geowave with Apache License 2.0 6 votes vote down vote up
private static FeatureTypeStyle getDirectRasterStyle(
    final String geometryPropertyName,
    final Expression transformation) {
  final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
  final FeatureTypeStyle style = styleFactory.createFeatureTypeStyle();
  final Rule rule = styleFactory.createRule();
  rule.setName("distributed render - direct raster");
  rule.setTitle("Distributed Render - Direct Raster");

  final RasterSymbolizer symbolizer = styleFactory.createRasterSymbolizer();
  symbolizer.setGeometryPropertyName(geometryPropertyName);
  rule.symbolizers().add(symbolizer);
  style.rules().add(rule);
  style.setTransformation(transformation);
  return style;
}
 
Example 3
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createPolygonStyle() {
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();

    // create a partially opaque outline stroke
    final Stroke stroke = styleFactory.createStroke(
            filterFactory.literal(Color.BLACK),
            filterFactory.literal(1),
            filterFactory.literal(.5)
    );

    // create a partially opaque fill
    final Fill fill = styleFactory.createFill(
            filterFactory.literal(COLORS.next()),
            filterFactory.literal(.5)
    );

    // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
    final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);

    // make rule
    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
    final Style style = styleFactory.createStyle();
    style.getDescription().setTitle("Polygon Style");
    style.featureTypeStyles().add(fts);

    return style;
}
 
Example 4
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createPolygonStyle(final SimpleFeatureCollection features) {
    // get name based rule names
    final List<Rule> ruleList = new ArrayList<>();
    final Set<String> nameSet = new HashSet<>();

    // setup custom rules for polygons
    final SimpleFeatureIterator featureIterator = features.features();
    while (featureIterator.hasNext()) {
        final SimpleFeature feature = featureIterator.next();
        if (nameSet.add((String) feature.getAttribute(ATTRIBUTE))) {
            ruleList.add(makeFillRule(feature));
        }
    }

    // create a partially opaque outline stroke
    final Rule defaultRule = makeFillRule();
    defaultRule.setElseFilter(true);
    defaultRule.setName("Default Rule");
    ruleList.add(defaultRule);

    // Create rule defined style
    final Rule[] rules = ruleList.toArray(new Rule[ruleList.size()]);
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    final FeatureTypeStyle featureTypeStyle = styleFactory.createFeatureTypeStyle(rules);

    final StyleBuilder builder = new StyleBuilder();
    final Style style = builder.createStyle();
    style.getDescription().setTitle("Polygon Style");
    style.featureTypeStyles().add(featureTypeStyle);

    return style;
}
 
Example 5
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createLineStyle() {
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();

    // create a partially opaque outline stroke
    final Stroke stroke = styleFactory.createStroke(
            filterFactory.literal(Color.WHITE),
            filterFactory.literal(1),
            filterFactory.literal(.5)
    );

    // create a partially opaque fill
    final Fill fill = styleFactory.createFill(
            filterFactory.literal(Color.RED),
            filterFactory.literal(.25)
    );

    // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
    final PolygonSymbolizer sym = styleFactory.createPolygonSymbolizer(stroke, fill, null);

    // make rule
    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
    final Style style = styleFactory.createStyle();
    style.getDescription().setTitle("Line Style");
    style.featureTypeStyles().add(fts);

    return style;
}
 
Example 6
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Style createPointStyle() {
    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    org.opengis.filter.FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory();

    final Mark mark = styleFactory.getCircleMark();
    mark.setStroke(styleFactory.createStroke(filterFactory.literal(Color.BLUE), filterFactory.literal(1)));
    mark.setFill(styleFactory.createFill(filterFactory.literal(Color.CYAN)));

    final Graphic gr = styleFactory.getDefaultGraphic();
    gr.graphicalSymbols().clear();
    gr.graphicalSymbols().add(mark);
    gr.setSize(filterFactory.literal(5));

    // setting the geometryPropertyName arg to null signals that we want to draw the default geometry of features
    final PointSymbolizer sym = styleFactory.createPointSymbolizer(gr, null);

    // make rule
    final Rule rule = styleFactory.createRule();
    rule.symbolizers().add(sym);

    final FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
    final Style style = styleFactory.createStyle();
    style.getDescription().setTitle("Point Style");
    style.featureTypeStyles().add(fts);

    return style;
}
 
Example 7
Source File: SLDExternalImagesTest.java    From sldeditor with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates the test line.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestLine(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();

    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    NamedLayer namedLayer = styleFactory.createNamedLayer();

    sld.addStyledLayer(namedLayer);

    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);

    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();

    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();

    ftsList.add(fts);

    Rule rule = styleFactory.createRule();

    fts.rules().add(rule);

    LineSymbolizer line = styleFactory.createLineSymbolizer();

    rule.symbolizers().add(line);

    Graphic graphicFill = createGraphic(url, styleFactory);
    Graphic graphicStroke = createGraphic(url, styleFactory);

    Stroke stroke =
            styleFactory.createStroke(
                    null, null, null, null, null, null, null, graphicFill, graphicStroke);
    line.setStroke(stroke);

    return sld;
}
 
Example 8
Source File: SLDExternalImagesTest.java    From sldeditor with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Creates the test point.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestPoint(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();

    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    NamedLayer namedLayer = styleFactory.createNamedLayer();

    sld.addStyledLayer(namedLayer);

    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);

    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();

    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();

    ftsList.add(fts);

    Rule rule = styleFactory.createRule();

    fts.rules().add(rule);

    PointSymbolizer point = styleFactory.createPointSymbolizer();

    rule.symbolizers().add(point);

    Graphic graphic = createGraphic(url, styleFactory);

    point.setGraphic(graphic);

    return sld;
}
 
Example 9
Source File: SLDExternalImagesTest.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates the test polygon.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestPolygon(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();

    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

    NamedLayer namedLayer = styleFactory.createNamedLayer();

    sld.addStyledLayer(namedLayer);

    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);

    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();

    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();

    ftsList.add(fts);

    Rule rule = styleFactory.createRule();

    fts.rules().add(rule);

    PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer();

    rule.symbolizers().add(polygon);

    Graphic graphicFill1 = createGraphic(url, styleFactory);
    Graphic graphicFill2 = createGraphic(url, styleFactory);
    Graphic graphicStroke = createGraphic(url, styleFactory);
    Fill fill = styleFactory.createFill(null, null, null, graphicFill1);

    polygon.setFill(fill);

    Stroke stroke =
            styleFactory.createStroke(
                    null, null, null, null, null, null, null, graphicFill2, graphicStroke);
    polygon.setStroke(stroke);

    return sld;
}