本文整理匯總了Python中qgis.core.QgsSymbolLayerV2Utils.convertToMapUnits方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsSymbolLayerV2Utils.convertToMapUnits方法的具體用法?Python QgsSymbolLayerV2Utils.convertToMapUnits怎麽用?Python QgsSymbolLayerV2Utils.convertToMapUnits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.core.QgsSymbolLayerV2Utils
的用法示例。
在下文中一共展示了QgsSymbolLayerV2Utils.convertToMapUnits方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testConvertToMapUnits
# 需要導入模塊: from qgis.core import QgsSymbolLayerV2Utils [as 別名]
# 或者: from qgis.core.QgsSymbolLayerV2Utils import convertToMapUnits [as 別名]
def testConvertToMapUnits(self):
# test QgsSymbolLayerV2Utils::convertToMapUnits() 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.convertToMapUnits(r, 2, QgsUnitTypes.RenderMapUnits, c)
self.assertEqual(size, 2.0)
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderMillimeters, c)
self.assertAlmostEqual(size, 47.244094, places=5)
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderPixels, c)
self.assertAlmostEqual(size, 4.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.convertToMapUnits(r, 2, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(size, 118.1102362, places=5)
# only conversion from mapunits should be affected
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderMillimeters, c)
self.assertAlmostEqual(size, 47.244094, places=5)
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderPixels, c)
self.assertAlmostEqual(size, 4.0, places=5)
c.minSizeMMEnabled = False
# maximum size less than the calculated size, so size should be limited to maxSizeMM
c.maxSizeMM = 0.05
c.maxSizeMMEnabled = True
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(size, 1.1811023622047245, places=5)
# only conversion from mapunits should be affected
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderMillimeters, c)
self.assertAlmostEqual(size, 47.244094, places=5)
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderPixels, c)
self.assertAlmostEqual(size, 4.0, places=5)
c.maxSizeMMEnabled = False
# test with minimum scale set
c.minScale = 1 / 150000000.0
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(size, 15.57001821, places=5)
# only conversion from mapunits should be affected
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderMillimeters, c)
self.assertAlmostEqual(size, 47.244094, places=5)
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderPixels, c)
self.assertAlmostEqual(size, 4.0, places=5)
c.minScale = 0
# test with maximum scale set
c.maxScale = 1 / 1550000000.0
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderMapUnits, c)
self.assertAlmostEqual(size, 1.50677595625, places=5)
# only conversion from mapunits should be affected
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderMillimeters, c)
self.assertAlmostEqual(size, 47.244094, places=5)
size = QgsSymbolLayerV2Utils.convertToMapUnits(r, 2, QgsUnitTypes.RenderPixels, c)
self.assertAlmostEqual(size, 4.0, places=5)
c.maxScale = 0