Change Shapefile Data Source Encoding – Quick Guide

encodingpyqgisqgis

I tried to change the only the shapefile datasource encoding through properties and also How to encode shapefiles from LATIN1 to UTF-8? but it doesn't change it.

Without saving the QGIS project can't I directly change the shapefile datasource encoding?

I also tried this code, it shows change encoding but as I open the shapefile again it show the same old system encoding:

for layer in QgsMapLayerRegistry.instance().mapLayers().values():
    layer.setProviderEncoding(u'UTF-8')
    layer.dataProvider().setEncoding(u'UTF-8')
    print layer.name(), layer.dataProvider().encoding()  

(I am not saving QGIS project, just accessing and saving shapefile directly. When I save the project and do this task then it work correctly)

Best Answer

From the menubar, go to:

Settings > Options > Data Sources > Data source handling

and uncheck the Ignore shapefile encoding declaration setting:

Encoding setting

This sets all layers loaded into QGIS to be default encoded to UTF-8