Last modified by Farooq Sheikh on 2019/10/11 06:07

What is a SHP file?

SHP is the file extension for one of the primary file types used for representation of ESRI Shapefile. It represents Geospatial information in the form of vector data to be used by Geographic Information Systems (GIS) applications. The format has been developed as open specifications in order to facilitate interoperability between ESRI and other software products.

Data Representation

As mentioned, a shapefile format describes geospatial information of a data set as vector features. These vector features include:

  • points
  • lines
  • polygons

These features in combination can represent almost any type of shapes like water wells, country boundaries, spatial points, rivers flow, lakes, etc. Each vector feature can have attributes that actually define the purpose of that feature. For example, a shapefile containing cities of Los Angeles can have city name and temperature as attributes which gives meaningful representation to the spatial data.

Associated Files

A standalone shp file can not be used by software applications to make meaning of the data it contains. In order to make sense of the information contained in such a file, a shapefile makes use of following additional mandatory files.

  • shx file - index file
  • dbf file - a dBASE file that stores all the attributes of the shapes in the main file
  • prj file - stores project information of the file

There can be other optional files as well that share the same name as the main file.

File Format Specifications

Open specifications of shapefile are available online from ESRI in the form of Technical Description and elaborates the overall structure of the file in detail. Information in main .shp file consists of headers and records. The fixed-length file header is followed by variable-length records where every record is made up of a fixed-length record header followed by variable-length record contents.

Main File Header

The main File Header starts from the beginning of the file and is 100 bytes in length.  Organization of this main file header along with byte position, value, type and byte order is as shown in the following table.

BytesFieldValueTypeByte Order
0-3File Code9994IntegerBig Endian
4-23Unused0IntegerBig Endian
24-27File LengthFile LengthIntegerBig Endian
28-31Version1000IntegerLittle Endian
32-35Shape TypeShape TypeIntegerLittle Endian
36-67Minimum Bounding RectangleXmin, Ymin, Xmax and YmaxdoubleLittle Endian
68-83Bounding BoxZmin, ZmaxdoubleLittle Endian
84-99Bounding BoxMmin, Mmaxdouble 

It is to be noted that the value of file length is the total length of the file in 16-bit words which also includes the fifty 16-bit words making up the header.

Shape Types

The values of shape types field in above table are as follow:

ValueShape Type
0Null Shape

Data Records

The main file header is followed by variable length records where each record consists of a fixed-length record header followed by variable-length record contents.

Record Header

Record header contains information about the record number and content length of the record in a fixed length of 8 bytes. The organization of record header is as shown follow:

BytesFieldValueTypeByte Order
0-3Record NumberRecord NumberIntegerBig
4-7Record LengthRecord LengthIntegerBig

Record Contents

A shapefile record contents consist of a shape type followed by the geometric data for that shape. A shape type of 0 represents a null shape that has no geometric data for the shape. The length of the record contents is reflection of the shape parts and vertices. Lets take an example of Point Shape type to elaborate how a record contains information about such a shape type.

A point represents a certain geographic location in the order X,Y where each coordinate is represented by a double-precision value. Following table shows the arrangement of a Point shape type.

BytesShape TypeValueTypeNumberByte Order
0-3Shape Type1Integer1Little

Examples of other shape types can be found the ESRI technical description document.


Created by Kashif Iqbal on 2019/09/10 02:59