wkt与wkb

来源:互联网 发布:qqgame mac 编辑:程序博客网 时间:2024/05/16 12:59
wkt(OGC well-known text)和wkb(OGC well-known binary)是OGC制定的空间数据的组织规范,wkt是以文本形式描述,wkb是以二进制形式描述。
使用wkt和wkb能够很好到和其他系统进行数据交换,目前大部分支持空间数据存储的数据库构造空间数据都采用这两种方式。
wkt的组织结构如下:

Geometry typeText descriptionCommentST_Point'point empty'empty pointST_Point'point z empty'empty point with z-coordinateST_Point'point m empty'empty point with measureST_Point'point zm empty'empty point with z-coordinate and measureST_Point'point ( 10.05 10.28 )'pointST_Point'point z( 10.05 10.28 2.51 )'point with z-coordinateST_Point'point m( 10.05 10.28 4.72 )'point with measureST_Point'point zm(10.05 10.28 2.51 4.72 )'point with z-coordinate and measureST_LineString'linestring empty'empty linestringST_LineString'linestring z empty'empty linestring with z-coordinatesST_LineString'linestring m empty'empty linestring with measuresST_LineString'linestring zm empty'empty linestring with z-coordinates and measuresST_LineString'linestring (10.05 10.28 , 20.95 20.89 )'linestringST_LineString'linestring z(10.05 10.28 3.09, 20.95 31.98 4.72, 21.98 29.80 3.51 )'linestring with z-coordinatesST_LineString'linestring m(10.05 10.28 5.84, 20.95 31.98 9.01, 21.98 29.80 12.84 )'linestring with measuresST_LineString'linestring zm(10.05 10.28 3.09 5.84, 20.95 31.98 4.72 9.01, 21.98 29.80 3.51 12.84)'linestring with z-coordinates and measuresST_Polygon'polygon empty'empty polygonST_Polygon'polygon z empty'empty polygon with z-coordinatesST_Polygon'polygon m empty'empty polygon with measuresST_Polygon'polygon zm empty'empty polygon with z-coordinates and measuresST_Polygon'polygon ((10 10, 10 20, 20 20, 20 15, 10 10))'polygonST_Polygon'polygon z((10 10 3, 10 20 3, 20 20 3, 20 15 4, 10 10 3))'polygon with z-coordinatesST_Polygon'polygon m((10 10 8, 10 20 9, 20 20 9, 20 15 9, 10 10 8 ))'polygon with measuresST_Polygon'polygon zm((10 10 3 8, 10 20 3 9, 20 20 3 9, 20 15 4 9, 10 10 3 8 ))'polygon with z-coordinates and measuresST_MultiPoint'multipoint empty'empty multipointST_MultiPoint'multipoint z empty'empty multipoint with z-coordinatesST_MultiPoint'multipoint m empty'empty multipoint with measuresST_MultiPoint'multipoint zm empty'empty multipoint with z-coordinates and measuresST_MultiPoint'multipoint (10 10, 20 20)'multipoint with two pointsST_MultiPoint'multipoint z(10 10 2, 20 20 3)'multipoint with z-coordinatesST_MultiPoint'multipoint m(10 10 4, 20 20 5)'multipoint with measuresST_MultiPoint'multipoint zm(10 10 2 4, 20 20 3 5)'multipoint with z-coordinates and measuresST_MultiLineString'multilinestring empty'empty multilinestringST_MultiLineString'multilinestring z empty'empty multilinestring with z-coordinatesST_MultiLineString'multilinestring m empty'empty multilinestring with measuresST_MultiLineString'multilinestring zm empty'empty multilinestring with z-coordinates and measuresST_MultiLineString'multilinestring ((10.05 10.28 , 20.95 20.89 ),( 20.95 20.89, 31.92 21.45))'multilinestringST_MultiLineString'multilinestring z((10.05 10.28 3.4, 20.95 20.89 4.5),( 20.95 20.89 4.5, 31.92 21.45 3.6))'multilinestring with z-coordinatesST_MultiLineString'multilinestring m((10.05 10.28 8.4, 20.95 20.89 9.5), (20.95 20.89 9.5, 31.92 21.45 8.6))'multilinestring with measuresST_MultiLineString'multilinestring zm((10.05 10.28 3.4 8.4, 20.95 20.89 4.5 9.5), (20.95 20.89 4.5 9.5, 31.92 21.45 3.6 8.6))'multilinestring with z-coordinates and measuresST_MultiPolygon'multipolygon empty'empty multipolygonST_MultiPolygon'multipolygon z empty'empty multipolygon with z-coordinatesST_MultiPolygon'multipolygon m empty'empty multipolygon with measuresST_MultiPolygon'multipolygon zm empty'emptyST_MultiPolygon'multipolygon (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 40)))'multipolygonST_MultiPolygon'multipolygon z(((10 10 7, 10 20 8, 20 20 7, 20 15 5, 10 10 7), (50 40 6, 50 50 6, 60 50 5, 60 40 6, 50 40 6)))'multipolygon with z-coordinatesST_MultiPolygon'multipolygon m(((10 10 2, 10 20 3, 20 20 4, 20 15 5, 10 10 2), (50 40 7, 50 50 3, 60 50 4, 60 40 5, 50 40 7)))'multipolygon with measuresST_MultiPolygon'multipolygon zm(((10 10 7 2, 10 20 8 3, 20 20 7 4, 20 15 5 5, 10 10 7 2), (50 40 6 7, 50 50 6 3, 60 50 5 4, 60 40 6 5, 50 40 6 7)))'multipolygon with z-coordinates and measures

