Grammar for Shape files (.shp)
The main file header is 100 bytes long
The value for file length is the total length of the file in 16-bit words (including the fifty 16-bit words that make up the header).
All the non-Null shapes in a shapefile are required to be of the same shape type.
Currently, shapefiles are restricted to contain the same type of shape as specified above. In the future, shapefiles may be allowed to contain more than one shape type. If mixed shape types are implemented, the shape type field in the header will flag the file as such.
The Bounding Box in the main file header stores the actual extent of the shapes in the file: the minimum bounding rectangle orthogonal to the X and Y (and potentially the M and Z) axes that contains all shapes. If the shapefile is empty (that is, has no records), the values for Xmin, Ymin, Xmax, and Ymax are unspecified. Mmin and Mmax can contain "no data" values for shapefiles of measured shape types that contain no measures.
A shape type of 0 indicates a null shape, with no geometric data for the shape. Each feature type (point, line, polygon, etc.) supports nullsit is valid to have points and null points in the same shapefile. Often null shapes are place holders; they are used during shapefile creation and are populated with geometric data soon after they are created.
A point consists of a pair of double-precision coordinates in the order X,Y
A MultiPoint represents a set of points
A PolyLine is an ordered set of vertices that consists of one or more parts. A part is a connected sequence of two or more points. Parts may or may not be connected to one another. Parts may or may not intersect one another
A polygon consists of one or more rings. A ring is a connected sequence of four or more points that form a closed, non-self-intersecting loop. A polygon may contain multiple outer rings. The order of vertices or orientation for a ring indicates which side of the ring is the interior of the polygon. The neighborhood to the right of an observer walking along the ring in vertex order is the neighborhood inside the polygon. Vertices of rings defining holes in polygons are in a counterclockwise direction. Vertices for a single, ringed polygon are, therefore, always in clockwise order. The rings of a polygon are referred to as its parts
A PointM consists of a pair of double-precision coordinates in the order X, Y, plus a measure M
X coordinate
Y coordinate
Measure
A MultiPointM represents a set of PointMs
Measure
Measure
Measure
Measure
Measure
Measure
A PolygonM consists of a number of rings. A ring is a closed, non-self-intersecting loop. Note that intersections are calculated in X,Y space, not in X,Y,M space. A PolygonM may contain multiple outer rings. The rings of a PolygonM are referred to as its parts
Measure
Measure
Measure
X coordinate
Y coordinate
Y coordinate
Measure
A MultiPointZ represents a set of PointZs
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
A PolygonZ consists of a number of rings. A ring is a closed, non-self-intersecting loop. A PolygonZ may contain multiple outer rings. The rings of a PolygonZ are referred to as its parts
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure
Measure