Beispiel #1
0
    def testQgsLinePatternFillSymbolLayer(self):
        """
        Create a new style from a .sld file and match test
        """
        mTestName = 'QgsLinePatternFillSymbolLayer'
        mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile, True)
        mFile.close()
        mSymbolLayer = QgsLinePatternFillSymbolLayer.createFromSld(
            mDoc.elementsByTagName('PolygonSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsLinePatternFillSymbolLayer())
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = '#ff55ff'
        mValue = mSymbolLayer.color().name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 1.5
        mValue = mSymbolLayer.lineWidth()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 4
        mValue = mSymbolLayer.distance()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 57
        mValue = mSymbolLayer.lineAngle()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        # test colors, need to make sure colors are passed/retrieved from subsymbol
        mSymbolLayer.setColor(QColor(150, 50, 100))
        self.assertEqual(mSymbolLayer.color(), QColor(150, 50, 100))
        self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(150, 50, 100))
        mSymbolLayer.subSymbol().setColor(QColor(250, 150, 200))
        self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(250, 150, 200))
        self.assertEqual(mSymbolLayer.color(), QColor(250, 150, 200))
    def testLineFillPixels(self):
        symbol = QgsLinePatternFillSymbolLayer()
        symbol.setLineAngle(45)
        symbol.setLineWidth(1)
        symbol.setOffset(5)
        symbol.setOutputUnit(QgsUnitTypes.RenderPixels)

        dom, root = self.symbolToSld(symbol)
        # print ("Line fill px: \n" + dom.toString())

        self.assertStaticRotation(root, '45')
        self.assertStrokeWidth(root, 1, 1)
        self.assertStaticSize(root, '5')
        self.assertStaticDisplacement(root, 4.25, 2.63)
    def testLineFillDefault(self):
        symbol = QgsLinePatternFillSymbolLayer()
        symbol.setLineAngle(45)
        symbol.setLineWidth(1)
        symbol.setOffset(5)

        dom, root = self.symbolToSld(symbol)
        # print ("Line fill mm: \n" + dom.toString())

        self.assertStaticRotation(root, '45')
        self.assertStrokeWidth(root, 1, 4)
        self.assertStaticSize(root, '18')
        self.assertStaticDisplacement(root, 15, 9)
