1

I am able to set data source encoding through this answer to Setting character encoding for all layers at once using PyQGIS? and now i want to list all the datasource encodig types. how it is possible i have also check official API but nothing found!

for layer in QgsMapLayerRegistry.instance().mapLayers().values():
    layer.setProviderEncoding(u'UTF-8')
    layer.dataProvider().setEncoding(u'UTF-8')
    print layer.name(), layer.dataProvider().encoding() 
2
  • You want to list all encoding types from your layers or all encoding types available in QGIS? – Joseph Dec 1 '16 at 10:31
  • i want to get both – Muhammad Faizan Khan Dec 1 '16 at 10:33
2

The QgsVectorDataProvider class has the availableEncodings() method which provides you with a list of available encoding types:

QgsVectorDataProvider.availableEncodings()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.