How is attribute data in DBF file tied to shapefile location data in SHP file?

As documented in the shapefile specification (p. 25), only record number links the SHP/SHX pair to the DBF :

The record order must be the same as the order of shape features in the main (*.shp) file.

There is a popular myth that the SHX file serves as a lookup to the dBase file, but this is not true. The SHX is only a fixed width complement to the SHP file, allowing direct access by record number into the variable record width SHP file.

Both the SHP and SHX have 100 byte fixed headers, and the DBF has a 32-byte fixed header and one additional 32-byte header per field. Once you know the byte position for the first record, both the SHX and DBF are fixed width, while the SHP is variable width by vertex count (point SHP files are also fixed width, so the illustration below would be for multipoint, polyline, polygon, or multipatch).

shapefile layout

Tags:

Shapefile