Search in sources :

Example 1 with FeatureTypeStyle

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

the class StyleHelper method getSpectrumStyles.

/**
 * Returns a default style for the given type.
 *
 * @param dataSetTypes type definitions associated to their data set
 * @return the style
 */
public static Style getSpectrumStyles(SetMultimap<DataSet, TypeDefinition> dataSetTypes) {
    int defWidth = StylePreferences.getDefaultWidth();
    Style style = styleFactory.createStyle();
    GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
    for (DataSet dataSet : dataSetTypes.keySet()) {
        float saturation;
        float brightness;
        switch(dataSet) {
            case TRANSFORMED:
                saturation = 0.8f;
                brightness = 0.6f;
                break;
            case SOURCE:
            default:
                saturation = 0.75f;
                brightness = 0.8f;
                break;
        }
        Set<TypeDefinition> types = new HashSet<>(dataSetTypes.get(dataSet));
        Iterator<TypeDefinition> it = types.iterator();
        while (it.hasNext()) {
            TypeDefinition type = it.next();
            // remove invalid types
            if (type.getConstraint(AbstractFlag.class).isEnabled() || gss.getDefaultGeometry(type) == null) {
                it.remove();
            }
        }
        int numberOfTypes = types.size();
        int index = 0;
        for (TypeDefinition typeDef : types) {
            FeatureTypeStyle fts;
            // TODO based on default geometry?
            // polygon is always OK as it contains stroke and fill
            // Color color = generateRandomColor(Color.WHITE);
            Color color;
            if (numberOfTypes == 1) {
                color = generateRandomColor(saturation, brightness);
            } else {
                color = Color.getHSBColor((float) index / (float) numberOfTypes, saturation, brightness);
            }
            fts = createPolygonStyle(color, defWidth);
            fts.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
            style.featureTypeStyles().add(fts);
            index++;
        }
    }
    return style;
}
Also used : NameImpl(org.geotools.feature.NameImpl) DataSet(eu.esdihumboldt.hale.common.instance.model.DataSet) Color(java.awt.Color) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) HashSet(java.util.HashSet)

Example 2 with FeatureTypeStyle

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

the class StyleHelper method createPointStyle.

/**
 * Manually create a default point style.
 *
 * @param color the point color
 * @param width the line width
 * @return a Style for Point objects.
 */
@SuppressWarnings("unused")
private static FeatureTypeStyle createPointStyle(Color color, double width) {
    PointSymbolizer symbolizer = createPointSymbolizer(color, width);
    // symbolizer.getGraphic().setSize(filterFactory.literal(1));
    Rule rule = styleFactory.createRule();
    rule.symbolizers().add(symbolizer);
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    fts.rules().add(rule);
    return fts;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 3 with FeatureTypeStyle

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

the class StyleHelper method createLineStyle.

/**
 * Create a default line style.
 *
 * @param color the line color
 * @param width the line width
 * @return a Style for Line/LineString objects.
 */
@SuppressWarnings("unused")
private static FeatureTypeStyle createLineStyle(Color color, double width) {
    LineSymbolizer symbolizer = createLineSymbolizer(color, width);
    Rule rule = styleFactory.createRule();
    rule.symbolizers().add(symbolizer);
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    fts.rules().add(rule);
    return fts;
}
Also used : LineSymbolizer(org.geotools.styling.LineSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 4 with FeatureTypeStyle

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

the class FeatureStyleDialog method setStyle.

/**
 * Set the feature type style
 *
 * @param style the style
 */
public void setStyle(Style style) {
    // set the feature names
    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
        fts.featureTypeNames().clear();
        fts.featureTypeNames().add(new NameImpl(StyleHelper.getFeatureTypeName(type)));
    }
    this.style = style;
}
Also used : NameImpl(org.geotools.feature.NameImpl) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 5 with FeatureTypeStyle

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

the class RuleStylePage method getStyle.

/**
 * @see FeatureStylePage#getStyle(boolean)
 */
@Override
public Style getStyle(boolean force) throws Exception {
    updateCurrentRule();
    if (force || changed) {
        Rule[] ruleArray = new Rule[rules.size()];
        for (int i = 0; i < rules.size(); i++) {
            Rule rule = rules.get(i).getRule();
            // set else filter
            rule.setIsElseFilter(rule.getFilter() == null);
            // TODO other rule manipulation?
            ruleArray[i] = rule;
        }
        // create style
        // $NON-NLS-1$
        FeatureTypeStyle fts = styleBuilder.createFeatureTypeStyle("Feature", ruleArray);
        Style style = styleBuilder.createStyle();
        style.featureTypeStyles().add(fts);
        return style;
    } else {
        return null;
    }
}
Also used : Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Aggregations

FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)110 Style (org.geotools.styling.Style)81 Rule (org.geotools.styling.Rule)65 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)43 Test (org.junit.Test)42 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)24 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)21 LineSymbolizer (org.geotools.styling.LineSymbolizer)20 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)17 Symbolizer (org.geotools.styling.Symbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)14 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)12 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)12 TextSymbolizer (org.geotools.styling.TextSymbolizer)12 UserLayerImpl (org.geotools.styling.UserLayerImpl)12 ArrayList (java.util.ArrayList)11 LineStyle (org.polymap.core.style.model.feature.LineStyle)11