A common frustration when opening third-party or legacy ESRI Shapefiles in QGIS is seeing garbled characters or question marks in the attribute table instead of Lao script, accented letters, or Unicode text. Because the `.dbf` attribute table stores text as raw bytes without a guaranteed universal encoding tag—and legacy dBASE headers or missing `.cpg` sidecar files often cause readers to guess the wrong code page—re-saving or reading the file with the wrong encoding can turn valid text into mojibake or replace characters with `?`.
- Root Causes: Why Shapefile Attributes Turn Garbled in QGIS
- Missing or Mismatched `.cpg` Code Page File: A `.cpg` file tells GIS software which character encoding (such as `UTF-8`) was used to write the `.dbf` table; when it is missing or conflicts with reader settings, characters can decode incorrectly.
- Reader / Writer Encoding Mismatch: If data encoded in one code page is opened or exported under a mismatched encoding or default system encoding, characters can break or lose non-ASCII glyphs.
- Converting to GeoPackage (`.gpkg`) Avoids Ambiguity: Storing vector tables in GeoPackage uses UTF-8 cleanly in SQLite rather than relying on legacy `.dbf` code-page conventions.
- Key Tools & Built-In QGIS Fixes Covered
- `Layer Properties > Source` Encoding Setting: Adjusts how QGIS interprets the layer's data source character encoding when inspecting attributes.
- `Settings > Options > Data Sources` (`Ignore shapefile encoding declaration`): Controls whether QGIS honors or ignores shapefile encoding declarations when loading layers.
- `Export > Save Features As...` with `UTF-8` Encoding: Writes a clean output layer with explicit `UTF-8` encoding (and `.cpg` sidecar for Shapefiles).
- Converting to GeoPackage (`.gpkg`): Provides a modern single-file container with standard UTF-8 text storage.
- Official Documentation & Reference Portals
Verify official QGIS and GDAL vector encoding documentation through these official portals:
- Official QGIS User Manual — Working with Vector Data & Layers: https://docs.qgis.org/latest/en/docs/user_manual/managing_data_source/supported_data.html
- Official QGIS User Manual — Creating & Exporting Layers: https://docs.qgis.org/latest/en/docs/user_manual/managing_data_source/create_layers.html
- Official GDAL ESRI Shapefile / DBF Driver Documentation: https://gdal.org/en/stable/drivers/vector/shapefile.html
- Official QGIS Desktop Download Portal: https://qgis.org/download/
- Step-by-Step Fix: Repairing Garbled Text Encoding in QGIS
- Add the Shapefile to QGIS: Load your `.shp` file into QGIS via the `Browser` panel or `Layer > Add Layer > Add Vector Layer...` and open its `Attribute Table` to inspect how text currently appears.
- Check Data Source Encoding in Layer Properties: Right-click the layer in the `Layers` panel, open `Properties > Source` (or `General`), set `Data source encoding` to `UTF-8` (or test the matching source encoding if known), click `Apply` / `OK`, and re-check the `Attribute Table`.
- Check QGIS Data Source Encoding Options: If needed, open `Settings > Options > Data Sources` and review `Ignore shapefile encoding declaration` so `.cpg` / encoding behavior matches your workflow.
- Export a Clean Copy with `UTF-8`: Once the text displays properly, right-click the layer and choose `Export > Save Features As...`, select `ESRI Shapefile` (with `UTF-8` encoding so a matching `.cpg` is written) or `GeoPackage` (`.gpkg`), save to a new file path, and save your QGIS project.
- How to Prevent Future Encoding Issues: Best Practices
- Standardize on `UTF-8` When Exporting: Always pick `UTF-8` when creating new Shapefiles or exporting vector layers in QGIS instead of leaving ambiguous defaults.
- Keep All Sidecar Files Together: When copying or sharing a Shapefile, keep `.shp`, `.shx`, `.dbf`, `.prj`, and `.cpg` together in the same folder.
- Prefer GeoPackage (`.gpkg`) for Modern GIS Workflows: Use `.gpkg` for project storage and data exchange when you want UTF-8 SQLite tables and a single portable file.
- Convert Only Once from True Source Encoding: Identify the true source encoding first and export once cleanly rather than repeatedly re-saving already-corrupted text.
6. Frequently Asked Questions (FAQ)
- Why do characters sometimes turn into `?` instead of garbled symbols?If text was already written or exported with a single-byte code page that cannot represent non-Latin or Unicode characters, those characters may be replaced with `?` during conversion or export.
- What is a `.cpg` file in a Shapefile folder?A `.cpg` sidecar file records the character code page (such as `UTF-8`) used for the `.dbf` attribute table so GIS tools read text with the intended encoding.
- Should I export fixed layers to a new file rather than overwriting immediately?Yes. Saving to a new file or GeoPackage first lets you verify every attribute column before replacing working files.