Java Code Examples for org.geotools.styling.StyledLayerDescriptor#layers()
The following examples show how to use
org.geotools.styling.StyledLayerDescriptor#layers() .
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 |
/** * Evaluate fields types. * * @return true, field types updated */ public static boolean fieldTypesUpdated() { boolean fieldsUpdated = false; StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld(); if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { List<org.geotools.styling.Style> styleList = SLDUtils.getStylesList(styledLayer); FeatureSource<SimpleFeatureType, SimpleFeature> featureList = DataSourceFactory.getDataSource().getFeatureSource(); if (featureList != null) { fieldsUpdated = processStyles(fieldsUpdated, styleList, featureList); } } } return fieldsUpdated; }
Example 2
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 3
Source File: SLDUtils.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Find equivalent rule. * * @param otherSLD the other SLD * @param styledLayerIndex the styled layer index * @param styleIndex the style index * @param ftsIndex the fts index * @param ruleIndex the rule index * @return the rule */ private static Rule findEquivalentRule( StyledLayerDescriptor otherSLD, int styledLayerIndex, int styleIndex, int ftsIndex, int ruleIndex) { if (otherSLD != null) { List<StyledLayer> styledLayerList = otherSLD.layers(); try { StyledLayer styledLayer = styledLayerList.get(styledLayerIndex); List<Style> styleList = getStylesList(styledLayer); Style style = styleList.get(styleIndex); FeatureTypeStyle fts = style.featureTypeStyles().get(ftsIndex); return fts.rules().get(ruleIndex); } catch (IndexOutOfBoundsException exception) { // Do nothing } } return null; }
Example 4
Source File: InlineFeatureUtils.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Extract user layers from an SLD. * * @param sld the sld * @return the list of user layers */ public static List<UserLayer> extractUserLayers(StyledLayerDescriptor sld) { List<UserLayer> userLayerList = new ArrayList<>(); if (sld != null) { for (StyledLayer layer : sld.layers()) { if (layer instanceof UserLayer) { UserLayer userLayer = (UserLayer) layer; userLayerList.add(userLayer); } } } return userLayerList; }
Example 5
Source File: SLDUtils.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Find rule. * * @param sld the sld * @param ruleToFind the rule to find * @param otherSLD the other SLD * @return the rule */ public static Rule findRule( StyledLayerDescriptor sld, Rule ruleToFind, StyledLayerDescriptor otherSLD) { if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); int styledLayerIndex = 0; int styleIndex = 0; int ftsIndex = 0; int ruleIndex = 0; for (StyledLayer styledLayer : styledLayerList) { List<Style> styleList = getStylesList(styledLayer); styleIndex = 0; for (Style style : styleList) { ftsIndex = 0; for (FeatureTypeStyle fts : style.featureTypeStyles()) { ruleIndex = fts.rules().indexOf(ruleToFind); if (ruleIndex > -1) { return findEquivalentRule( otherSLD, styledLayerIndex, styleIndex, ftsIndex, ruleIndex); } ftsIndex++; } styleIndex++; } styledLayerIndex++; } } return null; }
Example 6
Source File: SLDUtils.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Find equivalent symbolizer in another SLD. * * @param otherSLD the other SLD * @param styledLayerIndex the styled layer index * @param isNamedLayer the is named layer * @param styleIndex the style index * @param ftsIndex the fts index * @param ruleIndex the rule index * @param symbolizerIndex the symbolizer index * @return the symbolizer */ private static Symbolizer findEquivalentSymbolizer( StyledLayerDescriptor otherSLD, int styledLayerIndex, boolean isNamedLayer, int styleIndex, int ftsIndex, int ruleIndex, int symbolizerIndex) { if (otherSLD != null) { List<StyledLayer> styledLayerList = otherSLD.layers(); if (styledLayerList != null) { try { StyledLayer styledLayer = styledLayerList.get(styledLayerIndex); List<Style> styleList = null; if (isNamedLayer) { NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer; styleList = namedLayerImpl.styles(); } else { UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer; styleList = userLayerImpl.userStyles(); } if (styleList != null) { Style style = styleList.get(styleIndex); FeatureTypeStyle fts = style.featureTypeStyles().get(ftsIndex); Rule rule = fts.rules().get(ruleIndex); return rule.symbolizers().get(symbolizerIndex); } } catch (IndexOutOfBoundsException exception) { // Do nothing } } } return null; }
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: InlineFeatureUtils.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Checks to see if SLD contains inline features. * * @param sld the sld * @return true, if sld contains inline features */ public static boolean containsInLineFeatures(StyledLayerDescriptor sld) { if (sld != null) { for (StyledLayer layer : sld.layers()) { if (layer instanceof UserLayer) { UserLayer userLayer = (UserLayer) layer; if (userLayer.getInlineFeatureDatastore() != null) { return true; } } } } return false; }
Example 9
Source File: SLDTree.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override public void populateSLD() { reset(); SelectedSymbol selectedSymbol = SelectedSymbol.getInstance(); if (selectedSymbol != null) { StyledLayerDescriptor sld = selectedSymbol.getSld(); rootNode.setUserObject(sld); treeModel.nodeChanged(rootNode); if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { DefaultMutableTreeNode styledLayerTreeNode = null; List<Style> styleList = null; if (styledLayer instanceof NamedLayerImpl) { NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer; styleList = namedLayerImpl.styles(); styledLayerTreeNode = addObject(rootNode, namedLayerImpl, true); } else if (styledLayer instanceof UserLayerImpl) { UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer; styleList = userLayerImpl.userStyles(); styledLayerTreeNode = addObject(rootNode, userLayerImpl, true); } if (styleList != null) { populateStyles(styledLayerTreeNode, styleList); } } } } }
Example 10
Source File: LegendManager.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Creates the legend for multiple SLD styles. * * @param sld the sld * @param styleMap the style map * @param selectedStyledLayer the selected styled layer */ private void createMultipleStyleLegend( StyledLayerDescriptor sld, Map<String, Style> styleMap, StyledLayer selectedStyledLayer) { List<StyledLayer> styledLayerList = null; if (selectedStyledLayer == null) { styledLayerList = sld.layers(); } else { styledLayerList = new ArrayList<>(); styledLayerList.add(selectedStyledLayer); } for (StyledLayer styledLayer : styledLayerList) { List<Style> styleList = SLDUtils.getStylesList(styledLayer); int count = 1; for (Style style : styleList) { String styleName; if (style.getName() != null) { styleName = style.getName(); } else { styleName = String.format("Style %d", count); } styleMap.put(styleName, style); count++; } } }
Example 11
Source File: MapRender.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Render updated style. * * @param mapContent the map content */ private void renderUpdatedStyle(MapContent mapContent) { StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld(); if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { List<org.geotools.styling.Style> styleList = SLDUtils.getStylesList(styledLayer); for (Style style : styleList) { renderSymbol(mapContent, styledLayer, style); } } } }
Example 12
Source File: MXDParser.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Gets the label renderer. * * @param sld the sld * @param labelRenderArrayElement the label render array element * @param transparency the transparency */ private void processLabelRenderer(StyledLayerDescriptor sld, JsonArray labelRenderArrayElement, int transparency) { if(sld != null) { if(labelRenderArrayElement != null) { List<StyledLayer> styledLayers = sld.layers(); if(!styledLayers.isEmpty()) { if(styledLayers.get(0) instanceof NamedLayer) { NamedLayer namedLayer = (NamedLayer)styledLayers.get(0); List<Style> styleList = namedLayer.styles(); if(!styleList.isEmpty()) { List<FeatureTypeStyle> ftsList = styleList.get(0).featureTypeStyles(); if(!ftsList.isEmpty()) { List<Rule> ruleList = ftsList.get(0).rules(); List<Rule> newLabelRuleList = new ArrayList<Rule>(); for(int index = 0; index < labelRenderArrayElement.size(); index ++) { JsonElement labelRenderElement = labelRenderArrayElement.get(index); JsonObject renderer = labelRenderElement.getAsJsonObject(); boolean found = false; for(String labelRendererType : labelRendererMap.keySet()) { JsonElement obj = renderer.get(labelRendererType); if(obj != null) { EsriLabelRendererInterface esriLabelRenderer = labelRendererMap.get(labelRendererType); if(esriLabelRenderer != null) { for(Rule rule : ruleList) { esriLabelRenderer.convert(newLabelRuleList, rule, obj, transparency); } } found = true; break; } } if(!found) { ConsoleManager.getInstance().error(this, "Unsupported label renderer : " + SymbolUtils.extractName(labelRenderElement)); } } ruleList.addAll(newLabelRuleList); } } } } } } }
Example 13
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 14
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 15
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 16
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 17
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); }