I am adding a number of spatial csv files as layers and want to assign a qml layer style.
import processing
# User Dialog to pick Import_QGIS folder
Folder_Path = QFileDialog.getExistingDirectory(caption="Pick the folder 'Import_QGIS'.")
# Folder_Path for uri
Folder_Path_uri = "file:///"+ Folder_Path + "/"
# Make a tuple with the filenames
import os
i=0
my_tuple=[]
for file in os.listdir(Folder_Path):
First3Letters = file[0:2]
try:
int(First3Letters) < 300
print(file)
my_tuple.append(file)
i+=1
except:
continue
iNum = int(i)
print(iNum)
for x in range(iNum):
try:
uri = Folder_Path_uri + my_tuple[x] + "?type=csv&delimiter=,&detectTypes=yes&xField=X_Wert_Pos&yField=Y_Wert_Pos&crs=epsg:25832&spatialIndex=no&subsetIndex=no&watchFile=no"
print(uri)
mem_layer = QgsVectorLayer(uri, my_tuple[x], 'delimitedtext')
QgsProject.instance().addMapLayer(mem_layer)
mem_layer.loadNamedStyle("C:\Layer_styles\style3.qml")
x+=1
except:
break
All layers in the specific folder are added as new layers, but only with the default style. What am I missing?
r"C:\Layer_styles\style3.qml"
and aftermem_layer.triggerRepaint()