[Qgis-developer] QgsRendererRangeV2.symbol() dumps QGIS

Tom Chadwin tom.chadwin at nnpa.org.uk
Mon Mar 14 03:33:01 PDT 2016


Here's a fuller code snippet. 

# cleanedLayer is a memory layer with the extra fields added for height,
roof, colour, and wall colour
# i is the original layer
# canvas is obviously iface.mapCanvas()

fields = cleanedLayer.pendingFields()
renderer = i.rendererV2()
renderContext = QgsRenderContext.fromMapSettings(
        canvas.mapSettings())
feats = i.getFeatures()
context = QgsExpressionContext()
context.appendScope(QgsExpressionContextUtils.layerScope(i))
expression = QgsExpression('eval(@qgis_25d_height)')
heightField = fields.indexFromName("height")
wallField = fields.indexFromName("wallColor")
roofField = fields.indexFromName("roofColor")
renderer.startRender(renderContext, fields)
cleanedLayer.startEditing()
for feat in feats:
    context.setFeature(feat)
    height = expression.evaluate(context)
    if isinstance(renderer, QgsCategorizedSymbolRendererV2):
        classAttribute = renderer.classAttribute()
        attrValue = feat.attribute(classAttribute)
        catIndex = renderer.categoryIndexForValue(attrValue)
        categories = renderer.categories()
        symbol = categories[catIndex].symbol()
    elif isinstance(renderer, QgsGraduatedSymbolRendererV2):
        classAttribute = renderer.classAttribute()
        attrValue = feat.attribute(classAttribute)
        ranges = renderer.ranges()
        for range in ranges:
            if (attrValue >= range.lowerValue() and
                    attrValue <= range.upperValue()):
                symbol = range.symbol()
    else:
        symbol = renderer.symbolForFeature2(feat, renderContext)

As I say, this works for single symbol and categorized renderers, but dumps
QGIS for graduated renderers, crashing on the line:

symbol = range.symbol()

What's the cause?



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/QgsRendererRangeV2-symbol-dumps-QGIS-tp5255977p5256184.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list