[Qgis-developer] Specifying file encoding for vector files

Magnus Homann magnus at homann.se
Wed Jul 22 14:37:34 EDT 2009


Background:
Recently jef made some work on making project files shareable between OS:es by allowing
data sets to be specified with a reltive path in the project files. Thankful, I started
testing this with my Ubuntu and WinXP boxes, having files on a network drive.

However, opening vector files weren't as easy as I thought, the files were found but the encoding
was wrong.

Problem:
In the project file, each vector data sets have an encoding specified (e.g 'UTF-8', UTF-16', BIG5').
This encoding is specified when adding the layer to the project, and can't be changed.
Unfortunately, the default encoding when adding layers is taken from QTexCodec::codecForLocale()
and on BOTH Ubuntu and WinXP this defaults to "System". A bad name, becasue the system encoding
are infact different on different OS:es...

So, when users happily adding "System" encoded vectors on Ubuntu (i.e. UTF-8) it works flawlessly.
But when the project file is saved, and opened on WinXP the vectors are still opened with the "System"
encoding, which is not identical and the vectors are not properly read!

Unfortunately, there is no way to go from the "System" encoding to a universally recognizable name.

Current situation:
When creating a new layer, the default encoding is taken from last used encdoing.
When saving the layer as shapefile, the default encoding is UTF-8.
When adding a new layer, the default encoding is System.

Solution:
Instead of defaulting to "System", we should have another decoding set as default when the user is
prompted, and there are two solutions as I see it:

1) Go with the last used encoding everywhere.
2) Let the user specify a project wide default encoding which is used everywhere.

Ladies and gentlemen, let the voting begin!



More information about the Qgis-developer mailing list