一、概念
WKT格式是一种文本格式,用于描述二维和三维几何对象的空间特征。WKT是“Well-Known Text”的缩写,是一种开放的国际标准,由Open Geospatial Consortium(OGC)定义和维护。WKT格式通常用于在计算机系统之间交换空间数据,例如在GIS(地理信息系统)软件和数据库之间。WKT格式包括一些基本的几何对象,例如点、线、多边形和圆形,以及一些复合对象,例如多边形集合和几何对象集合。
二、WKT的应用
- 描述空间实体
- 描述空间坐标系参数
三、WKT描述空间实体
WKT可以表示的几何对象包括:点,线,多边形,TIN(不规则三角网)及多面体。可以通过几何集合的方式来表示不同维度的几何对象。
几何物体的坐标可以是2D(x,y),3D(x,y,z),4D(x,y,z,m),加上一个属于线性参照系统的m值。
WKT格式的基本语法如下:
<geometry tag> <wkt data>
<geometry tag> ::= POINT | LINESTRING | POLYGON | MULTIPOINT | MULTILINESTRING | MULTIPOLYGON | GEOMETRYCOLLECTION
<wkt data> ::= <point> | <linestring> | <polygon> | <multipoint> | <multilinestring> | <multipolygon> | <geometrycollection>
其中,表示几何对象的类型,表示几何对象的具体数据。
点
点的WKT格式如下:
POINT (<x> <y>)
POINT(6 10)
其中,表示点的x坐标,表示点的y坐标。注意,指定点坐标时不使用分隔用逗号。
线
线的WKT格式如下:
LINESTRING (<x1> <y1>, <x2> <y2>, ...)
LINESTRING(3 4,10 50,20 25)
其中, 表示线的第一个点的坐标, 表示线的第二个点的坐标,以此类推。注意,点坐标对采用逗号隔开。
多边形
多边形的WKT格式如下:
POLYGON ((<x1> <y1>, <x2> <y2>, ..., <x1> <y1>))
POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))
其中, 表示多边形的第一个点的坐标, 表示多边形的第二个点的坐标,以此类推。
多点
多点的WKT格式如下:
MULTIPOINT ((<x1> <y1>, <x2> <y2>, ...))
MULTIPOINT(3.5 5.6, 4.8 10.5)
其中, 表示多点的第一个点的坐标, 表示多点的第二个点的坐标,以此类推。
多线
多线的WKT格式如下:
MULTILINESTRING ((<x1> <y1>, <x2> <y2>, ...), (<x1> <y1>, <x2> <y2>, ...))
MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))
其中, 表示多线的第一个点的坐标, 表示多线的第二个点的坐标,以此类推。
多多边形
多多边形的WKT格式如下:
MULTIPOLYGON (((<x1> <y1>, <x2> <y2>, ..., <x1> <y1>)), ((<x1> <y1>, <x2> <y2>, ..., <x1> <y1>)))
MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),((6 3,9 2,9 4,6 3)))
其中, 表示多多边形的第一个点的坐标, 表示多多边形的第二个点的坐标,以此类推。
几何对象集合
几何对象集合的WKT格式如下:
GEOMETRYCOLLECTION (<geometry tag> <wkt data>, <geometry tag> <wkt data>, ...)
GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))
其中, 表示几何对象集合中的第一个几何对象, 表示几何对象集合中的第二个几何对象,以此类推。
其他:
# 三维
POINT ZM (1 1 5 60)
# 带M值
POINT M (1 1 80)
# 空数据
POINT EMPTY
MULTIPOLYGON EMPTY
四、WKT 描述空间坐标系参数
WKT格式的基本语法如下:
<coordinate system> = <horz cs> | <geocentric cs> | <vert cs> | <compd cs> | <fitted cs> | <local cs>
<horz cs> = <geographic cs> | <projected cs>
<projected cs> = PROJCS["<name>", <geographic cs>, <projection>, {<parameter>,}* <linear unit> {,<twin axes>}{,<authority>}]
<projection> = PROJECTION["<name>" {,<authority>}]
<geographic cs> = GEOGCS["<name>", <datum>, <prime meridian>, <angular unit> {,<twin axes>} {,<authority>}]
<datum> = DATUM["<name>", <spheroid> {,<to wgs84>} {,<authority>}]
<spheroid> = SPHEROID["<name>", <semi-major axis>, <inverse flattening> {,<authority>}]
<semi-major axis> = <number>
<inverse flattening> = <number>
<prime meridian> = PRIMEM["<name>", <longitude> {,<authority>}]
<longitude> = <number>
<angular unit> = <unit>
<linear unit> = <unit>
<unit> = UNIT["<name>", <conversion factor> {,<authority>}]
<conversion factor> = <number>
<geocentric cs> = GEOCCS["<name>", <datum>, <prime meridian>, <linear unit> {,<axis>, <axis>, <axis>} {,<authority>}]
<authority> = AUTHORITY["<name>", "<code>"]
<vert cs> = VERT_CS["<name>", <vert datum>, <linear unit>, {<axis>,} {,<authority>}]
<vert datum> = VERT_DATUM["<name>", <datum type> {,<authority>}]
<datum type> = <number>
<compd cs> = COMPD_CS["<name>", <head cs>, <tail cs> {,<authority>}]
<head cs> = <coordinate system>
<tail cs> = <coordinate system>
<twin axes> = <axis>, <axis>
<axis> = AXIS["<name>", NORTH | SOUTH | EAST | WEST | UP | DOWN | OTHER]
<to wgs84s> = TOWGS84[<seven param>]
<seven param> = <dx>, <dy>, <dz>, <ex>, <ey>, <ez>, <ppm>
<dx> = <number>
<dy> = <number>
<dz> = <number>
<ex> = <number>
<ey> = <number>
<ez> = <number>
<ppm> = <number>
<fitted cs> = FITTED_CS["<name>", <to base>, <base cs>]
<to base> = <math transform>
<base cs> = <coordinate system>
<local cs> = LOCAL_CS["<name>", <local datum>, <unit>, <axis>, {,<axis>}* {,<authority>}]
<local datum> = LOCAL_DATUM["<name>", <datum type> {,<authority>}]
比如我们要定义一个WGS84地理坐标系。
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
参考:
https://malagis.com/gis-encyclopedia-what-is-wkt-format.html