空间数据存储格式wkb和wkt(转载)

wkt(OGC well-known text)和wkb(OGC well-known binary)是OGC制定的空间数据的组织规范,wkt是以文本形式描述,wkb是以二进制形式描述。
使用wkt和wkb能够很好到和其他系统进行数据交换,目前大部分支持空间数据存储的数据库构造空间数据都采用这两种方式。
wkt的组织结构如下:

Geometry type Text description Comment
ST_Point ‘point empty‘ empty point
ST_Point ‘point z empty‘ empty point with z-coordinate
ST_Point ‘point m empty‘ empty point with measure
ST_Point ‘point zm empty‘ empty point with z-coordinate and measure
ST_Point ‘point ( 10.05 10.28 )‘ point
ST_Point ‘point z( 10.05 10.28 2.51 )‘ point with z-coordinate
ST_Point ‘point m( 10.05 10.28 4.72 )‘ point with measure
ST_Point ‘point zm(10.05 10.28 2.51 4.72 )‘ point with z-coordinate and measure
ST_LineString ‘linestring empty‘ empty linestring
ST_LineString ‘linestring z empty‘ empty linestring with z-coordinates
ST_LineString ‘linestring m empty‘ empty linestring with measures
ST_LineString ‘linestring zm empty‘ empty linestring with z-coordinates and measures
ST_LineString ‘linestring (10.05 10.28 , 20.95 20.89 )‘ linestring
ST_LineString ‘linestring z(10.05 10.28 3.09, 20.95 31.98 4.72, 21.98 29.80 3.51 )‘ linestring with z-coordinates
ST_LineString ‘linestring m(10.05 10.28 5.84, 20.95 31.98 9.01, 21.98 29.80 12.84 )‘ linestring with measures
ST_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 measures
ST_Polygon ‘polygon empty‘ empty polygon
ST_Polygon ‘polygon z empty‘ empty polygon with z-coordinates
ST_Polygon ‘polygon m empty‘ empty polygon with measures
ST_Polygon ‘polygon zm empty‘ empty polygon with z-coordinates and measures
ST_Polygon ‘polygon ((10 10, 10 20, 20 20, 20 15, 10 10))‘ polygon
ST_Polygon ‘polygon z((10 10 3, 10 20 3, 20 20 3, 20 15 4, 10 10 3))‘ polygon with z-coordinates
ST_Polygon ‘polygon m((10 10 8, 10 20 9, 20 20 9, 20 15 9, 10 10 8 ))‘ polygon with measures
ST_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 measures
ST_MultiPoint ‘multipoint empty‘ empty multipoint
ST_MultiPoint ‘multipoint z empty‘ empty multipoint with z-coordinates
ST_MultiPoint ‘multipoint m empty‘ empty multipoint with measures
ST_MultiPoint ‘multipoint zm empty‘ empty multipoint with z-coordinates and measures
ST_MultiPoint ‘multipoint (10 10, 20 20)‘ multipoint with two points
ST_MultiPoint ‘multipoint z(10 10 2, 20 20 3)‘ multipoint with z-coordinates
ST_MultiPoint ‘multipoint m(10 10 4, 20 20 5)‘ multipoint with measures
ST_MultiPoint ‘multipoint zm(10 10 2 4, 20 20 3 5)‘ multipoint with z-coordinates and measures
ST_MultiLineString ‘multilinestring empty‘ empty multilinestring
ST_MultiLineString ‘multilinestring z empty‘ empty multilinestring with z-coordinates
ST_MultiLineString ‘multilinestring m empty‘ empty multilinestring with measures
ST_MultiLineString ‘multilinestring zm empty‘ empty multilinestring with z-coordinates and measures
ST_MultiLineString ‘multilinestring ((10.05 10.28 , 20.95 20.89 ),( 20.95 20.89, 31.92 21.45))‘ multilinestring
ST_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-coordinates
ST_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 measures
ST_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 measures
ST_MultiPolygon ‘multipolygon empty‘ empty multipolygon
ST_MultiPolygon ‘multipolygon z empty‘ empty multipolygon with z-coordinates
ST_MultiPolygon ‘multipolygon m empty‘ empty multipolygon with measures
ST_MultiPolygon ‘multipolygon zm empty‘ empty
ST_MultiPolygon ‘multipolygon (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 40)))‘ multipolygon
ST_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-coordinates
ST_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 measures
ST_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
X          : 000000000000F03F
Y          : 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类型。

