3

I have created a new shapefile layer which uses Khmer language fields. The encoding is UTF-8. When I create new fields in Khmer in the attribute table it displays perfectly. Then as soon as I hit save a number of the characters are replaced with question marks. I also get the following error:

"Could not commit changes to layer ករណី

Errors: SUCCESS: 2 attribute(s) added. ERROR: field with index 3 is not the same! Provider: ogr Storage: ESRI Shapefile expected field: name=ឈ្មោះ type=QString typeName=string len=20 precision=0
retrieved field: name=ឈ្��_1 type=QString typeName=String len=20 precision=0"

0

1 Answer 1

6

Shapefile is an old format with many limitations. One of them is the Unknown character set:

There is no way to specify the character set used in the database. Many applications are using the old Windows-* or ISO-* data encodings, while nowadays we are tending to use UTF-8 more. Still there is no way to specify this in file header. The support for Unicode characters is also very limited.
http://switchfromshapefile.org/#characterset

So you should use another format e.g. GeoPackage which is the default format in QGIS and is supported in most GIS. Depending on what you intend to do (share files with other users e.g.), there might be other options, see Shapefile Alternatives.

If for some reason you have to stick to shapefiles, it's probably better to use only Latin/ASCII characters. Depending on the use case, you could link to a separate file containing the Khmer language content.

Vector layer, saved with field names and field values in Khmer alphabet; on the left side saved as Geopackage; from this, I saved as Shapefile (right side), where you see that some characters are represented as ?:

enter image description here

4
  • 1
    It looks like it's the attribute names themselves that are failing rather than the contents of the attributes.
    – Ian Turton
    Commented Jun 22 at 15:58
  • Yes, exactly for that reason Geopackage is preferable, as it does accept such fieldnames: tested with Geopackage and Shapefile - a fieldname in Khmer saves perfectly well in Geopackage, but not in Shapefile.
    – Babel
    Commented Jun 22 at 16:09
  • But I think that is a baked in limitation of the (American) specification, rather than a problem with the character set which can be overcome with a cfg file
    – Ian Turton
    Commented Jun 23 at 8:50
  • 1
    Indeed. So by default, Shapefiles can't handle this and using a cfg makes the already complicated handling of Shapefiles not easier. So if there are no strong reasons why to use the outdated Shapefile format, using Geopackage is easier, more flexible and has several other advantages over Shapefiles.
    – Babel
    Commented Jun 23 at 10:08

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.