本文整理匯總了Python中qgis.core.QgsSymbolLayerV2Utils類的典型用法代碼示例。如果您正苦於以下問題:Python QgsSymbolLayerV2Utils類的具體用法?Python QgsSymbolLayerV2Utils怎麽用?Python QgsSymbolLayerV2Utils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QgsSymbolLayerV2Utils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _getSymbolWidth
def _getSymbolWidth(self, context, width, unit):
scale = 1.0
if unit == QgsSymbolV2.MapUnit:
scale = QgsSymbolLayerV2Utils.lineWidthScaleFactor(
context, QgsSymbolV2.MM) / QgsSymbolLayerV2Utils.lineWidthScaleFactor(context, QgsSymbolV2.MapUnit)
width = max(width + 2 * self._buffer * scale, self._minWidth * scale)
return width
示例2: testMapUnitScaleFactor
def testMapUnitScaleFactor(self):
# test QgsSymbolLayerV2Utils::mapUnitScaleFactor() 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
c = QgsMapUnitScale()
sf = QgsSymbolLayerV2Utils.mapUnitScaleFactor(r, QgsSymbolV2.MapUnit, c)
self.assertAlmostEqual(sf, 1.0, places=5)
sf = QgsSymbolLayerV2Utils.mapUnitScaleFactor(r, QgsSymbolV2.MM, c)
self.assertAlmostEqual(sf, 23.622047, places=5)
sf = QgsSymbolLayerV2Utils.mapUnitScaleFactor(r, QgsSymbolV2.Pixel, c)
self.assertAlmostEqual(sf, 2.0, places=5)
示例3: set_alpha
def set_alpha(values, feature, parent):
"""
Sets the alpha component of a color
<p><h4>Syntax</h4>
set_alpha(<i>color</i>, <i>alpha</i>)</p>
<p><h4>Arguments</h4>
<i> color</i> → a color<br>
<i> alpha</i> → an alpha value between 0 and 255<br></p>
<p><h4>Example</h4>
<!-- Show example of function.-->
set_alpha('255,255,255,255', 125) → '255,255,255,125'</p>
"""
try:
color = QgsSymbolLayerV2Utils.decodeColor(values[0])
color.setAlpha(values[1])
return QgsSymbolLayerV2Utils.encodeColor(color)
except:
return None
示例4: set_hsv_value
def set_hsv_value(values, feature, parent):
"""
Sets the value of a color
<p><h4>Syntax</h4>
set_hsv_value(<i>color</i>, <i>value</i>)</p>
<p><h4>Arguments</h4>
<i> color</i> → a color<br>
<i> value</i> → a integer between 0 and 100<br></p>
<p><h4>Example</h4>
<!-- Show example of function.-->
set_hsv_value('0,255,0,255', 50) → '0,128,0,255'</p>
"""
try:
color = QgsSymbolLayerV2Utils.decodeColor(values[0])
color.setHsvF(color.hueF(), color.saturationF(), values[1] / 100.0, color.alphaF())
return QgsSymbolLayerV2Utils.encodeColor(color)
except:
return None
示例5: set_hue
def set_hue(values, feature, parent):
"""
Sets the hue component of a color
<p><h4>Syntax</h4>
set_hue(<i>color</i>, <i>hue</i>)</p>
<p><h4>Arguments</h4>
<i> color</i> → a color<br>
<i> hue</i> → a integer between 0 and 360<br></p>
<p><h4>Example</h4>
<!-- Show example of function.-->
set_hue('0,255,0,255', 0) → '255,0,0,255'</p>
"""
try:
color = QgsSymbolLayerV2Utils.decodeColor(values[0])
color.setHslF(values[1] / 360.0, color.saturationF(), color.lightnessF(), color.alphaF())
return QgsSymbolLayerV2Utils.encodeColor(color)
except:
return None
示例6: toDomElement
def toDomElement(self, domDocument):
"""
Returns a QDomElement with the object instance settings
"""
spColumnElement = domDocument.createElement("SpatialField")
spColumnElement.setAttribute("name",self._spatialField)
spColumnElement.setAttribute("labelField",self._labelField)
spColumnElement.setAttribute("itemid",self._itemId)
spColumnElement.setAttribute("srid",self._srid)
spColumnElement.setAttribute("geomType",self._geomType)
spColumnElement.setAttribute("zoom",self._zoom_level)
symbolElement = domDocument.createElement("Symbol")
#Append symbol properties element
if not self._symbol is None:
prop = self._symbol.properties()
QgsSymbolLayerV2Utils.saveProperties(prop,domDocument,symbolElement)
symbolElement.setAttribute("layerType",self._layerType)
spColumnElement.appendChild(symbolElement)
return spColumnElement
示例7: testConvertToPainterUnits
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)
示例8: testPixelSizeScaleFactor
def testPixelSizeScaleFactor(self):
# test QgsSymbolLayerV2Utils::pixelSizeScaleFactor() 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()
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.MapUnit, c)
self.assertAlmostEqual(sf, 0.5, places=5)
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.MM, c)
self.assertAlmostEqual(sf, 11.8110236, places=5)
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.Pixel, c)
self.assertAlmostEqual(sf, 1.0, places=5)
# minimum scale greater than the renderer scale, so should be limited to minScale
c.minScale = 1 / 150000000.0
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.MapUnit, c)
self.assertAlmostEqual(sf, 3.8925045, places=5)
# only conversion from mapunits should be affected
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.MM, c)
self.assertAlmostEqual(sf, 11.811023, places=5)
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.Pixel, c)
self.assertAlmostEqual(sf, 1.0, places=5)
c.minScale = 0
# maximum scale less than the renderer scale, so should be limited to maxScale
c.maxScale = 1 / 350000000.0
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.MapUnit, c)
self.assertAlmostEqual(sf, 0.5, places=5)
# only conversion from mapunits should be affected
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.MM, c)
self.assertAlmostEqual(sf, 11.8110236, places=5)
sf = QgsSymbolLayerV2Utils.pixelSizeScaleFactor(r, QgsSymbolV2.Pixel, c)
self.assertAlmostEqual(sf, 1.0, places=5)
示例9: testEncodeDecode
def testEncodeDecode(self):
# test encoding and decoding QgsMapUnitScale
s = QgsMapUnitScale()
s.minScale = 50
s.maxScale = 100
s.minSizeMMEnabled = True
s.minSizeMM = 3
s.maxSizeMMEnabled = False
s.maxSizeMM = 99
encode = QgsSymbolLayerV2Utils.encodeMapUnitScale(s)
r = QgsSymbolLayerV2Utils.decodeMapUnitScale(encode)
self.assertEqual(s, r)
# check old style encoding
encode = '9,78.3'
r = QgsSymbolLayerV2Utils.decodeMapUnitScale(encode)
self.assertEqual(r.minScale, 9)
self.assertEqual(r.maxScale, 78.3)
self.assertFalse(r.minSizeMMEnabled)
self.assertEqual(r.minSizeMM, 0)
self.assertFalse(r.maxSizeMMEnabled)
self.assertEqual(r.maxSizeMM, 0)
示例10: create
def create(dom_document):
"""
Create an instance of the 'SpatialFieldsConfiguration' object from a DOM document.
Returns None if the dom_document is invalid.
"""
from stdm.ui.composer import SpatialFieldMapping
dataSourceElem = dom_document.documentElement().firstChildElement("DataSource")
if dataSourceElem == None:
return None
spatialFieldsConfigElement = dataSourceElem.firstChildElement("SpatialFields")
spFieldsConfig = SpatialFieldsConfiguration()
#Get spatial field mappings
spatialFieldMappingList = spatialFieldsConfigElement.elementsByTagName("SpatialField")
numItems = spatialFieldMappingList.length()
for i in range(numItems):
spatialFieldMappingElement = spatialFieldMappingList.item(i).toElement()
labelField = spatialFieldMappingElement.attribute("labelField")
spatialField = spatialFieldMappingElement.attribute("name")
itemId = spatialFieldMappingElement.attribute("itemid")
srid = int(spatialFieldMappingElement.attribute("srid"))
geomType = spatialFieldMappingElement.attribute("geomType")
zoom = float(spatialFieldMappingElement.attribute("zoom"))
zoom_type = spatialFieldMappingElement.attribute('zoomType', 'RELATIVE')
#Create spatial field mapping
spFieldMapping = SpatialFieldMapping(spatialField,labelField)
spFieldMapping.setItemId(itemId)
spFieldMapping.setSRID(srid)
spFieldMapping.setGeometryType(geomType)
spFieldMapping.setZoomLevel(zoom)
spFieldMapping.zoom_type = zoom_type
symbolElement = spatialFieldMappingElement.firstChildElement("Symbol")
if not symbolElement is None:
layerType = symbolElement.attribute("layerType")
layerProps = QgsSymbolLayerV2Utils.parseProperties(symbolElement)
symbolLayer = QgsSymbolLayerV2Registry.instance().createSymbolLayer(layerType,layerProps)
spFieldMapping.setSymbolLayer(symbolLayer)
spFieldsConfig.addSpatialFieldMapping(spFieldMapping)
return spFieldsConfig
示例11: blue
def blue(values, feature, parent):
"""
Returns the blue component of a color
<p><h4>Syntax</h4>
blue(<i>color</i>)</p>
<p><h4>Arguments</h4>
<i> color</i> → a color<br></p>
<p><h4>Example</h4>
<!-- Show example of function.-->
blue('0,0,255') → 255</p>
"""
try:
return QgsSymbolLayerV2Utils.decodeColor(values[0]).blue()
except:
return None
示例12: alpha
def alpha(values, feature, parent):
"""
Returns the alpha component of a color
<p><h4>Syntax</h4>
alpha(<i>color</i>)</p>
<p><h4>Arguments</h4>
<i> color</i> → a color<br></p>
<p><h4>Example</h4>
<!-- Show example of function.-->
alpha('255,255,255,125') → 125</p>
"""
try:
return QgsSymbolLayerV2Utils.decodeColor(values[0]).alpha()
except:
return None
示例13: hsv_value
def hsv_value(values, feature, parent):
"""
Returns the hsv value component of a color, an integer between 0-100
<p><h4>Syntax</h4>
hsv_value(<i>color</i>)</p>
<p><h4>Arguments</h4>
<i> color</i> → a color<br></p>
<p><h4>Example</h4>
<!-- Show example of function.-->
hsv_value('125,255,125') → 100</p>
"""
try:
# Value ranges from 0 - 100
return int(QgsSymbolLayerV2Utils.decodeColor(values[0]).valueF() * 100)
except:
return None
示例14: lightness
def lightness(values, feature, parent):
"""
Returns the lightness of a color, an integer between 0-100
<p><h4>Syntax</h4>
lightness(<i>color</i>)</p>
<p><h4>Arguments</h4>
<i> color</i> → a color<br></p>
<p><h4>Example</h4>
<!-- Show example of function.-->
lightness('125,255,125') → 74</p>
"""
try:
# Lightness ranges from 0 - 100
return int(QgsSymbolLayerV2Utils.decodeColor(values[0]).lightnessF() * 100)
except:
return None
示例15: saturation
def saturation(values, feature, parent):
"""
Returns the saturation of a color, an integer between 0-100
<p><h4>Syntax</h4>
saturation(<i>color</i>)</p>
<p><h4>Arguments</h4>
<i> color</i> → a color<br></p>
<p><h4>Example</h4>
<!-- Show example of function.-->
saturation('125,255,125') → 50</p>
"""
try:
# Saturation ranges from 0 - 100
return int(QgsSymbolLayerV2Utils.decodeColor(values[0]).saturationF() * 100)
except:
return None