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;
}
}
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()]));
}
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;
}
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);
}
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);
}
Aggregations