Java Code Examples for org.geotools.styling.Rule#setElseFilter()
The following examples show how to use
org.geotools.styling.Rule#setElseFilter() .
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: StyleGenerator.java From constellation with Apache License 2.0 | 5 votes |
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 2
Source File: StyleConverterServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private Rule createRule(Filter filter, FeatureStyleInfo featureStyle) throws LayerException { Rule rule = styleBuilder.createRule(createGeometrySymbolizer(featureStyle)); if (filter.equals(Filter.INCLUDE)) { rule.setElseFilter(true); } else { rule.setFilter(filter); } rule.setName(featureStyle.getName()); rule.setTitle(featureStyle.getName()); return rule; }
Example 3
Source File: UniqueValueRenderer.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Creates the filter. * * @param rule the rule * @param fieldsElement the fields element * @param fieldDelimiterElement the field delimiter element * @param value the value */ private void createFilter(Rule rule, JsonElement fieldsElement, JsonElement fieldDelimiterElement, String value) { if(fieldsElement == null) return; if(value == null) { rule.setElseFilter(true); } else { List<String> fieldList = new ArrayList<String>(); JsonArray fieldArray = fieldsElement.getAsJsonArray(); for(int fieldIndex = 0; fieldIndex < fieldArray.size(); fieldIndex ++) { JsonElement jsonFieldElement = fieldArray.get(fieldIndex); if(jsonFieldElement != null) { JsonObject fieldObj = jsonFieldElement.getAsJsonObject(); fieldList.add(fieldObj.get("name").getAsString()); } } String[] values = null; if(fieldDelimiterElement != null) { values = value.split(fieldDelimiterElement.getAsString()); } else { values = new String[1]; values[0] = value; } List<Filter> filterList = new ArrayList<Filter>(); int index = 0; while(index < values.length) { Expression fieldExpression = filterFactory.property(fieldList.get(index)); Expression valueExpression = filterFactory.literal(values[index]); PropertyIsEqualTo filter = filterFactory.equals(fieldExpression, valueExpression); filterList.add(filter); index ++; } Filter completeFilter = null; if(filterList.size() > 1) { completeFilter = filterFactory.and(filterList); } else if(filterList.size() == 1) { completeFilter = filterList.get(0); } rule.setFilter(completeFilter); } }
Example 4
Source File: RuleRenderVisitor.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Visit. * * @param rule the rule */ /* * (non-Javadoc) * * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.Rule) */ @SuppressWarnings("deprecation") @Override public void visit(Rule rule) { Rule copy = null; Symbolizer[] symsCopy = null; if (!displayOverall && ((symbolizerIndex >= 0) && (symbolizerIndex < rule.getSymbolizers().length))) { symsCopy = new Symbolizer[1]; symsCopy[0] = copy(rule.getSymbolizers()[symbolizerIndex]); } // As a catch all copy everything if (symsCopy == null) { symsCopy = rule.getSymbolizers(); for (int i = 0; i < symsCopy.length; i++) { symsCopy[i] = copy(symsCopy[i]); } } Graphic[] legendCopy = rule.getLegendGraphic(); for (int i = 0; i < legendCopy.length; i++) { legendCopy[i] = copy(legendCopy[i]); } Description descCopy = rule.getDescription(); descCopy = copy(descCopy); copy = sf.createRule(); copy.setSymbolizers(symsCopy); copy.setDescription(descCopy); copy.setLegendGraphic(legendCopy); copy.setName(rule.getName()); Filter filterCopy = null; copy.setFilter(filterCopy); copy.setElseFilter(rule.isElseFilter()); // Do not copy the min and max scales if (STRICT && !copy.equals(rule)) { throw new IllegalStateException("Was unable to duplicate provided Rule:" + rule); } pages.push(copy); }
Example 5
Source File: SymbolizerFilterVisitor.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
/** * Overridden to skip some symbolizers. */ @Override public void visit(Rule rule) { Rule copy = null; Filter filterCopy = null; if (rule.getFilter() != null) { Filter filter = rule.getFilter(); filterCopy = copy(filter); } List<Symbolizer> symsCopy = new ArrayList<Symbolizer>(); for (Symbolizer sym : rule.symbolizers()) { if (!skipSymbolizer(sym)) { Symbolizer symCopy = copy(sym); symsCopy.add(symCopy); } } Graphic[] legendCopy = rule.getLegendGraphic(); for (int i = 0; i < legendCopy.length; i++) { legendCopy[i] = copy(legendCopy[i]); } Description descCopy = rule.getDescription(); descCopy = copy(descCopy); copy = sf.createRule(); copy.symbolizers().addAll(symsCopy); copy.setDescription(descCopy); copy.setLegendGraphic(legendCopy); copy.setName(rule.getName()); copy.setFilter(filterCopy); copy.setElseFilter(rule.isElseFilter()); copy.setMaxScaleDenominator(rule.getMaxScaleDenominator()); copy.setMinScaleDenominator(rule.getMinScaleDenominator()); if (STRICT && !copy.equals(rule)) { throw new IllegalStateException( "Was unable to duplicate provided Rule:" + rule); } pages.push(copy); }