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


Python QgsSymbolLayerV2Utils.convertToPainterUnits方法代碼示例

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


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

示例1: testConvertToPainterUnits

# 需要導入模塊: from qgis.core import QgsSymbolLayerV2Utils [as 別名]
# 或者: from qgis.core.QgsSymbolLayerV2Utils import convertToPainterUnits [as 別名]
    def testConvertToPainterUnits(self):
        # test QgsSymbolLayerV2Utils::convertToPainterUnits() using QgsMapUnitScale

        ms = QgsMapSettings()
        ms.setExtent(QgsRectangle(0, 0, 100, 100))
        ms.setOutputSize(QSize(100, 50))
        ms.setOutputDpi(300)
        r = QgsRenderContext.fromMapSettings(ms)

        # renderer scale should be about 1:291937841

        # start with no min/max scale
        c = QgsMapUnitScale()

        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.MapUnit, c)
        self.assertAlmostEqual(size, 1.0, places=5)
        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.MM, c)
        self.assertAlmostEqual(size, 23.622047, places=5)
        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.Pixel, c)
        self.assertAlmostEqual(size, 2.0, places=5)

        # minimum size greater than the calculated size, so size should be limited to minSizeMM
        c.minSizeMM = 5
        c.minSizeMMEnabled = True
        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.MapUnit, c)
        self.assertAlmostEqual(size, 59.0551181, places=5)
        # only conversion from mapunits should be affected
        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.MM, c)
        self.assertAlmostEqual(size, 23.622047, places=5)
        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.Pixel, c)
        self.assertAlmostEqual(size, 2.0, places=5)
        c.minSizeMMEnabled = False

        # maximum size less than the calculated size, so size should be limited to maxSizeMM
        c.maxSizeMM = 0.1
        c.maxSizeMMEnabled = True
        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.MapUnit, c)
        self.assertAlmostEqual(size, 1.0, places=5)
        # only conversion from mapunits should be affected
        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.MM, c)
        self.assertAlmostEqual(size, 23.622047, places=5)
        size = QgsSymbolLayerV2Utils.convertToPainterUnits(r, 2, QgsSymbolV2.Pixel, c)
        self.assertAlmostEqual(size, 2.0, places=5)
開發者ID:Antoviscomi,項目名稱:QGIS,代碼行數:45,代碼來源:test_qgsmapunitscale.py


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