2

I am seeing different behaviours when applying style files to rasters and vectors. This code opens a vector, fixes the geometry and adds that to the map with a preset style from a qml file:

#add, fix and style the  vector
segname=outname[:-4]+'.gpkg'
#result = iface.addVectorLayer(segname, "", "ogr")
segname2=outname[:-4]+'_fix.gpkg'
#layer = iface.activeLayer()
fix_layer = processing.run("native:fixgeometries", {'INPUT':segname,'OUTPUT':segname2})['OUTPUT']
result = iface.addVectorLayer(segname2, "", "ogr")
layer = iface.activeLayer()
layer.loadNamedStyle('/media/patrice/DataDrive/GORiM/ManualFineTuning/SegmentStyle.qml')
layer.triggerRepaint()
layer = iface.activeLayer()
layer.startEditing()

This code adds the raster, but does nothing with the style file.

Zone=os.path.basename(images[i])[-8:-4]
Sample=os.path.basename(images[i])[3:7]
#add the image
Cname=os.path.basename(images[i])[:-4]
#print(uri)
rlayer = iface.addRasterLayer(images[i],Cname,"gdal")
vLayer = iface.activeLayer()
canvas = iface.mapCanvas()
extent = vLayer.extent()
iface.mapCanvas().setExtent(extent)
iface.mapCanvas().refresh()
layer = iface.activeLayer()
layer.loadNamedStyle('/media/patrice/DataDrive/GORiM/ManualFineTuning/ImageNIRStyle.qml')
layer.triggerRepaint()

Any ideas why? Both style files work fine when used manually in QGIS symbology.

1 Answer 1

1

It was a typo in my style file name. Useful info is that the console did NOT return an error for a non-existent file.

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.