4

I am developing a QGIS plugin that, after a series of inputs, will produce a thematic map using the QgsGraduatedSymbolRendererV2. Because the polygon are very small, the boarders make it such that when zoomed out the entire map almost looks completely black. I want to remove the boarders to do this but no documentation or form I have found have demonstrated how to do this. Below is what I have to create the thematic map, but somewhere in there I need to set the border style to 'no pen'. But how!?

  uri = QgsDataSourceURI()
  # set host name, port, database name, username and password
  uri.setConnection("localhost", "5432", "public", "postgres", "password")

  uri.setDataSource("susip", str(filename)+"_mce_results", "the_geom")
  layer = QgsVectorLayer(uri.uri(), str(filename)+"_mce_results", "postgres")

  fieldName = "score"
  fieldIndex = layer.fieldNameIndex( columnName )
  provider = layer.dataProvider()
  numberOfClasses = 10
  color1 = QColor("red")  
  color2 = QColor("green")
  color3 = QColor("white")
  ramp = QgsVectorGradientColorRampV2(color1, color2)

  renderer = QgsGraduatedSymbolRendererV2.createRenderer(layer, columnName, numberOfClasses, QgsGraduatedSymbolRendererV2.Quantile, QgsSymbolV2.defaultSymbol(layer.geometryType()), ramp)

  layer.setRendererV2( renderer )
  QgsMapLayerRegistry.instance().addMapLayer( layer )
2
  • Check this answer out: gis.stackexchange.com/questions/53121/…
    – A.A
    Commented Nov 22, 2016 at 14:00
  • This question is very old but, I found the answer. It's necessary for each symbol (QgsFillSymbolV2 for polygon geometry) to use 'setOutputUnit' method to set it with value equal 1.
    – xunilk
    Commented Jul 9, 2017 at 15:02

1 Answer 1

1

This question is very old but, I found the answer. It's necessary for each symbol (QgsFillSymbolV2 for polygon geometry) to use 'setOutputUnit' method to set it with value equal 1. Complete code is:

from qgis.PyQt.QtGui import QColor

layer = iface.activeLayer()

fieldName = "FID"

provider = layer.dataProvider()
numberOfClasses = 10
color1 = QColor("red")  
color2 = QColor("green")
color3 = QColor("white")

ramp = QgsVectorGradientColorRampV2(color1, color2)

renderer = QgsGraduatedSymbolRendererV2.createRenderer(layer, 
                                                       fieldName, 
                                                       numberOfClasses, 
                                                       QgsGraduatedSymbolRendererV2.Quantile, 
                                                       QgsSymbolV2.defaultSymbol(layer.geometryType()), 
                                                       ramp)

symbols = renderer.symbols()

for symbol in symbols:
    symbol.setOutputUnit(1) #1 is for no pen

layer.setRendererV2( renderer )

layer.triggerRepaint()

I tried it out with this shapefile:

enter image description here

After running the code at Python Console of QGIS I got:

enter image description here

It works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.