6

I want to convert my shapefile encoding source to ASCII but unfortunately, it is not given in the encoding source type. Maybe it is given with a different name or it is not supported in QGIS?

Unfortunately there is no guide available.

1
  • instead, you can convert the coordinates and encode it in ASCII google polyline format. Each line will be represented by a single line of ascii chars, and can be stored as CSV. This is how Google store lines and coordinates. This is not in QGIS, but seems like it answers the problem.
    – sutan
    Mar 21, 2022 at 11:51

1 Answer 1

9

Many of the existing encodings are ASCII compatible, so there is no need for a dedicated ASCII encoding. E.g. latin-1 (ISO 8859-1) is one of these. And it's also the one which shapefiles should be encoded in according to the original standard (actually according to the dbf specification). Unfortunately it can only represent western european special characters.

ASCII itself only defines the first seven bits, only 128 of the 256 characters which can be represented with a single byte. The other half is defined in different encodings in the second half of the available characters. That's where latin-1/ISO8859-1 chose western european special characters.

What that means is, that giving someone a file using extended ASCII characters but not specifying the encoding is like giving someone a set of coordinates and not specifying the coordinate reference system. In explicit: it's just a bunch of bytes/numbers.

Normally file formats take this fact into account by specifying the encoding in a header whereas shapefile failes big time with respect to this but often a .cpg file is used to work around this deficiency.

Got a .cpg file? Good for you, applications will load the correct encoding automatically when opening the file.

Got none but still get strange characters? Good luck trying to figure out which to choose with trial and error. Best try through UTF-8 and the ISO8859-xx encodings.

To avoid such a situation for the consumer of your own files in the future you can do a couple of things

  • avoid shapefiles
  • if using shapefiles prefer ISO8859-1 (i.e. no special characters or only western european ones)
  • if ISO8859-1 is not possible, use UTF-8 and make sure a .cpg file is present

Interested in how ASCII and Unicode work? Have a look at this awesome explanation on Youtube

4
  • Do you have any suggestion to replace shape files?
    – Marco
    Jan 8, 2018 at 9:30
  • 2
    The trend goes towards geopackage.org Jan 8, 2018 at 9:45
  • @MatthiasKuhn Is there a specific reason not to propose UTF-8 as default encoding in general? From my limited understanding I thought, this would be "the" universal encoding for everyone and everything.
    – Bernd V.
    Jan 27, 2018 at 17:05
  • Just that the dbf specification mentions latin-1 as standard. Jan 28, 2018 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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