Polygon

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.

Because this specification does not forbid consecutive points with identical coordinates, shapefile readers must handle such cases. On the other hand, the degenerate zero length or zero area parts that might result are not allowed.

The following fields are for a polygon:
Box
The bounding box for the polygon, stored in the order Xmin, Ymin, Xmax, Ymax
NumParts
The number of rings in the polygon
NumPoints
The total number of points for all rings
Parts
An array of length NumParts.

Stores, for each ring, the index of its first point in the points array. Array indexes are numbered with respect to 0.

Points
An array of length NumPoints

The points for each ring in the polygon are stored end to end. The points for ring 2 follow the points for ring 1, and so on. The parts array holds the array index of the starting point for each ring. There is no delimiter in the points array between rings.

The following are important notes about polygon shapes:
  • The rings are closed (the first and last vertex of a ring must be the same).
  • The order of rings in the points array is not significant.
  • Polygons stored in a shapefile must be clean.
  • A clean polygon is one that has no self-intersections. This means that a segment belonging to one ring may not intersect a segment belonging to another ring. The rings of a polygon can touch each other at vertices but not along segments. Colinear segments are considered intersecting.
  • A clean polygon is one that has the inside of the polygon on the correct side of the line that defines it. The neighborhood to the right of an observer walking along the ring in vertex order is the inside of the polygon. Vertices for a single, ringed polygon are, therefore, always in clockwise order.

    Rings defining holes in these polygons have a counterclockwise orientation. Dirty polygons occur when the rings that define holes in the polygon also go clockwise, which causes overlapping interiors.