I'm loading several shapefiles into QGIS using the Python console. The script works by reading a list of directories and a list of shapefiles to load from each directory, then it loads each file. Like this:
encList = "/foo/encList.txt"
shapeList = "/foo/shpList.txt"
path = "/bar/"
with open(encList) as encs:
for enc in encs:
with open(shapeList) as shps:
for shp in shps:
file=path+str(enc).rstrip()+'/'+str(enc).rstrip()+str(shp).rstrip()+".shp"
print file
qgis.utils.iface.addVectorLayer(file, str(enc).rstrip()+str(shp).rstrip(), 'ogr' )
#Use loaded layer as active layer to set the CRS
myLayer = qgis.utils.iface.activeLayer()
myLayer.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))
I would like to also configure the shapefile layers as I go along. As you would if you right click on a layer and select properties.
Specifically, I would like to change the line colours and label display. In my head I'd need something like this pseudo-code added into the loop:
if shapefile == line:
then shapefile.setColor(black)
if shapefile == points:
then shapefile.setStyle(pointDisplacement)
ans shapefile.setStyle.lable('nameOfPoint')
Or something like that. I have figured out how to do the conditions, I just need to understand how to change the attributes. Does anybody know of a way or a tutorial?
(I'm new to QGIS, but know my way around Python)