How can I change the fill border color for vector layers? I want to make it Transparent Fill. I have 1000 shapefiles, and want them to be transparent fill. Is there a way to do it by Python Script?
-
1What kind of vector layers? Are they all polygons, lines, points, or a mixture of all three?– JosephDec 7, 2016 at 10:32
2 Answers
While setting the outline colour for vector layer, set opacity to '0', then outline will be transparent in Layer Properties -> Style, then save your layer style the layer style as .qml file and apply the same style to all layers. To apply layer style for layer using following codes in python console
# create vector layer object
vector_file = '/path/to/vetor.shp'
vector = QgsVectorLayer(vector_file, 'vector name', 'ogr')
# Adds vector layer to registry
QgsMapLayerRegistry.instance().addMapLayer(vector)
# Set the layer style from qml file
vector.loadNamedStyle('/path/to/file.qml')
# Refresh the canvas to make the change in layer style visible
iface.mapCanvas().refresh()
Use some loop to repeat do the same for multiple layers. See here to load multiple layers.
-
This is a good solution if all layers should have the exact same style. My guess is that the layers will have their own particular style and the OP just wants to set the outline to be transparent. Nevertheless, +1 ;)– JosephDec 7, 2016 at 13:32
-
Thanks !it works too. but i used some other code for making it transparent :)– User18Dec 8, 2016 at 6:58
To Fill Layer background Transparent .Use code as follows :
from PyQt4 import QtGui
layer = iface.addVectorLayer("path_to_vector_layer", "layer_name", "ogr")
myVectorLayer = iface.activeLayer()
myRenderer = myVectorLayer.rendererV2()
if myVectorLayer.geometryType() == QGis.Polygon:
mySymbol1 = QgsFillSymbolV2.createSimple({'color':'#ffffff',
'color_border':'#000000',
'width_border':'0.6'})
myRenderer.setSymbol(mySymbol1)
myVectorLayer.triggerRepaint()
It works for me :)