时间: 2024-12-18 13:19:51

空间数据存储格式wkb和wkt(转载)的相关文章

JTS(Geometry)(转)

原文链接:http://blog.csdn.net/cdl2008sky/article/details/7268577 空间数据模型(1).JTS Geometry model (2).ISO Geometry model (Geometry Plugin and JTS Wrapper Plugin)GeoTools has two implementations of these interfaces:Geometry Plugin a port of JTS 1.7 to the ISO

PostgreSQL+PostGIS 的使用

一.PostGIS中的几何类型 PostGIS支持所有OGC规范的“Simple Features”类型,同时在此基础上扩展了对3DZ.3DM.4D坐标的支持. 1. OGC的WKB和WKT格式 OGC定义了两种描述几何对象的格式,分别是WKB(Well-Known Binary)和WKT(Well-Known Text). 在SQL语句中,用以下的方式可以使用WKT格式定义几何对象: POINT(0 0) ——点 LINESTRING(0 0,1 1,1 2) ——线 POLYGON((0 0

C#读取Oracle Spatial的sdo_geometry

oracle的sdo_geometry中内置get_wkt和get_wkb两个方法. 以数据库表geoms为例,此表中有id和geometry两列 try { OracleConnection con = new OracleConnection(conStr); OracleCommand cmd = new OracleCommand(@"SELECT sdo_geometry.get_wkt(geometry) FROM geoms WHERE id= 1902 ", con);

Go语言(golang)开源项目大全

转http://www.open-open.com/lib/view/open1396063913278.html内容目录Astronomy构建工具缓存云计算命令行选项解析器命令行工具压缩配置文件解析器控制台用户界面加密数据处理数据结构数据库和存储开发工具分布式/网格计算文档编辑器Encodings and Character SetsGamesGISGo ImplementationsGraphics and AudioGUIs and Widget ToolkitsHardwareLangu

GO语言的开源库

Indexes and search engines These sites provide indexes and search engines for Go packages: godoc.org gowalker gosearch Sourcegraph Contributing To edit this page you must be a contributor to the go-wiki project. To get contributor access, send mail t

SQL Server 地理数据库中的系统表

转自:http://resources.arcgis.com/zh-cn/help/main/10.1/index.html#/na/002q00000080000000/ 地理数据库的系统表可以强制地理数据库行为.存储有关地理数据库的信息以及追踪存储在地理数据库中的数据. 不得使用 ArcGIS 软件以外的任何其他软件更改系统表及其内容.不过,可以使用 SQL 查看系统表的内容. GDB_ITEMRELATIONSHIPS GDB_ITEMRELATIONSHIPS 表用于存储有关 GDB_I

Shapely中的几何图形操作

Geometric Objects object.area Returns the area (float) of the object. object.bounds Returns a (minx, miny, maxx, maxy) tuple (float values) that bounds the object. object.length Returns the length (float) of the object. object.geom_type Returns a str

[转]Go语言(golang)开源项目大全

内容目录 Astronomy 构建工具 缓存 云计算 命令行选项解析器 命令行工具 压缩 配置文件解析器 控制台用户界面 加密 数据处理 数据结构 数据库和存储 开发工具 分布式/网格计算 文档 编辑器 Encodings and Character Sets Games GIS Go Implementations Graphics and Audio GUIs and Widget Toolkits Hardware Language and Linguistics 日志 机器学习 Math

ChemDraw支持哪些化学文件格式

ChemDraw支持Connection Table.ISIS.SMD.MDL MolFile和Molecular Simulations MolFile等格式文件.利用由ChemDraw提供的文件解释器(或称为文件解释程序),可以打开以这些文件格式存储的文件.在ChemDraw绘制窗口绘制完成化学结构后要注意ChemDraw文档的保存格式.本节内容小编将举例讨论由ChemDraw提供的文件解释,想获取更多精彩教程请猛戳ChemDraw中文官网. ChemDraw支持文件格式的遵循原则 当使用C