Search in sources :

Example 11 with Symbolizer

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

the class SLDEditorBufferedImageLegendGraphicBuilder method calcSymbolScale.

/**
 * Calculates a global rescaling factor for all the symbols to be drawn in the given rules. This
 * is to be sure all symbols are drawn inside the given w x h box.
 *
 * @param width horizontal constraint
 * @param height vertical constraint
 * @param featureType FeatureType to be used for size extraction in expressions (used to create
 *     a sample if feature is null)
 * @param feature Feature to be used for size extraction in expressions (if null a sample
 *     Feature will be created from featureType)
 * @param rules set of rules to scan for symbols
 * @param minimumSymbolSize lower constraint for the symbols size
 */
private double calcSymbolScale(int width, int height, FeatureType featureType, Feature feature, final Rule[] rules, double minimumSymbolsSize) {
    // check for max and min size in rendered symbols
    double minSize = Double.MAX_VALUE;
    double maxSize = 0.0;
    final int ruleCount = rules.length;
    for (int i = 0; i < ruleCount; i++) {
        Feature sample = getSampleFeatureForRule(featureType, feature, rules[i]);
        final Symbolizer[] symbolizers = rules[i].getSymbolizers();
        for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
            final Symbolizer symbolizer = symbolizers[sIdx];
            if (symbolizer instanceof PointSymbolizer) {
                double size = getGraphicSize(sample, ((PointSymbolizer) symbolizer).getGraphic(), Math.min(width, height));
                if (size < minSize) {
                    minSize = size;
                }
                if (size > maxSize) {
                    maxSize = size;
                }
            }
        }
    }
    if (minSize != maxSize) {
        return (maxSize - minSize + 1) / (Math.min(width, height) - minimumSymbolsSize);
    } else {
        return maxSize / (Math.min(width, height) - minimumSymbolsSize);
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) Point(org.locationtech.jts.geom.Point) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer)

Example 12 with Symbolizer

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

the class StrokeTreeItem method itemSelected.

/*
     * (non-Javadoc)
     *
     * @see com.sldeditor.ui.tree.SLDTreeItemInterface#itemSelected(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)
     */
@Override
public void itemSelected(DefaultMutableTreeNode node, Object userObject) {
    if (node != null) {
        SelectedSymbol selectedSymbol = SelectedSymbol.getInstance();
        // Individual symbol selected
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
        if ((parent != null) && (parent.getUserObject() instanceof Symbolizer)) {
            Symbolizer symbolizer = (Symbolizer) parent.getUserObject();
            selectedSymbol.setSymbolizer(symbolizer);
        }
    }
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Symbolizer(org.geotools.styling.Symbolizer)

Example 13 with Symbolizer

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

the class SymbolizerTreeItem method itemSelected.

/**
 * Item selected.
 *
 * @param node the node
 * @param userObject the user object
 */
@Override
public void itemSelected(DefaultMutableTreeNode node, Object userObject) {
    SelectedSymbol selectedSymbol = SelectedSymbol.getInstance();
    // Individual symbol selected
    Symbolizer symbolizer = (Symbolizer) userObject;
    if (node != null) {
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
        if (parent != null) {
            selectedSymbol.setSymbolizer(symbolizer);
        }
    }
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 14 with Symbolizer

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

the class SelectedSymbol method updateInternalData.

/**
 * 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();
        }
    }
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) Symbolizer(org.geotools.styling.Symbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer)

Example 15 with Symbolizer

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

the class NewPolygonSLDTest method testNewPolygonSLD.

/**
 * Test new polygon sld.
 */
@Test
public void testNewPolygonSLD() {
    NewPolygonSLD newData = new NewPolygonSLD();
    StyledLayerDescriptor sld = newData.create();
    assertTrue(sld.layers().size() == 1);
    StyledLayer styledLayer = sld.layers().get(0);
    NamedLayer namedLayer = (NamedLayer) styledLayer;
    Symbolizer symbolizer = namedLayer.styles().get(0).featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
    assertTrue(symbolizer instanceof PolygonSymbolizer);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) NewPolygonSLD(com.sldeditor.create.sld.NewPolygonSLD) StyledLayer(org.geotools.styling.StyledLayer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) NamedLayer(org.geotools.styling.NamedLayer) Symbolizer(org.geotools.styling.Symbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Test(org.junit.jupiter.api.Test)

Aggregations

Symbolizer (org.geotools.styling.Symbolizer)65 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)29 LineSymbolizer (org.geotools.styling.LineSymbolizer)28 PointSymbolizer (org.geotools.styling.PointSymbolizer)27 Rule (org.geotools.styling.Rule)21 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)20 Style (org.geotools.styling.Style)18 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)15 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 Test (org.junit.jupiter.api.Test)13 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 JsonObject (com.google.gson.JsonObject)11 StyledLayer (org.geotools.styling.StyledLayer)11 NamedLayer (org.geotools.styling.NamedLayer)10 ArrayList (java.util.ArrayList)8 JsonElement (com.google.gson.JsonElement)7 Stroke (org.geotools.styling.Stroke)6 JsonArray (com.google.gson.JsonArray)5 Expression (org.opengis.filter.expression.Expression)5