Search in sources :

Example 71 with Rule

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

the class RuleStylePage method addRule.

/**
 * Add a new {@link Rule}
 */
protected void addRule() {
    SymbolizerDialog symDlg = new SymbolizerDialog(getShell());
    symDlg.open();
    Symbolizer symbolizer = symDlg.getSymbolizer();
    if (symbolizer != null) {
        Rule rule = styleBuilder.createRule(symbolizer);
        RuleItem item = new RuleItem(rule);
        rules.add(item);
        listViewer.add(item);
        updateButtonState();
        changed = true;
    }
}
Also used : Rule(org.geotools.styling.Rule) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer)

Example 72 with Rule

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

the class StyleServiceImpl method getSelectedStyle.

/**
 * Convert the given style for selection
 *
 * @param fts the feature type style to convert
 *
 * @return the converted feature type style
 */
@SuppressWarnings("deprecation")
private FeatureTypeStyle getSelectedStyle(FeatureTypeStyle fts) {
    List<Rule> rules = fts.rules();
    List<Rule> newRules = new ArrayList<Rule>();
    for (Rule rule : rules) {
        Symbolizer[] symbolizers = rule.getSymbolizers();
        List<Symbolizer> newSymbolizers = new ArrayList<Symbolizer>();
        for (Symbolizer symbolizer : symbolizers) {
            // get symbolizers
            List<Symbolizer> addSymbolizers = getSelectionSymbolizers(symbolizer);
            if (addSymbolizers != null) {
                newSymbolizers.addAll(addSymbolizers);
            }
        }
        // create new rule
        Rule newRule = styleBuilder.createRule(newSymbolizers.toArray(new Symbolizer[newSymbolizers.size()]));
        newRule.setFilter(rule.getFilter());
        newRule.setIsElseFilter(rule.isElseFilter());
        newRule.setName(rule.getName());
        newRules.add(newRule);
    }
    // FIXME use featureTypeNames list
    return styleBuilder.createFeatureTypeStyle(fts.getFeatureTypeName(), newRules.toArray(new Rule[newRules.size()]));
}
Also used : ArrayList(java.util.ArrayList) Rule(org.geotools.styling.Rule) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer)

Example 73 with Rule

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

the class StyledInstanceMarker method honorRules.

/**
 * Checks if there is a rule for the certain Instance
 *
 * @param context the context
 * @return a certain style rule for the instance, else-rule if nothing found
 *         or null if there is no else-rule
 */
private Rule honorRules(InstanceWaypoint context) {
    Style style = getStyle(context);
    Rule[] rules = SLD.rules(style);
    if (rules == null || rules.length == 0) {
        return null;
    }
    // sort the elserules at the end
    if (rules.length > 1) {
        rules = sortRules(rules);
    }
    // if rule exists
    InstanceReference ir = context.getValue();
    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    boolean instanceInitialized = false;
    // instance variable - only initialize if needed
    Instance inst = null;
    for (int i = 0; i < rules.length; i++) {
        if (rules[i].getFilter() != null) {
            if (!instanceInitialized) {
                // initialize instance (as it is needed for the filter)
                inst = is.getInstance(ir);
                instanceInitialized = true;
            }
            if (rules[i].getFilter().evaluate(inst)) {
                return rules[i];
            }
        } else // if a rule exist without a filter and without being an
        // else-filter,
        // the found rule applies to all types
        {
            if (!rules[i].isElseFilter()) {
                return rules[i];
            }
        }
    }
    // if there is no appropriate rule, check if there is an else-rule
    for (int i = 0; i < rules.length; i++) {
        if (rules[i].isElseFilter()) {
            return rules[i];
        }
    }
    // return null if no rule was found
    return null;
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) Style(org.geotools.styling.Style) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) Rule(org.geotools.styling.Rule) SelectableWaypoint(de.fhg.igd.mapviewer.waypoints.SelectableWaypoint) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 74 with Rule

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

the class SLDUtilsTest method testFindRule.

@Test
public void testFindRule() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
    Rule actualRule = SLDUtils.findRule(sld, rule, sldCopy);
    assertNotNull(actualRule);
    assertEquals(rule.getName(), actualRule.getName());
    actualRule = SLDUtils.findRule(sld, null, sldCopy);
    assertNull(actualRule);
    actualRule = SLDUtils.findRule(sld, rule, null);
    assertNull(actualRule);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Test(org.junit.Test)

Example 75 with Rule

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

the class SLDUtilsTest method testFindSymbolizer.

@Test
public void testFindSymbolizer() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
    Symbolizer actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, sldCopy);
    assertNotNull(actualSymbolizer);
    assertEquals(symbolizer.getLabel().toString(), ((TextSymbolizer) actualSymbolizer).getLabel().toString());
    actualSymbolizer = SLDUtils.findSymbolizer(sld, null, sldCopy);
    assertNull(actualSymbolizer);
    actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, null);
    assertNull(actualSymbolizer);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) Test(org.junit.Test)

Aggregations

Rule (org.geotools.styling.Rule)110 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)65 Style (org.geotools.styling.Style)60 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)51 Test (org.junit.Test)48 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)28 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)26 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 Symbolizer (org.geotools.styling.Symbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)19 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)16 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)16 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)13 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)11 ArrayList (java.util.ArrayList)11 Filter (org.opengis.filter.Filter)11 UserLayerImpl (org.geotools.styling.UserLayerImpl)10 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)8