Example #1
0
def line_to_sld(document, element, penStyle, color, width, penJoinStyle,
                customDashPattern, dashOffset):
    dashPattern = []
    if penStyle == Qt.CustomDashLine and not customDashPattern:
        element.appendChild(
            document.createComment(
                "WARNING: Custom dash pattern required but not provided."
                " Using default dash pattern."))
        penStyle = Qt.DashLine
    if penStyle == Qt.NoPen:
        return
    if penStyle != Qt.SolidLine:
        if penStyle == Qt.DashLine:
            dashPattern.append(4.0)
            dashPattern.append(2.0)
        elif penStyle == Qt.DotLine:
            dashPattern.append(1.0)
            dashPattern.append(2.0)
        elif penStyle == Qt.DashDotLine:
            dashPattern.append(4.0)
            dashPattern.append(2.0)
            dashPattern.append(1.0)
            dashPattern.append(2.0)
        elif penStyle == Qt.DashDotDotLine:
            dashPattern.append(4.0)
            dashPattern.append(2.0)
            dashPattern.append(1.0)
            dashPattern.append(2.0)
            dashPattern.append(1.0)
            dashPattern.append(2.0)
        else:
            element.appendChild(
                document.createComment('BrushStyle %s not supported yet' %
                                       penStyle))
    if color.isValid():
        element.appendChild(
            createCssParameterElement(document, "stroke", color.name()))
        if color.alpha() < 255:
            element.appendChild(
                createCssParameterElement(
                    document, "stroke-opacity",
                    QgsSymbolLayerUtils.encodeSldAlpha(color.alpha())))
    if width > 0:
        element.appendChild(
            createCssParameterElement(document, "stroke-width", str(width)))
    if penJoinStyle:
        element.appendChild(
            createCssParameterElement(
                document, "stroke-linejoin",
                QgsSymbolLayerUtils.encodeSldLineJoinStyle(penJoinStyle)))
    # TODO: manage penCapStyle
    if len(dashPattern) > 0:
        element.appendChild(
            createCssParameterElement(
                document, "stroke-dasharray",
                QgsSymbolLayerUtils.encodeSldRealVector(
                    dashPattern)))  # " ".join(dashPattern)))
Example #2
0
def fill_to_sld(symbolLayer, document, element, brushStyle, color):
    patternName = ''
    if brushStyle == Qt.NoBrush:
        return
    elif brushStyle == Qt.SolidPattern:
        if color.isValid():
            cssElement = createCssParameterElement(document, 'fill',
                                                   color.name())
            element.appendChild(cssElement)
            if color.alpha() < 255:
                cssElement = createCssParameterElement(
                    document, 'fill-opacity',
                    QgsSymbolLayerUtils.encodeSldAlpha(color.alpha()))
                element.appendChild()
        return
    elif brushStyle in (
            Qt.CrossPattern,
            Qt.CrossPattern,
            Qt.DiagCrossPattern,
            Qt.HorPattern,
            Qt.VerPattern,
            Qt.BDiagPattern,
            Qt.FDiagPattern,
            Qt.Dense1Pattern,
            Qt.Dense2Pattern,
            Qt.Dense3Pattern,
            Qt.Dense4Pattern,
            Qt.Dense5Pattern,
            Qt.Dense6Pattern,
            Qt.Dense7Pattern,
    ):
        patternName = QgsSymbolLayerUtils.encodeSldBrushStyle(brushStyle)
        return
    else:
        element.appendChild(document.createComment('Brush not supported'))
    graphicFillElem = document.createElement('sld:GraphicFill')
    element.appendChild(graphicFillElem)
    graphicElem = document.createElement('sld:Graphic')
    element.appendChild(graphicElem)
    fillColor = color if patternName.startswith('brush://') else Qt.QColor()
    strokeColor = \
        color if not patternName.startswith('brush://') else Qt.QColor()
    # Use WellKnownName tag to handle QT brush styles.
    QgsSymbolLayerUtils.wellKnownMarkerToSld(document, graphicElem,
                                             patternName, fillColor,
                                             strokeColor, Qt.SolidLine, -1, -1)