Java Code Examples for org.geotools.styling.FeatureTypeStyle#rules()
The following examples show how to use
org.geotools.styling.FeatureTypeStyle#rules() .
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: ExtractValidFieldTypes.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Process styles. * * @param fieldsUpdated the fields updated * @param styleList the style list * @param featureList the feature list * @return true, if successful */ private static boolean processStyles( boolean fieldsUpdated, List<org.geotools.styling.Style> styleList, FeatureSource<SimpleFeatureType, SimpleFeature> featureList) { for (Style style : styleList) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { Object drawMe = null; try { drawMe = featureList.getFeatures().features().next(); } catch (IOException | NoSuchElementException e) { ConsoleManager.getInstance().exception(ExtractValidFieldTypes.class, e); } fieldsUpdated = processRule(fieldsUpdated, rule, drawMe); } } } return fieldsUpdated; }
Example 2
Source File: RenderSymbol.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Should render symbol. * * @param style the style * @param ruleToRender the rule to render * @return true, if successful */ private boolean shouldRenderSymbol( Style style, FeatureTypeStyle ftsToRender, Rule ruleToRender) { if (ruleToRender == null) { return true; } for (FeatureTypeStyle fts : style.featureTypeStyles()) { if (fts == ftsToRender) { for (Rule rule : fts.rules()) { if (rule == ruleToRender) { return true; } } } } return false; }
Example 3
Source File: SLDTree.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Populate styles. * * @param styledLayerTreeNode the styled layer tree node * @param styleList the style list */ private void populateStyles(DefaultMutableTreeNode styledLayerTreeNode, List<Style> styleList) { for (Style style : styleList) { DefaultMutableTreeNode styleTreeNode = addObject(styledLayerTreeNode, style, true); for (FeatureTypeStyle fts : style.featureTypeStyles()) { DefaultMutableTreeNode ftsTreeNode = addObject(styleTreeNode, fts, true); for (Rule rule : fts.rules()) { DefaultMutableTreeNode ruleTreeNode = addObject(ftsTreeNode, rule, true); for (Symbolizer symbolizer : rule.symbolizers()) { populateSymbolizer(ruleTreeNode, symbolizer); } } } } }
Example 4
Source File: SLDUtils.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Traverse symbolizers. * * @param sld the sld * @param traverseSymbolizersInterface the traverse symbolizers interface */ public static void traverseSymbolizers( StyledLayerDescriptor sld, TraverseSymbolizersInterface traverseSymbolizersInterface) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { List<Style> styleList = SLDUtils.getStylesList(styledLayer); for (Style style : styleList) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { for (org.opengis.style.Symbolizer symbolizer : rule.symbolizers()) { processSymbolizer(symbolizer, traverseSymbolizersInterface); } } } } } }
Example 5
Source File: SelectedSymbol.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Checks if the selected Style contains a raster symbol. * * @return true, if is raster symbol */ public boolean isRasterSymbol() { Style style = getStyle(); if (style != null) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { for (Symbolizer symbolizer : rule.symbolizers()) { if (symbolizer instanceof RasterSymbolizer) { return true; } } } } } return false; }
Example 6
Source File: FeatureTypeStyleDetails.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** Update symbol. */ private void updateSymbol() { if (!Controller.getInstance().isPopulating()) { StandardData standardData = getStandardData(); Expression transformation = fieldConfigVisitor.getExpression(FieldIdEnum.TRANSFORMATION); FeatureTypeStyle existingFTS = SelectedSymbol.getInstance().getFeatureTypeStyle(); if (existingFTS != null) { List<org.opengis.style.Rule> newRuleList = new ArrayList<>(); for (org.opengis.style.Rule rule : existingFTS.rules()) { newRuleList.add(rule); } FeatureTypeStyle fts = getStyleFactory() .featureTypeStyle( standardData.getName(), (org.opengis.style.Description) standardData.getDescription(), existingFTS.getFeatureInstanceIDs(), existingFTS.featureTypeNames(), existingFTS.semanticTypeIdentifiers(), newRuleList); if (transformation != null) { fts.setTransformation(transformation); } if (vendorOptionFTSFactory != null) { vendorOptionFTSFactory.updateSymbol(fts); } SelectedSymbol.getInstance().replaceFeatureTypeStyle(fts); this.fireUpdateSymbol(); } } }
Example 7
Source File: MinimumVersion.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Find minimum version. * * @param sld the sld */ public void findMinimumVersion(StyledLayerDescriptor sld) { vendorOptionsPresentList.clear(); Object parentObj = null; if ((sld != null) && (uiMgr != null)) { uiMgr.getMinimumVersion(parentObj, sld, vendorOptionsPresentList); List<StyledLayer> styledLayerList = sld.layers(); parentObj = sld; for (StyledLayer styledLayer : styledLayerList) { uiMgr.getMinimumVersion(parentObj, styledLayer, vendorOptionsPresentList); List<Style> styleList = SLDUtils.getStylesList(styledLayer); parentObj = styledLayer; for (Style style : styleList) { uiMgr.getMinimumVersion(parentObj, style, vendorOptionsPresentList); parentObj = style; for (FeatureTypeStyle fts : style.featureTypeStyles()) { uiMgr.getMinimumVersion(parentObj, fts, vendorOptionsPresentList); parentObj = fts; for (Rule rule : fts.rules()) { uiMgr.getMinimumVersion(parentObj, rule, vendorOptionsPresentList); parentObj = rule; for (Symbolizer symbolizer : rule.symbolizers()) { uiMgr.getMinimumVersion( parentObj, symbolizer, vendorOptionsPresentList); } } } } } } removeStrictSLD(); }
Example 8
Source File: FeatureTypeStyleWrapper.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public FeatureTypeStyleWrapper( FeatureTypeStyle featureTypeStyle, StyleWrapper parent ) { this.featureTypeStyle = featureTypeStyle; this.parent = parent; List<Rule> rules = featureTypeStyle.rules(); for( Rule rule : rules ) { RuleWrapper ruleWrapper = new RuleWrapper(rule, this); rulesWrapperList.add(ruleWrapper); } }
Example 9
Source File: BatchUpdateFontUtils.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Contains font details. * * @param sldData the sld data * @return the scale sld data, returns null if invalid SLD string supplied. */ public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) { List<BatchUpdateFontData> dataList = null; StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData); if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { if (styledLayer instanceof NamedLayerImpl) { NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer; for (Style style : namedLayerImpl.styles()) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { for (Symbolizer symbolizer : rule.symbolizers()) { if (symbolizer instanceof TextSymbolizer) { TextSymbolizer textSymbol = (TextSymbolizer) symbolizer; Font font = textSymbol.getFont(); if (font != null) { if (dataList == null) { dataList = new ArrayList<>(); } BatchUpdateFontData fontSLDData = new BatchUpdateFontData(sld, sldData); fontSLDData.setNamedLayer(namedLayerImpl.getName()); fontSLDData.setFeatureTypeStyle(fts.getName()); fontSLDData.setStyle(style.getName()); fontSLDData.setRule(rule); fontSLDData.setSymbolizer(textSymbol); fontSLDData.setFont(font); dataList.add(fontSLDData); } } } } } } } } } return dataList; }
Example 10
Source File: ScalePanelUtils.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Extracts all the rule scales. * * @param sldData the sld data * @return the scale sld data */ public static List<ScaleSLDData> containsScales(SLDDataInterface sldData) { List<ScaleSLDData> dataList = null; StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData); if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { if (styledLayer instanceof NamedLayerImpl) { NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer; for (Style style : namedLayerImpl.styles()) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { double minScale = rule.getMinScaleDenominator(); double maxScale = rule.getMaxScaleDenominator(); if (isMinScaleSet(minScale) || isMaxScaleSet(maxScale)) { if (dataList == null) { dataList = new ArrayList<>(); } ScaleSLDData scaleSLDData = new ScaleSLDData(sld, sldData); scaleSLDData.setNamedLayer(namedLayerImpl.getName()); scaleSLDData.setFeatureTypeStyle(fts.getName()); scaleSLDData.setStyle(style.getName()); scaleSLDData.setRule(rule); if (isMinScaleSet(minScale)) { scaleSLDData.setMinScale(minScale); } if (isMaxScaleSet(maxScale)) { scaleSLDData.setMaxScale(maxScale); } dataList.add(scaleSLDData); } } } } } } } return dataList; }
Example 11
Source File: SLDUtils.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Find symbolizer. * * @param sld the sld * @param symbolizerToFind the symbolizer to find * @param otherSLD the other SLD * @return the symbolizer */ public static Symbolizer findSymbolizer( StyledLayerDescriptor sld, Symbolizer symbolizerToFind, StyledLayerDescriptor otherSLD) { List<StyledLayer> styledLayerList = sld.layers(); int styledLayerIndex = 0; int styleIndex = 0; int ftsIndex = 0; int ruleIndex = 0; int symbolizerIndex = 0; boolean isNamedLayer = true; for (StyledLayer styledLayer : styledLayerList) { List<Style> styleList = getStylesList(styledLayer); isNamedLayer = (styledLayer instanceof NamedLayerImpl); styleIndex = 0; for (Style style : styleList) { ftsIndex = 0; for (FeatureTypeStyle fts : style.featureTypeStyles()) { ruleIndex = 0; for (Rule rule : fts.rules()) { symbolizerIndex = (rule.symbolizers().indexOf(symbolizerToFind)); if (symbolizerIndex > -1) { return findEquivalentSymbolizer( otherSLD, styledLayerIndex, isNamedLayer, styleIndex, ftsIndex, ruleIndex, symbolizerIndex); } ruleIndex++; } ftsIndex++; } styleIndex++; } styledLayerIndex++; } return null; }
Example 12
Source File: SelectedSymbol.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Update internal data based on the supplied mask. * * @param maskValue the mask value */ private void updateInternalData(SelectedSymbolMask.SymbolMaskEnum maskValue) { SymbolData localSymbolData = new SymbolData(); SelectedSymbolMask mask = new SelectedSymbolMask(maskValue); if (sld == null) { return; } List<StyledLayer> styledLayers = sld.layers(); if (!styledLayers.isEmpty()) { localSymbolData.initialiseSelectedStyledLayerIndex(); for (StyledLayer styledLayer : styledLayers) { localSymbolData.setStyledLayer(styledLayer); if (styledLayer == symbolData.getStyledLayer()) { this.symbolData.update(localSymbolData); return; } List<Style> styleList = null; if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLED_LAYER)) { styleList = SLDUtils.getStylesList(styledLayer); } if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLE) && (styleList != null) && !styleList.isEmpty()) { localSymbolData.initialiseSelectedStyleIndex(); for (Style style : styleList) { localSymbolData.setStyle(style); if (style == symbolData.getStyle()) { this.symbolData.update(localSymbolData); return; } if (mask.shouldContinue( SelectedSymbolMask.SymbolMaskEnum.E_FEATURE_TYPE_STYLE)) { localSymbolData.initialiseSelectedFTSIndex(); for (FeatureTypeStyle fts : style.featureTypeStyles()) { localSymbolData.setFeatureTypeStyle(fts); if (fts == symbolData.getFeatureTypeStyle()) { this.symbolData.update(localSymbolData); return; } if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_RULE)) { localSymbolData.initialiseSelectedRuleIndex(); for (Rule rule : fts.rules()) { localSymbolData.setRule(rule); if (rule == symbolData.getRule()) { this.symbolData.update(localSymbolData); return; } if (mask.shouldContinue( SelectedSymbolMask.SymbolMaskEnum.E_SYMBOLIZER)) { localSymbolData.initialiseSelectedSymbolizerIndex(); for (Symbolizer symbol : rule.symbolizers()) { localSymbolData.setSymbolizer(symbol); if (symbol == this.symbolData.getSymbolizer()) { this.symbolData.update(localSymbolData); return; } else { localSymbolData .incrementSelectedSymbolizerIndex(); } } } localSymbolData.incrementSelectedRuleIndex(); } } localSymbolData.incrementSelectedFTSIndex(); } } localSymbolData.incrementSelectedStyleIndex(); } } localSymbolData.incrementSelectedStyledLayerIndex(); } } }
Example 13
Source File: ScaleToolPanelTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Test method for {@link * com.sldeditor.tool.scale.ScaleToolPanel#ScaleToolPanel(com.sldeditor.common.SLDEditorInterface)}. */ @Test void testScaleToolPanel() { TestSLDEditorInterface app = new TestSLDEditorInterface(); TestScaleToolPanel testObj = new TestScaleToolPanel(app); DummyScaleSLDFile testData = new DummyScaleSLDFile(); List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>(); SLDEditorFile.getInstance().setSLDData(testData.getSLDData()); sldDataList.add(testData.getSLDData()); testObj.populate(sldDataList); double expectedMinScale = 100.0; testObj.setMinScale(0, expectedMinScale); double expectedMaxScale = 999.0; testObj.setMaxScale(1, expectedMaxScale); // Make no changes testObj.saveData(); // Should be the same as before assertNotNull(app.savedSldData); StyledLayerDescriptor sld = SLDUtils.createSLDFromString(app.savedSldData); List<Rule> ruleList = null; if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); if (styledLayerList != null) { for (StyledLayer styledLayer : styledLayerList) { if (styledLayer instanceof NamedLayerImpl) { NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer; for (Style style : namedLayerImpl.styles()) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { ruleList = fts.rules(); } } } } } } assertNotNull(ruleList); assertTrue(Math.abs(ruleList.get(0).getMinScaleDenominator() - expectedMinScale) < 0.0001); assertTrue(Math.abs(ruleList.get(1).getMaxScaleDenominator() - expectedMaxScale) < 0.0001); }
Example 14
Source File: ScaleToolPanelTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Test method for {@link * com.sldeditor.tool.scale.ScaleToolPanel#ScaleToolPanel(com.sldeditor.common.SLDEditorInterface)}. */ @Test void testScaleToolPanelRevert() { TestSLDEditorInterface app = new TestSLDEditorInterface(); TestScaleToolPanel testObj = new TestScaleToolPanel(app); DummyScaleSLDFile testData = new DummyScaleSLDFile(); List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>(); SLDEditorFile.getInstance().setSLDData(testData.getSLDData()); sldDataList.add(testData.getSLDData()); testObj.populate(sldDataList); StyledLayerDescriptor sld = SLDUtils.createSLDFromString(testData.getSLDData()); List<Rule> ruleList = null; if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); if (styledLayerList != null) { for (StyledLayer styledLayer : styledLayerList) { if (styledLayer instanceof NamedLayerImpl) { NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer; for (Style style : namedLayerImpl.styles()) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { ruleList = fts.rules(); } } } } } } assertNotNull(ruleList); double originalMaxScale = ruleList.get(1).getMaxScaleDenominator(); double expectedMinScale = 100.0; testObj.setMinScale(0, expectedMinScale); double expectedMaxScale = 999.0; testObj.setMaxScale(1, expectedMaxScale); // Make no changes testObj.revertData(); assertNull(testObj.getMinScale(0)); String stringValue = (String) testObj.getMaxScale(1); double actualScale = ScaleUtil.extractValue((String) stringValue); assertTrue(Math.abs(actualScale - originalMaxScale) < 0.0001); }
Example 15
Source File: SelectedSymbolTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
@Test public void testGetSLD() { SelectedSymbol.destroyInstance(); SelectedSymbol instance = SelectedSymbol.getInstance(); // CHECKSTYLE:OFF Rule rule = DefaultSymbols.createNewRule(); FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle(); Style style = DefaultSymbols.createNewStyle(); NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer(); StyledLayerDescriptor sld = DefaultSymbols.createNewSLD(); PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer(); // CHECKSTYLE:ON instance.createNewSLD(sld); instance.setSld(sld); System.out.println("Select named layer"); instance.addNewStyledLayer(namedLayer); instance.setStyledLayer(namedLayer); assertEquals(namedLayer, instance.getStyledLayer()); assertNull(instance.getRule()); assertNull(instance.getStyle()); assertNull(instance.getFeatureTypeStyle()); assertNull(instance.getSymbolizer()); System.out.println("Select style"); instance.addNewStyle(style); instance.setStyle(style); assertEquals(namedLayer, instance.getStyledLayer()); assertEquals(style, instance.getStyle()); assertNull(instance.getFeatureTypeStyle()); assertNull(instance.getRule()); assertNull(instance.getSymbolizer()); System.out.println("Select feature type style"); instance.addNewFeatureTypeStyle(fts); instance.setFeatureTypeStyle(fts); assertEquals(namedLayer, instance.getStyledLayer()); assertEquals(style, instance.getStyle()); assertEquals(fts, instance.getFeatureTypeStyle()); assertNull(instance.getRule()); assertNull(instance.getSymbolizer()); System.out.println("Select rule"); instance.addNewRule(rule); instance.setRule(rule); assertEquals(namedLayer, instance.getStyledLayer()); assertEquals(style, instance.getStyle()); assertEquals(fts, instance.getFeatureTypeStyle()); assertEquals(rule, instance.getRule()); assertNull(instance.getSymbolizer()); assertTrue(instance.hasOnlyOneRule()); System.out.println("Select symbolizer"); instance.addSymbolizerToRule(symbolizer); instance.addNewRule(DefaultSymbols.createNewRule()); assertFalse(instance.hasOnlyOneRule()); assertEquals(-1, instance.getSymbolIndex()); instance.setSymbolizer(symbolizer); assertEquals(namedLayer, instance.getStyledLayer()); assertEquals(style, instance.getStyle()); assertEquals(fts, instance.getFeatureTypeStyle()); assertEquals(rule, instance.getRule()); assertEquals(symbolizer, instance.getSymbolizer()); assertEquals(0, instance.getSymbolIndex()); // Get SLD structure StyledLayerDescriptor actualSLD = instance.getSld(); assertEquals(sld, actualSLD); StyledLayer[] actualStyledLayers = actualSLD.getStyledLayers(); assertEquals(1, actualStyledLayers.length); NamedLayer actualNamedLayer = (NamedLayer) actualStyledLayers[0]; assertEquals(namedLayer, actualNamedLayer); Style[] actualStyle = actualNamedLayer.getStyles(); assertEquals(1, actualStyle.length); assertEquals(style, actualStyle[0]); assertEquals(1, style.featureTypeStyles().size()); FeatureTypeStyle actualFeatureTypeStyle = style.featureTypeStyles().get(0); assertEquals(fts, actualFeatureTypeStyle); List<Rule> actualRules = actualFeatureTypeStyle.rules(); assertEquals(2, actualRules.size()); Rule actualRule = actualRules.get(0); assertEquals(rule, actualRule); assertEquals(1, actualRule.symbolizers().size()); assertEquals(symbolizer, actualRule.symbolizers().get(0)); }