Shapefile — Code Page Sidecar (.cpg, UTF-8)
A one-line sidecar naming the encoding of the .dbf. Without it a reader has to guess — usually cp1252 — and every non-ASCII attribute value comes back as mojibake, which is the single most common shapefile data-loss bug.
UTF-8
Specifications
- Format
- Esri shapefile component
- Crs
- WGS 84 (EPSG:4326)
- Byte Order
- mixed — big-endian headers, little-endian records
- Sidecar Set
- .shp/.shx/.dbf/.prj/.cpg
- Content
- UTF-8
- Purpose
- declares the .dbf character encoding
- Line Endings
- LF
Testing contract
Expected to pass- Scenario
- Read the attribute table with and without honouring the .cpg declaration.
- Expected result
- With the sidecar the DBF is decoded as UTF-8; without it a reader falling back to cp1252 mis-decodes any multi-byte character.
What is a .cpg file?
A .cpg file is a one-line sidecar naming the character encoding used by a shapefile's .dbf attribute table — typically UTF-8, or a legacy code page such as ISO-8859-1 or CP1252. The dBase format has no reliable in-band encoding declaration, so without this file a reader has to guess, and non-ASCII attribute values come back as mojibake.
How to use this file
Use an example .cpg file to test shapefile readers' encoding handling, confirming that the declared code page is applied to .dbf string fields and that a missing or contradictory .cpg is reported rather than silently guessed.
How to use this file for testing
“Shapefile — Code Page Sidecar (.cpg, UTF-8)” is a deterministic Novus Examples fixture for Geospatial, Encoding detection, Metadata testing. GeoJSON, GPX, and KML files with points, lines, polygons, and tracks — for testing map tools, route parsers, and geo importers.
Documented properties for this file: LF · Esri shapefile component. Compare results against paired or grouped companions on this page when present (clean↔damaged, searchable↔scanned, or format twins) so scores stay reproducible across runs.
Download the file once, keep the path stable in CI or local scripts, and treat the spec table as the contract: dimensions, seeds, field lists, and roles are intentional. Corrupt or invalid samples are labelled as such — expect parsers to fail loudly rather than silently accept them.
Geospatial fixtures publish one invented territory across formats, with the coordinate reference system and feature counts documented in specs. Convert or reproject and diff against the twin in the same group; edge-case geometries state exactly which assumption they are built to break.
Related files
- cpgShapefile Code Page — ISO-8859-1 DeclarationThe sidecar that declares `attributes-cp1252.dbf` as ISO-8859-1. Note that the DBF also carries a language-driver byte in its header, and the two can disagree — which is exactly the ambiguity a reader has to resolve and document.

- cpgShapefile Code Page — UTF-8 DeclarationThe sidecar that declares `attributes-utf8.dbf` as UTF-8. Note that the DBF also carries a language-driver byte in its header, and the two can disagree — which is exactly the ambiguity a reader has to resolve and document.

- dbfShapefile DBF — Accented Attributes in CP1252The same four accented attribute rows written in CP1252. Both files are exactly the same size because DBF fields are fixed-width in bytes, not characters — so the UTF-8 table fits fewer characters per field, and a reader that guesses the encoding produces mojibake rather than an obvious failure.

- dbfShapefile DBF — Accented Attributes in UTF-8The same four accented attribute rows written in UTF-8. Both files are exactly the same size because DBF fields are fixed-width in bytes, not characters — so the UTF-8 table fits fewer characters per field, and a reader that guesses the encoding produces mojibake rather than an obvious failure.

- geojsonGeoJSON — bbox on Every FeatureThree features that each carry their own bbox. Spatial indexes are often built from these declared boxes instead of the geometry, so a wrong or stale one produces a query that silently misses features.

- geojsonGeoJSON — bbox on the FeatureCollectionThe five towns with a four-element bounding box on the collection, ordered west, south, east, north as RFC 7946 requires. The values are the true extent of the contained points, so a reader that recomputes the box can be scored against the declared one.

Generated by generation/geospatial.py. Free for any use, no attribution required — license.