Beispiel #4
0
    def testQgsLinePatternFillSymbolLayer(self):
        '''
        Create a new style from a .sld file and match test
        '''
        mTestName = QString('QgsLinePatternFillSymbolLayer')
        mFilePath = QDir.toNativeSeparators(
            QString('%1/symbol_layer/%2.sld').arg(unitTestDataPath(),
                                                  mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile, True)
        mFile.close()
        mSymbolLayer = QgsLinePatternFillSymbolLayer.createFromSld(
            mDoc.elementsByTagName('PolygonSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsLinePatternFillSymbolLayer())
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = QString(u'#ff55ff')
        mValue = mSymbolLayer.color().name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 1.5
        mValue = mSymbolLayer.lineWidth()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 4
        mValue = mSymbolLayer.distance()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 57
        mValue = mSymbolLayer.lineAngle()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage
    def testLineFillDefault(self):
        symbol = QgsLinePatternFillSymbolLayer()
        symbol.setLineAngle(45)
        symbol.setLineWidth(1)
        symbol.setOffset(5)

        dom, root = self.symbolToSld(symbol)
        # print ("Line fill mm: \n" + dom.toString())

        self.assertStaticRotation(root, '45')
        self.assertStrokeWidth(root, 1, 4)
        self.assertStaticSize(root, '18')
        self.assertStaticDisplacement(root, 15, 9)
    def testQgsLinePatternFillSymbolLayer(self):
        """
        Create a new style from a .sld file and match test
        """
        mTestName = "QgsLinePatternFillSymbolLayer"
        mFilePath = QDir.toNativeSeparators("%s/symbol_layer/%s.sld" % (unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile, True)
        mFile.close()
        mSymbolLayer = QgsLinePatternFillSymbolLayer.createFromSld(
            mDoc.elementsByTagName("PolygonSymbolizer").item(0).toElement()
        )

        mExpectedValue = type(QgsLinePatternFillSymbolLayer())
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = u"#ff55ff"
        mValue = mSymbolLayer.color().name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 1.5
        mValue = mSymbolLayer.lineWidth()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 4
        mValue = mSymbolLayer.distance()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 57
        mValue = mSymbolLayer.lineAngle()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        # test colors, need to make sure colors are passed/retrieved from subsymbol
        mSymbolLayer.setColor(QColor(150, 50, 100))
        self.assertEqual(mSymbolLayer.color(), QColor(150, 50, 100))
        self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(150, 50, 100))
        mSymbolLayer.subSymbol().setColor(QColor(250, 150, 200))
        self.assertEqual(mSymbolLayer.subSymbol().color(), QColor(250, 150, 200))
        self.assertEqual(mSymbolLayer.color(), QColor(250, 150, 200))
    def testQgsLinePatternFillSymbolLayer(self):
        '''
        Create a new style from a .sld file and match test
        '''
        mTestName = QString ('QgsLinePatternFillSymbolLayer')
        mFilePath = QDir.toNativeSeparators(
            QString ('%1/symbol_layer/%2.sld').arg(
                unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile (mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile,True)
        mFile.close()
        mSymbolLayer = QgsLinePatternFillSymbolLayer.createFromSld(
            mDoc.elementsByTagName('PolygonSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsLinePatternFillSymbolLayer())
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = QString(u'#ff55ff')
        mValue = mSymbolLayer.color().name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 1.5
        mValue = mSymbolLayer.lineWidth()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 4
        mValue = mSymbolLayer.distance()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 57
        mValue = mSymbolLayer.lineAngle()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage
Beispiel #8
0
def append_LineFillSymbolLayer(symbol, layer: LineFillSymbolLayer):
    """
    Appends a LineFillSymbolLayer to a symbol
    """
    line = Symbol_to_QgsSymbol(layer.line)

    out = QgsLinePatternFillSymbolLayer()
    out.setSubSymbol(line)
    out.setLineAngle(convert_angle(layer.angle))
    out.setDistance(layer.separation)
    out.setDistanceUnit(QgsUnitTypes.RenderPoints)
    out.setOffset(layer.offset)
    out.setOffsetUnit(QgsUnitTypes.RenderPoints)

    symbol.appendSymbolLayer(out)
    if layer.outline_layer:
        append_SymbolLayer_to_QgsSymbolLayer(symbol, layer.outline_layer)
    elif layer.outline_symbol:
        # get all layers from outline
        append_SymbolLayer_to_QgsSymbolLayer(symbol, layer.outline_symbol)
Beispiel #9
0
def append_LineFillSymbolLayer(symbol, layer: LineFillSymbolLayer,
                               context: Context):
    """
    Appends a LineFillSymbolLayer to a symbol
    """
    line = Symbol_to_QgsSymbol(layer.line, context)

    out = QgsLinePatternFillSymbolLayer()
    out.setSubSymbol(line)
    out.setLineAngle(layer.angle)
    out.setDistance(context.convert_size(layer.separation))
    out.setDistanceUnit(context.units)
    out.setOffset(context.convert_size(layer.offset))
    out.setOffsetUnit(context.units)

    symbol.appendSymbolLayer(out)
    if layer.outline_layer:
        append_SymbolLayer_to_QgsSymbolLayer(symbol, layer.outline_layer,
                                             context)
    elif layer.outline_symbol:
        # get all layers from outline
        append_SymbolLayer_to_QgsSymbolLayer(symbol, layer.outline_symbol,
                                             context)
Beispiel #10
0
    def __getQgsPolygonSymbolLayer(self, msstyle):
        props = {}
        type_marker = ''

        symbol = msstyle.get('symbol', False)
        if symbol:
            (type_marker, symbolname, msSymbol,
             props) = self.__getMsSymbol(symbol, props, True)

        opacity = self.__getMsOpacity(msstyle)
        color = self.__getMsColor(msstyle, props, opacity)
        self.__getMsOutlinecolor(msstyle, props, opacity)
        self.__getMsLinecap(msstyle, props)
        self.__getMsLinejoin(msstyle, props)
        self.__getMsPattern(msstyle, props)
        self.__getMsWidth(msstyle, props)
        self.__getMsOutline(msstyle, props)
        self.__getMsScale(msstyle, props)
        offset = self.__getMsOffset(msstyle, props)
        if not type_marker:
            #-linea sencilla exterior-#
            #-relleno simple (sin estilo de relleno preconfigurados)-#
            if not color:
                self.deleteProperties(props, _qgis.SIMPLE_LINE_SYMBOL_LAYER)
                qgsSymbol = QgsSimpleLineSymbolLayerV2.create(props)
            else:
                self.deleteProperties(props, _qgis.SIMPLE_FILL_SYMBOL_LAYER)
                qgsSymbol = QgsSimpleFillSymbolLayerV2.create(props)
            #-relleno de gradientes-#
            #el gradiente es para renderer por categorias continuas
            #no aplica, porque aca es para gradiente de un simbolo
        else:
            props_parent = {}
            self.__setMsOffsetXY(offset, props)
            self.__getMsAngle(msstyle, props, props_parent)
            gap = self.__getMsGap(msstyle)
            size = self.__getMsSize(msstyle, props)
            self.__getMarkerDisplacementAndRotate(msstyle, gap, size,
                                                  props_parent)

            geomtransform = msstyle.get('geomtransform', '').lower()
            if geomtransform == 'centroid':
                #-relleno de centroides-#
                self.__getMsAnchorpoint(msSymbol, props)
                qgsSubSymbol = self.__getQgsMarkerSubSymbol(
                    type_marker, msSymbol, size, props)
                #self.deleteProperties(props_parent, _qgis.CENTROID_FILL_SYMBOL_LAYER)
                qgsSymbol = QgsCentroidFillSymbolLayerV2.create({})
                qgsSymbol.setSubSymbol(qgsSubSymbol)
            elif not color:
                #-Linea exterior:linea de marcador-#
                self.__getMsAnchorpoint(msSymbol, props)
                qgsSubSymbol = self.__getQgsMarkerSubSymbol(
                    type_marker, msSymbol, size, props)
                self.deleteProperties(props_parent,
                                      _qgis.MARKER_LINE_SYMBOL_LAYER)
                qgsSymbol = QgsMarkerLineSymbolLayerV2.create(props_parent)
                qgsSymbol.setSubSymbol(qgsSubSymbol)
            elif type_marker == _ms.MS_SYMBOL_HATCH:
                if not props['use_custom_dash']:
                    #-relleno simple (con estilo de relleno)-#
                    self.deleteProperties(props,
                                          _qgis.SIMPLE_LINE_SYMBOL_LAYER)
                    qgsSymbol = QgsSimpleLineSymbolLayerV2.create(props)
                else:
                    #-Patron de relleno de linea-#
                    self.deleteProperties(props,
                                          _qgis.SIMPLE_LINE_SYMBOL_LAYER)
                    qgsSubSymbol = self.__getSubSymbol(
                        QgsLineSymbolV2, QgsSimpleLineSymbolLayerV2, QGis.Line,
                        props)
                    self.deleteProperties(props_parent,
                                          _qgis.LINE_PATTERN_FILL_SYMBOL_LAYER)
                    qgsSymbol = QgsLinePatternFillSymbolLayer.create(
                        props_parent)
                    qgsSymbol.setSubSymbol(qgsSubSymbol)
            elif type_marker == _ms.MS_SYMBOL_PIXMAP:
                #-relleno de imagen raster-#
                self.deleteProperties(props, _qgis.RASTER_FILL_SYMBOL_LAYER)
                qgsSymbol = QgsRasterFillSymbolLayer.create(props)
            elif type_marker == _ms.MS_SYMBOL_SVG:
                #-relleno SVG-#
                self.deleteProperties(props, _qgis.SIMPLE_LINE_SYMBOL_LAYER)
                qgsSubSymbol = self.__getSubSymbol(QgsLineSymbolV2,
                                                   QgsSimpleLineSymbolLayerV2,
                                                   QGis.Line, props)
                self.deleteProperties(props_parent,
                                      _qgis.SVG_FILL_SYMBOL_LAYER)
                qgsSymbol = QgsSVGFillSymbolLayer.create(props_parent)
                qgsSymbol.setSubSymbol(qgsSubSymbol)
            else:
                #-patron de relleno de puntos-#
                self.__getMsAnchorpoint(msSymbol, props)
                qgsSubSymbol = self.__getQgsMarkerSubSymbol(
                    type_marker, msSymbol, size, props)
                self.deleteProperties(props_parent,
                                      _qgis.POINT_PATTERN_FILL_SYMBOL_LAYER)
                qgsSymbol = QgsPointPatternFillSymbolLayer.create(props_parent)
                qgsSymbol.setSubSymbol(qgsSubSymbol)

        #qgsSymbol.setAlpha((opacity*1.0)/100)
        #print(props)
        return qgsSymbol