Well-known text (WKT) is a text
markup language
A markup language is a Encoding, text-encoding system which specifies the structure and formatting of a document and potentially the relationships among its parts. Markup can control the display of a document or enrich its content to facilitate au ...
for representing
vector
Vector most often refers to:
* Euclidean vector, a quantity with a magnitude and a direction
* Disease vector, an agent that carries and transmits an infectious pathogen into another living organism
Vector may also refer to:
Mathematics a ...
geometry
Geometry (; ) is a branch of mathematics concerned with properties of space such as the distance, shape, size, and relative position of figures. Geometry is, along with arithmetic, one of the oldest branches of mathematics. A mathematician w ...
objects. A
binary equivalent, known as well-known binary (WKB), is used to transfer and store the same information in a more compact form convenient for computer processing but that is not human-readable. The formats were originally defined by the
Open Geospatial Consortium
The Open Geospatial Consortium (OGC) is an international voluntary consensus standards organization that develops and maintains international standards for geospatial content and location-based services, sensor web, Internet of Things, Geographi ...
(OGC) and described in their
Simple Feature Access.
The current standard definition is in the ISO/IEC 13249-3:2016 standard.
Geometric objects
WKT can represent the following distinct geometric objects:
*
Point, MultiPoint
*
LineString, MultiLineString
*
Polygon
In geometry, a polygon () is a plane figure made up of line segments connected to form a closed polygonal chain.
The segments of a closed polygonal chain are called its '' edges'' or ''sides''. The points where two edges meet are the polygon ...
, MultiPolygon,
Triangle
A triangle is a polygon with three corners and three sides, one of the basic shapes in geometry. The corners, also called ''vertices'', are zero-dimensional points while the sides connecting them, also called ''edges'', are one-dimension ...
*
PolyhedralSurface
*TIN (
Triangulated irregular network)
*GeometryCollection
Coordinates for geometries may be 2D (''x'', ''y''),
3D (''x'', ''y'', ''z''), 4D (''x'', ''y'', ''z'', ''m'') with an ''m'' value that is part of a
linear referencing system or 2D with an ''m'' value (''x'', ''y'', ''m''). Three-dimensional geometries are designated by a "Z" after the geometry type and geometries with a
linear referencing system have an "M" after the geometry type. Empty geometries that contain no coordinates can be specified by using the symbol
EMPTY
after the type name.
WKT geometries are used throughout OGC specifications and are present in applications that implement these specifications. For example,
PostGIS
PostGIS ( ) is an open source software program that adds support for geographic objects to the PostgreSQL object-relational database. PostGIS follows the Simple Features for SQL specification from the Open Geospatial Consortium (OGC).
PostGIS is ...
contains functions that can convert geometries to and from a WKT representation, making them human readable.
The OGC standard definition requires a polygon to be topologically closed. It also states that if the exterior linear ring of a polygon is defined in a counterclockwise direction, then it will be seen from the "top". Any interior linear rings should be defined in opposite fashion compared to the exterior ring, in this case, clockwise.
The following are some other examples of geometric WKT strings: (Note: Each item below is an individual geometry.)
GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))
POINT ZM (1 1 5 60)
POINT M (1 1 80)
POINT EMPTY
MULTIPOLYGON EMPTY
TRIANGLE((0 0 0,0 1 0,1 1 0,0 0 0))
TIN (((0 0 0, 0 0 1, 0 1 0, 0 0 0)), ((0 0 0, 0 1 0, 1 1 0, 0 0 0)))
POLYHEDRALSURFACE Z ( PATCHES
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),
((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)),
((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)),
((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),
((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))
)
Well-known binary
Well-known binary (WKB) representations are typically shown in
hexadecimal
Hexadecimal (also known as base-16 or simply hex) is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of sixteen. Unlike the decimal system representing numbers using ten symbo ...
strings.
The first
byte
The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable un ...
indicates the
byte order
'' Jonathan_Swift.html" ;"title="Gulliver's Travels'' by Jonathan Swift">Gulliver's Travels'' by Jonathan Swift, the novel from which the term was coined
In computing, endianness is the order in which bytes within a word (data type), word of d ...
for the data:
*
0x00
: big endian
*
0x01
: little endian
The next 4 bytes are a
32-bit unsigned integer for the geometry type, as described below:
Each data type has a unique data structure, such as the number of points or linear rings, followed by coordinates in
64-bit double numbers.
For example, the geometry
POINT(2.0 4.0)
is represented as:
000000000140000000000000004010000000000000
, where:
* 1-byte integer
00
or 0: big endian
* 4-byte integer
00000001
or 1: POINT (2D)
* 8-byte float
4000000000000000
or 2.0: ''x''-coordinate
* 8-byte float
4010000000000000
or 4.0: ''y''-coordinate
Format variations
; ''EWKT'' and ''EWKB'' – ''Extended Well-Known Text/Binary'' : A
PostGIS
PostGIS ( ) is an open source software program that adds support for geographic objects to the PostgreSQL object-relational database. PostGIS follows the Simple Features for SQL specification from the Open Geospatial Consortium (OGC).
PostGIS is ...
-specific format that includes the
spatial reference system identifier (SRID) and up to 4 ordinate values (XYZM). For example:
SRID=4326;POINT(-44.3 60.1)
to locate a longitude/latitude coordinate using the
WGS 84
The World Geodetic System (WGS) is a standard used in cartography, geodesy, and satellite navigation including GPS. The current version, WGS 84, defines an Earth-centered, Earth-fixed coordinate system and a geodetic datum, and also descri ...
reference coordinate system. It also supports circular curves, following elements named (but not fully defined) within the original WKT: CircularString, CompoundCurve, CurvePolygon and CompoundSurface.
; ''AGF Text'' –
Autodesk
Autodesk, Inc. is an American multinational software corporation that provides software products and services for the architecture, engineering, construction, manufacturing, media, education, and entertainment industries. Autodesk is headquarte ...
Geometry Format : An extension to
OGC's Standard (at the time), to include curved elements; most notably used in
MapGuide.
See also
*
Simple Features
Simple Features (officially Simple Feature Access) is a set of standards that specify a common storage and access model of geographic features made of mostly two-dimensional geometries (point, line, polygon, multi-point, multi-line, etc.) used by ...
*
Geography Markup Language
The Geography Markup Language (GML) is the XML grammar defined by the Open Geospatial Consortium (OGC) to express geographical features. GML serves as a modeling language for geographic systems as well as an open interchange format for geographic ...
*
Well-known text representation of coordinate reference systems
References
External links
Simple Feature AccessSpecification
BNF Notation of WKT{{Webarchive, url=https://web.archive.org/web/20230103103049/https://git.osgeo.org/gitea/postgis/postgis/src/branch/master/doc/bnf-wkt.txt , date=2023-01-03
EBNF Notation of WKTOnline conversion between geometry objects representations
GIS file formats
Markup languages