-2

Can a shapefile store several geometry types? Yes or no? Why or why not?

4

1 Answer 1

6

Wikipedia says yes and no (but mostly no):

Mixing shape types

Because the shape type precedes each record, a shape file is physically capable of storing a mixture of different shape types. However, the specification states, "All the non-Null shapes in a shapefile are required to be of the same shape type." Therefore this ability to mix shape types must be limited to interspersing null shapes with the single shape type declared in the file's header. A shape file must not contain both polyline and polygon data, for example, and the descriptions for a well (point), a river (polyline), and a lake (polygon) would be stored in three separate files.

The ESRI Shapefile Technical Description confirms this:

All the non-Null shapes in a shapefile are required to be of the same shape type. The values for shape type are as follows:

Value Shape Type
0     Null Shape
1     Point
3     PolyLine
5     Polygon
8     MultiPoint
11    PointZ
13    PolyLineZ
15    PolygonZ
18    MultiPointZ
21    PointM
23    PolyLineM
25    PolygonM
28    MultiPointM
31    MultiPatch
3
  • 2
    A shapefile can store mixed geometry types like POLYGON and MULTIPOLYGON, or LINESTRING and MULTILINESTRING, but not the ones in your example like POLYGON vs LINESTRING vs POINT.
    – SaultDon
    Commented Mar 6, 2014 at 18:29
  • 3
    @SaultDon those are WKT representations, in the shapefile format they are the same, only differentiated by the number of parts (single-part vs. multi-part). The exception is Point vs. Multipoint which are different geometry types and cannot be mixed: esri.com/library/whitepapers/pdfs/shapefile.pdf
    – blah238
    Commented Mar 6, 2014 at 18:36
  • 1
    Multipoint shapefiles can have features with one vertex, but they still must be represented as a MultiPoint record, with an envelope (minx=maxx, miny=maxy) and a vertex count. They index differently (and less efficiently) than point shapefiles, though, so you shouldn't use Multipoint unless the table will need to store them.
    – Vince
    Commented Mar 6, 2014 at 22:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.