當前位置: 首頁>>代碼示例>>Python>>正文


Python QgsSymbolLayerV2Utils.fieldOrExpressionToExpression方法代碼示例

本文整理匯總了Python中qgis.core.QgsSymbolLayerV2Utils.fieldOrExpressionToExpression方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsSymbolLayerV2Utils.fieldOrExpressionToExpression方法的具體用法?Python QgsSymbolLayerV2Utils.fieldOrExpressionToExpression怎麽用?Python QgsSymbolLayerV2Utils.fieldOrExpressionToExpression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在qgis.core.QgsSymbolLayerV2Utils的用法示例。


在下文中一共展示了QgsSymbolLayerV2Utils.fieldOrExpressionToExpression方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testQgsGraduatedSymbolRendererV2_1

# 需要導入模塊: from qgis.core import QgsSymbolLayerV2Utils [as 別名]
# 或者: from qgis.core.QgsSymbolLayerV2Utils import fieldOrExpressionToExpression [as 別名]
    def testQgsGraduatedSymbolRendererV2_1(self):
        """Test QgsGraduatedSymbolRendererV2: Basic get/set functions """

        # Create a renderer
        renderer = QgsGraduatedSymbolRendererV2()

        symbol = createMarkerSymbol()
        renderer.setSourceSymbol(symbol.clone())
        self.assertEqual(symbol.dump(), renderer.sourceSymbol().dump(), "Get/set renderer source symbol")

        attr = '"value"*"value"'
        renderer.setClassAttribute(attr)
        self.assertEqual(attr, renderer.classAttribute(), "Get/set renderer class attribute")

        for m in (
            QgsGraduatedSymbolRendererV2.Custom,
            QgsGraduatedSymbolRendererV2.EqualInterval,
            QgsGraduatedSymbolRendererV2.Quantile,
            QgsGraduatedSymbolRendererV2.Jenks,
            QgsGraduatedSymbolRendererV2.Pretty,
            QgsGraduatedSymbolRendererV2.StdDev,
        ):
            renderer.setMode(m)
            self.assertEqual(m, renderer.mode(), "Get/set renderer mode")

        format = createLabelFormat()
        renderer.setLabelFormat(format)
        self.assertEqual(
            dumpLabelFormat(format),
            dumpLabelFormat(renderer.labelFormat()),
            "Get/set renderer label format")

        ramp = createColorRamp()
        renderer.setSourceColorRamp(ramp)
        self.assertEqual(
            dumpColorRamp(ramp),
            dumpColorRamp(renderer.sourceColorRamp()),
            "Get/set renderer color ramp")

        renderer.setInvertedColorRamp(True)
        self.assertTrue(renderer.invertedColorRamp(),
                        "Get/set renderer inverted color ramp")
        renderer.setInvertedColorRamp(False)
        self.assertFalse(renderer.invertedColorRamp(),
                         "Get/set renderer inverted color ramp")

        value = '"value"*2'
        exp = QgsSymbolLayerV2Utils.fieldOrExpressionToExpression(value)
        valuestr = QgsSymbolLayerV2Utils.fieldOrExpressionFromExpression(exp)
        renderer.setRotationField(value)
        self.assertEqual(valuestr, renderer.rotationField(),
                         "Get/set renderer rotation field")

        value = '"value"*3'
        exp = QgsSymbolLayerV2Utils.fieldOrExpressionToExpression(value)
        valuestr = QgsSymbolLayerV2Utils.fieldOrExpressionFromExpression(exp)
        renderer.setSizeScaleField(value)
        self.assertEqual(valuestr, renderer.sizeScaleField(),
                         "Get/set renderer size scale field")

        renderer.setSourceColorRamp(ramp)
        self.assertEqual(
            dumpColorRamp(ramp),
            dumpColorRamp(renderer.sourceColorRamp()),
            "Get/set renderer color ramp")

        for sm in (
            QgsSymbolV2.ScaleArea,
            QgsSymbolV2.ScaleDiameter,
        ):
            renderer.setScaleMethod(sm)
            self.assertEqual(str(sm), str(renderer.scaleMethod()),
                             "Get/set renderer scale method")
        # test for classificatio with varying size
        renderer.setGraduatedMethod(QgsGraduatedSymbolRendererV2.GraduatedSize)
        renderer.setSourceColorRamp(None)
        renderer.addClassLowerUpper(0, 2)
        renderer.addClassLowerUpper(2, 4)
        renderer.addClassLowerUpper(4, 6)
        renderer.setSymbolSizes(2, 13)
        self.assertEqual(renderer.maxSymbolSize(), 13)
        self.assertEqual(renderer.minSymbolSize(), 2)
        refSizes = [2, (13 + 2) * .5, 13]
        ctx = QgsRenderContext()
        for idx, symbol in enumerate(renderer.symbols2(ctx)):
            self.assertEqual(symbol.size(), refSizes[idx])
