Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Shapefile

From ReverseEngineering.wiki
Format
Magic 00 00 27 0A
Extensions .shp, .shx, .dbf, .prj
Endianness mixed (header big-endian, contents little-endian)
On this wiki Facts · Code · Notes · Topics

Esri Shapefile, the classic vector GIS format: a .shp main file (100-byte header with big-endian file code 9994 and little-endian version 1000, shape type and bounding box, then records), a .shx index and a .dbf attribute table.

Overview

A shapefile is a set of sibling files with the same base name. The .shp holds geometry, the .shx an index of record offsets, the .dbf per-record attributes (Unverified: dBASE format, not read here), and the optional .prj the coordinate system as text (Unverified).

Header

The 100-byte header of .shp and .shx starts with the file code 9994 (bytes 00 00 27 0A, big-endian); the file length is in 16-bit words, big-endian; the version 1000 and the shape type are little-endian, followed by the bounding box as eight little-endian doubles (X min, Y min, X max, Y max, Z min, Z max, M min, M max). The shapelib reader accepts 0x0A or 0x0D as the last byte of the file code. See Fact:Shapefile/struct/Main file header and Fact:Shapefile/enum/Shape types.

Records

Unverified: each record has an 8-byte big-endian header (record number, content length in words) followed by a little-endian shape type and the geometry; the .shx has one 8-byte entry (offset, length, both in words) per record. The checked shapelib code derives the record count from the .shx length: (length in words - 50) / 4.

Code & repositories

shapelib (MIT or LGPL-2.0-or-later).

  • https://github.com/OSGeo/shapelib @ 6e3ac42088274d3a68c0c35aa42e0ddf7f80104e · license: MIT OR LGPL-2.0-or-later (declared by the contributor; GitHub's detector did not recognize LICENSE-LGPL)
    C library reading and writing shapefiles; shpopen.c holds the header code and shapefil.h the shape types
    Tested on: source read, not run: source read only · checked 2026-10-19; last activity 2026-04-12; Note: the latest release ships binaries; the wiki links only the source, never the binaries