Search in sources :

Example 21 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class CachedFont method evaluate.

@Override
protected void evaluate() {
    if (!isNotEvaluated)
        return;
    final List<Expression> expFamily = styleElement.getFamily();
    final Expression expSize = styleElement.getSize();
    final Expression expWeight = styleElement.getWeight();
    final Expression expStyle = styleElement.getStyle();
    // we can not know so always visible
    isStaticVisible = VisibilityState.VISIBLE;
    // TODO find the best font acoording to OS font list
    if (!expFamily.isEmpty() && GO2Utilities.isStatic(expFamily.get(0))) {
        fontFamily = GO2Utilities.evaluate(expFamily.get(0), null, String.class, "Dialog");
    } else if (!expFamily.isEmpty()) {
        GO2Utilities.getRequieredAttributsName(expFamily.get(0), requieredAttributs);
        isStatic = false;
    } else {
        fontFamily = "Dialog";
    }
    if (GO2Utilities.isStatic(expSize)) {
        final Float f = GO2Utilities.evaluate(expSize, null, Float.class, 10f);
        if (f != null) {
            fontSize = f.intValue();
        }
    } else {
        GO2Utilities.getRequieredAttributsName(expSize, requieredAttributs);
        isStatic = false;
    }
    if (GO2Utilities.isStatic(expWeight) && GO2Utilities.isStatic(expStyle)) {
        String strWeight = GO2Utilities.evaluate(expWeight, null, String.class, FONT_STYLE_NORMAL_STRING);
        String strStyle = GO2Utilities.evaluate(expStyle, null, String.class, FONT_WEIGHT_NORMAL_STRING);
        if (FONT_WEIGHT_BOLD_STRING.equalsIgnoreCase(strWeight)) {
            if (FONT_STYLE_ITALIC_STRING.equalsIgnoreCase(strStyle)) {
                fontStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
            } else if (FONT_STYLE_OBLIQUE_STRING.equalsIgnoreCase(strStyle)) {
                fontStyle = java.awt.Font.BOLD | java.awt.Font.ITALIC;
            } else {
                fontStyle = java.awt.Font.BOLD;
            }
        } else {
            if (FONT_STYLE_ITALIC_STRING.equalsIgnoreCase(strStyle)) {
                fontStyle = java.awt.Font.ITALIC;
            } else if (FONT_STYLE_OBLIQUE_STRING.equalsIgnoreCase(strStyle)) {
                fontStyle = java.awt.Font.ITALIC;
            } else {
                fontStyle = java.awt.Font.PLAIN;
            }
        }
    } else {
        GO2Utilities.getRequieredAttributsName(expWeight, requieredAttributs);
        GO2Utilities.getRequieredAttributsName(expStyle, requieredAttributs);
        isStatic = false;
    }
    // no attributs needed replace with static empty list.
    if (requieredAttributs.isEmpty()) {
        requieredAttributs = EMPTY_ATTRIBUTS;
    }
    // cache the font if possible
    if (fontSize != Integer.MIN_VALUE && fontStyle != Integer.MIN_VALUE && fontFamily != null) {
        cache = new java.awt.Font(fontFamily, fontStyle, (int) fontSize);
    }
    isNotEvaluated = false;
}
Also used : Expression(org.opengis.filter.Expression)

Example 22 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class CachedGraphic method getMargin.

/**
 * @return margin of this style for the given feature
 */