開發者ID:Geoneer,項目名稱:QGIS,代碼行數:88,代碼來源:test_qgsgraduatedsymbolrendererv2.py

示例2: testQgsGraduatedSymbolRendererV2_1

# 需要導入模塊: from qgis.core import QgsSymbolLayerV2Utils [as 別名]
# 或者: from qgis.core.QgsSymbolLayerV2Utils import fieldOrExpressionToExpression [as 別名]
    def testQgsGraduatedSymbolRendererV2_1(self):
        """Test QgsGraduatedSymbolRendererV2: Basic get/set functions """

        # Create a renderer
        renderer=QgsGraduatedSymbolRendererV2()

        symbol=createMarkerSymbol()
        renderer.setSourceSymbol(symbol.clone())
        self.assertEqual(symbol.dump(),renderer.sourceSymbol().dump(),"Get/set renderer source symbol")

        attr='"value"*"value"'
        renderer.setClassAttribute(attr)
        self.assertEqual(attr,renderer.classAttribute(),"Get/set renderer class attribute")

        for m in (
            QgsGraduatedSymbolRendererV2.Custom,
            QgsGraduatedSymbolRendererV2.EqualInterval,
            QgsGraduatedSymbolRendererV2.Quantile,
            QgsGraduatedSymbolRendererV2.Jenks,
            QgsGraduatedSymbolRendererV2.Pretty,
            QgsGraduatedSymbolRendererV2.StdDev,
        ):
            renderer.setMode(m)
            self.assertEqual(m,renderer.mode(),"Get/set renderer mode")

        format=createLabelFormat()
        renderer.setLabelFormat(format)
        self.assertEqual(
            dumpLabelFormat(format),
            dumpLabelFormat(renderer.labelFormat()),
            "Get/set renderer label format")

        ramp=createColorRamp()
        renderer.setSourceColorRamp(ramp)
        self.assertEqual(
            dumpColorRamp(ramp),
            dumpColorRamp(renderer.sourceColorRamp()),
            "Get/set renderer color ramp")

        renderer.setInvertedColorRamp(True)
        self.assertTrue(renderer.invertedColorRamp(),
                        "Get/set renderer inverted color ramp")
        renderer.setInvertedColorRamp(False)
        self.assertFalse(renderer.invertedColorRamp(),
                         "Get/set renderer inverted color ramp")

        value='"value"*2'
        exp=QgsSymbolLayerV2Utils.fieldOrExpressionToExpression(value)
        valuestr=QgsSymbolLayerV2Utils.fieldOrExpressionFromExpression(exp)
        renderer.setRotationField(value)
        self.assertEqual(valuestr,renderer.rotationField(),
                         "Get/set renderer rotation field")

        value='"value"*3'
        exp=QgsSymbolLayerV2Utils.fieldOrExpressionToExpression(value)
        valuestr=QgsSymbolLayerV2Utils.fieldOrExpressionFromExpression(exp)
        renderer.setSizeScaleField(value)
        self.assertEqual(valuestr,renderer.sizeScaleField(),
                         "Get/set renderer size scale field")


        renderer.setSourceColorRamp(ramp)
        self.assertEqual(
            dumpColorRamp(ramp),
            dumpColorRamp(renderer.sourceColorRamp()),
            "Get/set renderer color ramp")

        for sm in (
            QgsSymbolV2.ScaleArea,
            QgsSymbolV2.ScaleDiameter,
        ):
            renderer.setScaleMethod(sm)
            self.assertEqual(str(sm),str(renderer.scaleMethod()),
                             "Get/set renderer scale method")
開發者ID:Ariki,項目名稱:QGIS,代碼行數:76,代碼來源:test_qgsgraduatedsymbolrendererv2.py


注:本文中的qgis.core.QgsSymbolLayerV2Utils.fieldOrExpressionToExpression方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。