wkb的组织结构如下:
基本类型定义:
byte : 1 byte
uint32 : 32 bit unsigned integer  (4 bytes)
double : double precision number (8 bytes)
Building Blocks : Point, LinearRing
Point {
double x;
double y;
};
LinearRing   {
uint32 numPoints;
Point points[numPoints];
}
enum wkbGeometryType {      
wkbPoint = 1,
wkbLineString = 2,
wkbPolygon = 3,
wkbMultiPoint = 4,
wkbMultiLineString = 5,
wkbMultiPolygon = 6,
wkbGeometryCollection = 7
};
enum wkbByteOrder {
wkbXDR = 0,     Big Endian
wkbNDR = 1     Little Endian
};
WKBPoint {
byte    byteOrder;
uint32   wkbType;       1
Point    point;
}
WKBLineString {
byte    byteOrder;
uint32   wkbType;      2
uint32   numPoints;
Point    points[numPoints];
}
WKBPolygon {
byte    byteOrder;
uint32   wkbType;      3
uint32   numRings;
LinearRing  rings[numRings];
}
WKBMultiPoint {
byte    byteOrder;
uint32   wkbType;          4
uint32   num_wkbPoints;
WKBPoint   WKBPoints[num_wkbPoints];
}
WKBMultiLineString {
byte    byteOrder;
uint32   wkbType;      5
uint32   num_wkbLineStrings;
WKBLineString WKBLineStrings[num_wkbLineStrings];
}
wkbMultiPolygon {    
byte    byteOrder;       

uint32   wkbType;      6
uint32   num_wkbPolygons;
WKBPolygon  wkbPolygons[num_wkbPolygons];
}
WKBGeometry  {
union {
WKBPoint      point;
WKBLineString    linestring;
WKBPolygon     polygon;
WKBGeometryCollection collection;
WKBMultiPoint    mpoint;
WKBMultiLineString  mlinestring;
WKBMultiPolygon   mpolygon;
}
};
WKBGeometryCollection {
byte    byte_order;
uint32   wkbType;      7
uint32   num_wkbGeometries;
WKBGeometry  wkbGeometries[num_wkbGeometries]
}
下面是一个point(1,1) 使用WKB存储的例子:
0101000000000000000000F03F000000000000F03F
这个2进制流可以按照WKBPoint的结构进行拆分:
Byte order : 01
WKB type   : 01000000
         : 000000000000F03F
         : 000000000000F03F
byte order要么为0,要么为1,0为使用little-endian编码(NDR),1为使用big-endian编码(XDR)。
WKB type 是几何类型,在wkbGeometryType中定义. 值为1-7,分别对应 Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection. 
x,y为点的坐标值,为double类型。
0 0
原创粉丝点击