[Qgis-developer] how to set square symbol in a point layer with python

Stefano Masera stefano.masera at arpa.piemonte.it
Mon Oct 13 02:51:17 PDT 2014


Thanks for the answer! 
Sorry but I didn't understand how to use QgsSimpleMarkerSymbolLayerV2. 
I did some attempt but I didn't manage.. 
Below there's my code (with only two symbol item as example) 



myTargetField = field 
myRangeList = [] 
myOpacity = 1 



# symbol 1 
mySymbol = QgsSymbolV2.defaultSymbol(layer.geometryType()) 
mySymbol.setColor(QColor('#FFFFFF')) 
mySymbol.setAlpha(myOpacity) 
myRange = QgsRendererRangeV2(0.1,34.4,mySymbol,"< 35") 
myRangeList.append(myRange) 
# symbol 2 
mySymbol = QgsSymbolV2.defaultSymbol(layer.geometryType()) 
mySymbol.setColor(QColor('#238443')) 
mySymbol.setAlpha(myOpacity) 
myRange = QgsRendererRangeV2(34.5,39.4,mySymbol,"35 - 39 dB(A)") 
myRangeList.append(myRange) 

# other symbol items 




myRenderer = QgsGraduatedSymbolRendererV2('', myRangeList) 
myRenderer.setMode(QgsGraduatedSymbolRendererV2.EqualInterval) 
myRenderer.setClassAttribute(myTargetField) 

layer.setRendererV2(myRenderer) 
iface.legendInterface().refreshLayerSymbology(layer) 
layer.triggerRepaint() 


And I want that symbol 1 became a square. 
I can't understand how to use QgsSimpleMarkerSymbolLayerV2. 

Sorry and thank you! 

C 
S 











----- Messaggio originale -----

Da: "Salvatore Larosa" <lrssvtml at gmail.com> 
A: "Stefano Masera" <stefano.masera at arpa.piemonte.it> 
Cc: "qgis-developer" <qgis-developer at lists.osgeo.org> 
Inviato: Lunedì, 13 ottobre 2014 11:21:37 
Oggetto: Re: [Qgis-developer] how to set square symbol in a point layer with python 

Hi, 

On Mon, Oct 13, 2014 at 10:11 AM, Stefano Masera 
<stefano.masera at arpa.piemonte.it> wrote: 
> Hi list, 
> I wan't to set a square symbol in a point layer with python. 
> 
> Currently, I use a graduated symbol legend, and I have a circle (point) 
> symbol with this line for each item: 
> 
> symbol = QgsSymbolV2.defaultSymbol(layer.geometryType()) 
> 
> But I want to set a square for one item. 
> 
> How can I do? 

after having got the symbol layer (QgsSimpleMarkerSymbolLayerV2) you 
can use the setName() method to change from circle (default) to any 
other symbol. In your case setName("square"). 

Regards, 
-SL 

-- 
Salvatore Larosa 
linkedIn: http://linkedin.com/in/larosasalvatore 
twitter: @lrssvt 
skype: s.larosa 
IRC: lrssvt on freenode 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20141013/5b2e5ef2/attachment.html>


More information about the Qgis-developer mailing list