GIS中的WKB介紹
WKB的全稱是The Well-known Binary,也簡稱WKB,OGC與ISO/TC211都做出了一樣的規(guī)范,它是用來幾何體的表達(dá)。即用連續(xù)的2進(jìn)制流來表達(dá)幾何體,這樣在GIS互操作方面也有好處?,F(xiàn)代GIS軟件的底層模塊中可以說都有關(guān)于WKB解析代碼。在2進(jìn)制存儲(chǔ)中有大尾端和小尾端之分,通常在2進(jìn)制流的第1個(gè)字節(jié)就指定,這樣在這個(gè)字節(jié)以后的字節(jié)流就能夠依照相應(yīng)的大小尾端模式進(jìn)行解析。分大小尾端是為了適應(yīng)不同平臺(tái)環(huán)境。在1些開源和商業(yè)GIS軟件中都支持幾何體的WKB表示,這樣做也是為了異構(gòu)平臺(tái)之間互操作。
基本塊的定義以下,這些基本定義在后面的幾何體建模中會(huì)用到:
Point {
double x;
double y}
PointZ {
double x;
double y;
double z}
PointM {
double x;
double y;
double m}
PointZM{
double x;
double y;
double z;
double m}
LinearRing{
uint32 numPoints;
Point points[numPoints]}
LinearRingZ{
uint32 numPoints;
PointZ points[numPoints]}
LinearRingM{
uint32 numPoints;
PointM points[numPoints]}
LinearRingZM{
uint32 numPoints;
PointZM points[numPoints]}
//字節(jié)序
enum WKBByteOrder {
wkbXDR =0, // 大尾端
wkbNDR =1 // 小尾端
}
下面表示幾何體的整型的數(shù)值,用枚舉表示。
enum WKBGeometryType {
wkbPoint = 1,
wkbLineString = 2,
wkbPolygon = 3,
wkbTriangle = 17
wkbMultiPoint = 4,
wkbMultiLineString = 5,
wkbMultiPolygon = 6,
wkbGeometryCollection = 7,
wkbPolyhedralSurface = 15,
wkbTIN = 16
wkbPointZ = 1001,
wkbLineStringZ = 1002,
wkbPolygonZ = 1003,
wkbTrianglez = 1017
wkbMultiPointZ = 1004,
wkbMultiLineStringZ = 1005,
wkbMultiPolygonZ = 1006,
wkbGeometryCollectionZ = 1007,
wkbPolyhedralSurfaceZ = 1015,
wkbTINZ = 1016
wkbPointM = 2001,
wkbLineStringM = 2002,
wkbPolygonM = 2003,
wkbTriangleM = 2017
wkbMultiPointM = 2004,
wkbMultiLineStringM = 2005,
wkbMultiPolygonM = 2006,
wkbGeometryCollectionM = 2007,
wkbPolyhedralSurfaceM = 2015,
wkbTINM = 2016
wkbPointZM = 3001,
wkbLineStringZM = 3002,
wkbPolygonZM = 3003,
wkbTriangleZM = 3017
wkbMultiPointZM = 3004,
wkbMultiLineStringZM = 3005,
wkbMultiPolygonZM = 3006,
wkbGeometryCollectionZM = 3007,
wkbPolyhedralSurfaceZM = 3015,
wkbTinZM = 3016,
}
以下就是各個(gè)幾何體的定義了。
(1) 點(diǎn)
主要包括字節(jié)序和幾何體類型,接著后面是坐標(biāo)總共是1+4+16=21個(gè)字節(jié)
WKBPoint{
byte byteOrder; //字節(jié)序
static uint32 wkbType= 1; //幾何體類型
Point point} //點(diǎn)的坐標(biāo)
WKBPointZ{
byte byteOrder;
static uint32 wkbType = 1001;
PointZ point}
WKBPointM{
byte byteOrder;
static uint32 wkbType= 2001;
PointM point}
WKBPointZM{
byte byteOrder;
static uint32 wkbType= 3001;
PointZM point}
(2)線串,即折線
WKBLineString{
byte byteOrder; //字節(jié)序
static uint32 wkbType = 2; //幾何體類型
uint32 numPoints; //點(diǎn)的個(gè)數(shù)
Point points[numPoints]} //點(diǎn)的坐標(biāo)數(shù)組
總的字節(jié)大小
1+4+4+ numPoints*sizeof(Point)字節(jié)
WKBLineStringZ{
byte byteOrder;
static uint32 wkbType = 1002;
uint32 numPoints;
PointZ points[numPoints]}
WKBLineStringM{
byte byteOrder;
static uint32 wkbType= 2002;
uint32 numPoints;
PointM points[numPoints]}
WKBLineStringZM{
byte byteOrder;
static uint32 wkbType= 3002;
uint32 numPoints;
PointZM points[numPoints]}
(2) 多邊形
所占的字節(jié)大小是:1+4+4+ numRings*(4 + LinearRing.numPoints*sizeof(Point))
WKBPolygon{
byte byteOrder; //字節(jié)序
static uint32 wkbType= 3; //幾何體類型
uint32 numRings; //線串的個(gè)數(shù)
LinearRing rings[numRings]} //線串(環(huán))的數(shù)組
WKBPolygonZ{
byte byteOrder;
static uint32 wkbType= 1003;
uint32 numRings;
LinearRingZ rings[numRings]}
WKBPolygonM{
byte byteOrder;
static uint32 wkbType = 2003;
uint32 numRings;
LinearRingM rings[numRings]}
WKBPolygonZM{
byte byteOrder;
static uint32 wkbType = 3003;
uint32 numRings;
LinearRingZM rings[numRings]}
(4)3角形注:當(dāng)前主流GIS軟件中把這個(gè)放在TIN中建模
WKBTriangle{
byte byteOrder; //字節(jié)序
static uint32 wkbType= 17; //幾何體的類型
uint32 numRings; //環(huán)的個(gè)數(shù)
LinearRing rings[numRings]} //環(huán)的數(shù)組
WKBTriangleZ{
byte byteOrder;
static uint32 wkbType= 1017;
uint32 numRings;
LinearRingZ rings[numRings]}
WKBTriangleM{
byte byteOrder;
Static uint32 wkbType= 2017;
uint32 numRings;
LinearRingM rings[numRings]}
WKBTriangleZM{
Byte byteOrder;
static uint32 wkbType= 3017;
uint32 numRings;
LinearRingZM rings[numRings]}
(5)多面體表面
WKBPolyhedralSurface{
bytebyteOrder; //字節(jié)序
staticuint32 wkbType = 15; //幾何體類型
uint32numPolygons; //多邊形數(shù)目
WKBPolygonpolygons[numPolygons]} //多邊形的數(shù)組
WKBPolyhedralSurfaceZ{
bytebyteOrder;
staticuint32 wkbType=1015;
uint32numPolygons;
WKBPolygonZpolygons[numPolygons]}
WKBPolyhedralSurfaceM{
bytebyteOrder;
staticuint32 wkbType=2015;
uint32numPolygons;
WKBPolygonMpolygons[numPolygons]}
WKBPolyhedralSurfaceZM{
bytebyteOrder;
staticuint32 wkbType=3015;
uint32numPolygons;
WKBPolygonZMpolygons[numPolygons]}
(6)不規(guī)則3角網(wǎng)(TIN)貌似1般3角網(wǎng)和矢量數(shù)據(jù)的幾何模型位于同1層次上,所以目前很少看到有GIS軟件這樣建模的。僅僅是自己的觀點(diǎn)
WKBTIN {
bytebyteOrder; //字節(jié)序
staticuint32 wkbType = 16; //幾何體的類型
uint32numPolygons; //多邊形的數(shù)目
WKBPolygonpolygons[numPolygons]} //多邊形數(shù)組
WKBTINZ{
bytebyteOrder;
staticuint32 wkbType=1016;
uint32numPolygons;
WKBPolygonZpolygons[numPolygons]}
WKBTINM{
bytebyteOrder;
staticuint32 wkbType=2016;
uint32numPolygons;
WKBPolygonMpolygons[numPolygons]}
WKBTINZM{
bytebyteOrder;
staticuint32 wkbType=3016;
uint32numPolygons;
WKBPolygonZMpolygons[numPolygons]}
(7)多點(diǎn)
WKBMultiPoint{
byte byteOrder; //字節(jié)序
staticuint32 wkbType=4; //幾何體類型
uint32 numPoints; //點(diǎn)的個(gè)數(shù)
WKBPoint points[numPoints]} //點(diǎn)的數(shù)組
WKBMultiPointZ{
Byte byteOrder;
Static uint32 wkbType=1004;
uint32 numPoints;
WKBPointZ points[numPoints]}
WKBMultiPointM{
byte byteOrder;
static uint32 wkbType=2004;
uint32 numPoints;
WKBPointM points[numPoints]}
WKBMultiPointZM{
byte byteOrder;
Static uint32 wkbType=3004;
uint32 numPoints;
WKBPointZM points[numPoints]}
(8)多線串
WKBMultiLineString{
byte byteOrder; //字節(jié)序
staticuint32 wkbType = 5; //幾何體類型
uint32 numLineStrings; //線串的個(gè)數(shù)
WKBLineString lineStrings[numLineStrings]} //線串?dāng)?shù)組
WKBMultiLineStringZ{
byte byteOrder;
static uint32 wkbType= 1005;
uint32 numLineStrings;
WKBLineStringZ lineStrings[numLineStrings]}
WKBMultiLineStringM{
byte byteOrder;
static uint32 wkbType = 2005;
uint32 numLineStrings;
WKBLineStringM lineStrings[numLineStrings]}
WKBMultiLineStringZM{
byte byteOrder;
static uint32 wkbType = 3005;
uint32 numLineStrings;
WKBLineStringZM lineStrings[numLineStrings]}
(9)多多邊形
WKBMultiPolygon{
bytebyteOrder; //字節(jié)序
staticuint32 wkbType = 6; //幾何體類型
uint32numPolygons; //多邊形數(shù)目
WKBPolygonpolygons[numPolygons]} //多邊形數(shù)組
WKBMultiPolygonZ{
bytebyteOrder;
staticuint32 wkbType = 1006;
uint32numPolygons;
WKBPolygonZpolygons[numPolygons]}
WKBMultiPolygonM{
bytebyteOrder;
staticuint32 wkbType = 2006;
uint32numPolygons;
WKBPolygonMpolygons[numPolygons]}
WKBMultiPolygonZM{
bytebyteOrder;
staticuint32 wkbType = 3006;
uint32numPolygons;
WKBPolygonZMpolygons[numPolygons]}
下圖是1個(gè)多邊形的WKB布局。該圖表示這個(gè)多邊形的WKB存儲(chǔ)是小尾端,有兩個(gè)環(huán),并且兩個(gè)環(huán)的點(diǎn)的個(gè)數(shù)都是3。