4

I've been asked to map an area of land using QGIS, so I created a new vector layer polygon and saved it to my PC without problems.

They've asked for the following files: .shp, .shx, .dbf, .prj and .cpg.

When I go to the folder containing my saved polygon files, all files except .cpg are there.

How do I create a .cpg file for my polygon?

2
  • 3
    .cpg isn't a required extension for your file. From gisgeography.com/arcgis-shapefile-files-types-extensions : ".cpg: These are optional plain text files that describes the encoding applied to create the Shapefile. If your shapefile doesn’t have a cpg file, then it has the system default encoding."
    – MaryBeth
    Jul 5 '17 at 18:48
  • Thanks MaryBeth. They've said they definitely need a .cpg file but I'll try and explain to them what you said.
    – bird0507
    Jul 5 '17 at 19:20
10

The .cpg file is optional.

It is used to specify the code page (only for .dbf) for identifying the character encoding to be used (for example to encode utf-8).

It should not be a problem for the one who gets the shapefile to open it without .cpg-file

For further information https://en.wikipedia.org/wiki/Shapefile

But if you really need that file. just open a texteditor and write "UTF-8" into the first line and save it as "shapefilename.cpg"

3
  • Thanks Dirk, I'll try your text editor suggestion. What does UTF-8 mean?
    – bird0507
    Jul 5 '17 at 19:26
  • UTF-8 is a character encoding capable of encoding all possible Unicode code points. It encodes the text so all possible letters are written correctly and not like hieroglyphics en.wikipedia.org/wiki/UTF-8
    – DirkB.
    Jul 5 '17 at 19:31
  • To decide if you really need that file, check if the attributes contain wrong representations of characters. E.g. "Kreisbögen" instead of "Kreisbögen" etc. In QGIS you can also go to "Layer Properties -> Source -> Data Source Encoding" to quickly check some different encodings that are correct for the data you have. Jul 17 '19 at 9:11
0

A quick update to the answer. You may find that your data haven't been saved in UTF-8. You will need to use a different code in the cpg file.

For example, Latin-9 requires the code ISO 88591 instead. Just that, one small line of text at the top of a text file. The encoding of this text file (the cpg file) can be UTF-8 or whatever the OS prefers.

QGIS doesn't need the cpg file and works out for itself what the dbf file's encoding is.

-3

In the 'Save As' window select 'UTF-8'as Encoding.

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.