ShapeFile的文件格式设计

Shape格式的文件是一种常用的保存gis文件的格式。底层为矢量存储。

ShapeFile的组成, 一个file header和一组gis元素的record。

一个file header, 具有固定长度为100bytes。里面指定了file length,shapeType,bounding box, version等等东西。
有一个奇怪的设计是它的编码有些是LE有些是BE,不知道这样是为了什么。
ShapeType指定了该shapefile中存储元素的类型。如Point,Polygon,PolyLine等等。
一个shapeFile只能存储一种shapeType的元素,这是它的一个限制。

一个gis元素的record=record header+record content。

record header为一个8bytes的记录头,记录了该纪录的number和length。

record content根据不同的shapeType有不同的格式。

例子1 int为4bytes,double为8bytes.

Point
{
Integer              Shape Type
Double               X           // X coordinate
Double               Y           // Y coordinate
}

PolyLine
{
Integer              Shape Type
Double[4]            Box              // Bounding Box
Integer              NumParts         // Number of Parts
Integer              NumPoints        // Total Number of Points
Integer[NumParts]    Parts            // Index to First Point in Part
Point[NumPoints]     Points           // Points for All Parts
}

可以看出,每个Record都会重复的纪录一次Shape Type。不知道这样是为了什么。
既然已经有了All the non-Null shapes in a shapefile are required to be of the same shape type.为什么又要存储每个record的shape type呢。
还有一个小的地方是shape file里面的长度度量一般是以16bits为单位的,这个不是什么问题,注意一下好了。

当然了,shape file其格式简单是一个优点,便于解析,适合做底层的gis data存储。 用很少的时间就可以写一个简单的基于shapefile的小地图查看器。

关于shape file伴生的为了执行速度的index fie和存储属性的dBase table file就不做介绍了。



你可能感兴趣的:(gis shapefile)