public float getMargin(final Object candidate, final float coeff) {
    evaluate();
    final boolean noFeature = (candidate == null);
    // //we have a cachedImage, we return it's bigest attribut
    // BufferedImage img = (BufferedImage)cachedValues.get(ID_BUFFER);
    // if(img != null){
    // return (img.getHeight()*coeff > img.getWidth()*coeff) ? img.getHeight()*coeff : img.getWidth()*coeff;
    // }
    // get the displacement margin
    final float maxDisplacement = cachedDisplacement.getMargin(candidate, coeff);
    if (Float.isNaN(maxDisplacement))
        return Float.NaN;
    // get anchor margin
    final float anchorRatio = cachedAnchor.getMarginRatio(candidate, coeff);
    if (Float.isNaN(anchorRatio))
        return Float.NaN;
    float candidateOpacity = cachedOpacity;
    float candidateRotation = cachedRotation;
    float candidateSize = cachedSize;
    if (Float.isNaN(candidateOpacity)) {
        final Expression expOpacity = styleElement.getOpacity();
        if (noFeature) {
            // can not evaluate
            return Float.NaN;
        } else {
            candidateOpacity = GO2Utilities.evaluate(expOpacity, candidate, 1f, 0f, 1f);
        }
    }
    if (candidateOpacity <= 0)
        return 0;
    if (Float.isNaN(candidateRotation)) {
        final Expression expRotation = styleElement.getRotation();
        final Number rot = GO2Utilities.evaluate(expRotation, candidate, Number.class, 0f);
        candidateRotation = (float) Math.toRadians(rot.doubleValue());
    }
    if (Float.isNaN(candidateSize)) {
        final Expression expSize = styleElement.getSize();
        if (noFeature) {
            // can not evaluate
            return Float.NaN;
        } else {
            candidateSize = GO2Utilities.evaluate(expSize, candidate, Number.class, 16f).floatValue();
        }
    }
    if (candidateSize <= 0)
        return 0;
    // the subbuffer image
    BufferedImage subBuffer = null;
    // we have a cached mark ------------------------------------------------------------------
    if (cachedMark != null) {
        if (noFeature) {
            if (cachedMark.isStatic()) {
                subBuffer = cachedMark.getImage(candidate, candidateSize * coeff, null);
            }
        } else {
            subBuffer = cachedMark.getImage(candidate, candidateSize * coeff, null);
        }
    }
    // we have a cached external --------------------------------------------------------------
    if (cachedExternal != null) {
        if (noFeature) {
            if (cachedExternal.isStatic()) {
                subBuffer = cachedExternal.getImage(candidateSize, coeff, null);
            }
        } else {
            subBuffer = cachedExternal.getImage(candidateSize, coeff, null);
        }
    }
    if (subBuffer == null)
        return 0;
    // we must change size according to rotation ---------------------------------------------
    final int maxSizeX;
    final int maxSizeY;
    if (candidateRotation == 0) {
        maxSizeX = subBuffer.getWidth();
        maxSizeY = subBuffer.getHeight();
    } else {
        Rectangle rect = new Rectangle(subBuffer.getWidth(), subBuffer.getHeight());
        TransformedShape trs = new TransformedShape();
        trs.setOriginalShape(rect);
        trs.rotate(candidateRotation);
        maxSizeX = (int) trs.getBounds2D().getWidth();
        maxSizeY = (int) trs.getBounds2D().getHeight();
    }
    // consider the anchor value and displacement
    // max margin is : iconSize/2 + iconSize-0.5 + maxDisplacement
    final float iconSize = Math.max(maxSizeX, maxSizeY);
    return (iconSize / 2f + (Math.abs(anchorRatio - 0.5f) * iconSize) + maxDisplacement) * coeff;
}
Also used : TransformedShape(org.geotoolkit.display.shape.TransformedShape) Expression(org.opengis.filter.Expression) Rectangle(java.awt.Rectangle) BufferedImage(java.awt.image.BufferedImage)

Example 23 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class PatternSymbolizer method getRanges.

public Map<Expression, List<Symbolizer>> getRanges() {
    if (thredholds == null && range != null) {
        thredholds = new TreeMap<>(new ExpComparator());
        final SLD110toGTTransformer io = new StyleXmlIO().getTransformer110();
        final Map<Expression, List<Symbolizer>> visitRanges = io.visitRanges(range);
        thredholds.putAll(visitRanges);
    }
    return thredholds;
}
Also used : Expression(org.opengis.filter.Expression) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) ArrayList(java.util.ArrayList) List(java.util.List) SLD110toGTTransformer(org.geotoolkit.sld.xml.SLD110toGTTransformer)

Example 24 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class PatternSymbolizer method setRanges.

public void setRanges(Map<Expression, List<Symbolizer>> range) {
    this.thredholds = new TreeMap<>(new ExpComparator());
    if (range != null)
        this.thredholds.putAll(range);
    final GTtoSLD110Transformer io = new StyleXmlIO().getTransformerXMLv110();
    final List<JAXBElement<RangeType>> ranges = new ArrayList<>();
    for (Entry<Expression, List<Symbolizer>> entry : this.thredholds.entrySet()) {
        final JAXBElement<RangeType> rt = io.visitRange(entry.getKey(), entry.getValue());
        ranges.add(rt);
    }
    this.range = ranges;
}
Also used : RangeType(org.geotoolkit.se.xml.vext.RangeType) Expression(org.opengis.filter.Expression) ArrayList(java.util.ArrayList) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) GTtoSLD110Transformer(org.geotoolkit.sld.xml.GTtoSLD110Transformer) ArrayList(java.util.ArrayList) List(java.util.List) JAXBElement(javax.xml.bind.JAXBElement)

Example 25 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class CachedLineSymbolizer method evaluateOffset.

private void evaluateOffset() {
    final Expression offset = line.getPerpendicularOffset();
    if (GO2Utilities.isStatic(offset)) {
        cachedOffset = GO2Utilities.evaluate(offset, null, Float.class, 0f);
    } else {
        isStatic = false;
        GO2Utilities.getRequieredAttributsName(offset, requieredAttributs);
    }
}
Also used : Expression(org.opengis.filter.Expression)

Aggregations

Expression (org.opengis.filter.Expression)325 Test (org.junit.Test)112 LineString (org.locationtech.jts.geom.LineString)73 Literal (org.opengis.filter.Literal)65 ArrayList (java.util.ArrayList)47 MultiLineString (org.locationtech.jts.geom.MultiLineString)46 Unit (javax.measure.Unit)45 Description (org.opengis.style.Description)40 Fill (org.opengis.style.Fill)38 GraphicFill (org.opengis.style.GraphicFill)38 Stroke (org.opengis.style.Stroke)35 Geometry (org.locationtech.jts.geom.Geometry)31 Displacement (org.opengis.style.Displacement)29 GraphicStroke (org.opengis.style.GraphicStroke)29 ValueReference (org.opengis.filter.ValueReference)27 JAXBElement (javax.xml.bind.JAXBElement)22 LineSymbolizer (org.opengis.style.LineSymbolizer)22 PointSymbolizer (org.opengis.style.PointSymbolizer)22 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)22 MutableStyle (org.geotoolkit.style.MutableStyle)21