Ejemplo n.º 1
0
Archivo: qgis.py Proyecto: zyxgis/slyr
def append_MarkerLineSymbolLayer(symbol, layer: MarkerLineSymbolLayer,
                                 context: Context):
    """
    Appends a MarkerLineSymbolLayer to a symbol
    """
    template = layer.template

    # first work out total length of pattern
    current_length = 0
    for t in template.pattern_parts:
        current_length += t[0]
        current_length += t[1]

    total_length = current_length * template.pattern_interval

    marker = Symbol_to_QgsSymbol(layer.pattern_marker, context)
    marker.setAngle(90)

    current_offset_from_start = 0
    for t in template.pattern_parts:
        if t[0]:
            # marker
            line = QgsMarkerLineSymbolLayer(True)
            start_marker = marker.clone()
            start_marker.setAngle(start_marker.angle() - 90)
            line.setSubSymbol(start_marker)
            line.setOffset(-context.convert_size(layer.offset))
            line.setOffsetUnit(context.units)
            line.setInterval(context.convert_size(total_length))
            line.setIntervalUnit(context.units)
            line.setOffsetAlongLine(
                context.convert_size(current_offset_from_start +
                                     template.pattern_interval / 2))
            line.setOffsetAlongLineUnit(context.units)
            symbol.appendSymbolLayer(line)

            current_offset_from_start += template.pattern_interval * t[0]

        if t[1]:
            # space
            current_offset_from_start += template.pattern_interval * t[1]

    if layer.decoration is not None:
        append_Decorations(symbol, layer.decoration, context)
    def testNoPoint(self):
        s = QgsLineSymbol()
        s.deleteSymbolLayer(0)

        marker_line = QgsMarkerLineSymbolLayer(True)
        marker_line.setPlacement(QgsTemplatedLineSymbolLayerBase.Interval)
        marker_line.setOffsetAlongLine(1000)
        marker_line.setIntervalUnit(QgsUnitTypes.RenderMapUnits)
        marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Circle, 4)
        marker.setColor(QColor(255, 0, 0, 100))
        marker.setStrokeStyle(Qt.NoPen)
        marker_symbol = QgsMarkerSymbol()
        marker_symbol.changeSymbolLayer(0, marker)
        marker_line.setSubSymbol(marker_symbol)
        line_symbol = QgsLineSymbol()
        line_symbol.changeSymbolLayer(0, marker_line)

        s.appendSymbolLayer(marker_line.clone())

        g = QgsGeometry.fromWkt('LineString(0 0, 0 10, 10 10)')
        rendered_image = self.renderGeometry(s, g)
        assert self.imageCheck('markerline_none', 'markerline_none', rendered_image)
    def testNoPoint(self):
        s = QgsLineSymbol()
        s.deleteSymbolLayer(0)

        marker_line = QgsMarkerLineSymbolLayer(True)
        marker_line.setPlacement(QgsTemplatedLineSymbolLayerBase.Interval)
        marker_line.setOffsetAlongLine(1000)
        marker_line.setIntervalUnit(QgsUnitTypes.RenderMapUnits)
        marker = QgsSimpleMarkerSymbolLayer(QgsSimpleMarkerSymbolLayer.Circle, 4)
        marker.setColor(QColor(255, 0, 0, 100))
        marker.setStrokeStyle(Qt.NoPen)
        marker_symbol = QgsMarkerSymbol()
        marker_symbol.changeSymbolLayer(0, marker)
        marker_line.setSubSymbol(marker_symbol)
        line_symbol = QgsLineSymbol()
        line_symbol.changeSymbolLayer(0, marker_line)

        s.appendSymbolLayer(marker_line.clone())

        g = QgsGeometry.fromWkt('LineString(0 0, 0 10, 10 10)')
        rendered_image = self.renderGeometry(s, g)
        assert self.imageCheck('markerline_none', 'markerline_none', rendered_image)