Well-known text representation of geometry#Well-known binary

{{Short description|Computer markup language}}

{{Redirect|Well-known text|representation of coordinate reference systems|Well-known text representation of coordinate reference systems}}

Well-known text (WKT) is a text markup language for representing vector geometry 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 (OGC) and described in their Simple Feature Access.{{citation |editor-first=John R. |editor-last=Herring |title=OpenGIS® Implementation Standard for Geographic information – Simple feature access – Part 1: Common architecture |number=OGC 06-103r4 |institution=Open Geospatial Consortium |date=2011-05-28 |url=http://www.opengeospatial.org/standards/sfa |access-date=2019-01-28}} The current standard definition is in the ISO/IEC 13249-3:2016 standard.{{citation |number=ISO/IEC 13249-3:2016 |edition=5th |date=2016-01-15 |title=Information technology – Database languages – SQL multimedia and application packages – Part 3: Spatial |publisher=ISO |url=https://www.iso.org/standard/60343.html |access-date=2019-01-28}}

Geometric objects

WKT can represent the following distinct geometric objects:

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 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.See the OGC Implementation Specification for geographic information – Simple Feature Access, section 6.1.11.1. http://www.opengeospatial.org/standards/sfa

class="wikitable"

|+Geometry primitives (2D)

Type

!colspan="2"| Examples

Point

| File:SFA Point.svg

| POINT (30 10)

LineString

| File:SFA LineString.svg

| LINESTRING (30 10, 10 30, 40 40)

rowspan="2"| Polygon

| File:SFA Polygon.svg

| POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))

File:SFA Polygon with hole.svg

| POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),
(20 30, 35 35, 30 20, 20 30))

class="wikitable"

|+Multipart geometries (2D)

Type

!colspan="2"| Examples

rowspan="2"| MultiPoint

|rowspan="2"| File:SFA MultiPoint.svg

| MULTIPOINT ((10 40), (40 30), (20 20), (30 10))

MULTIPOINT (10 40, 40 30, 20 20, 30 10)
MultiLineString

| File:SFA MultiLineString.svg

| MULTILINESTRING ((10 10, 20 20, 10 40),
(40 40, 30 30, 40 20, 30 10))

rowspan="2"| MultiPolygon

| File:SFA MultiPolygon.svg

| MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),
((15 5, 40 10, 10 20, 5 10, 15 5)))

File:SFA MultiPolygon with hole.svg

| MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),
((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),
(30 20, 20 15, 20 25, 30 20)))

GeometryCollection

| File:SFA GeometryCollection.svg

| GEOMETRYCOLLECTION (POINT (40 10),
LINESTRING (10 10, 20 20, 10 40),
POLYGON ((40 40, 20 45, 45 30, 40 40)))

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 strings.

The first byte indicates the byte order 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:

class="wikitable"

|+ Geometry types, and WKB integer codes (specified below in decimal)

Type2DZMZM
Geometry

| 0

100020003000
Point

| 1

100120013001
LineString

| 2

100220023002
Polygon

| 3

100320033003
MultiPoint

| 4

100420043004
MultiLineString

| 5

100520053005
MultiPolygon

| 6

100620063006
GeometryCollection

| 7

100720073007
CircularString

| 8

100820083008
CompoundCurve

| 9

100920093009
CurvePolygon

| 10

101020103010
MultiCurve

| 11

101120113011
MultiSurface

| 12

101220123012
Curve

| 13

101320133013
Surface

| 14

101420143014
PolyhedralSurface

| 15

101520153015
TIN

| 16

101620163016
Triangle

| 17

101720173017
Circle

| 18

101820183018
GeodesicString

| 19

101920193019
EllipticalCurve

| 20

102020203020
NurbsCurve

| 21

102120213021
Clothoid

| 22

102220223022
SpiralCurve

| 23

102320233023
CompoundSurface

| 24

102420243024
BrepSolid

|

1025
AffinePlacement

| 102

1102

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 EWKBExtended Well-Known Text/Binary : A PostGIS-specific format that includes the spatial reference system identifier (SRID) and up to 4 ordinate values (XYZM).{{Cite web|url=https://github.com/postgis/postgis/blob/2.1.0/doc/ZMSgeoms.txt|title = Postgis/Postgis|website = GitHub|date = 6 October 2021}}{{Cite web|url=https://postgis.net/docs/ST_GeomFromEWKT.html|title=ST_GeomFromEWKT|access-date=2022-11-25}} For example: SRID=4326;POINT(-44.3 60.1) to locate a longitude/latitude coordinate using the WGS 84 reference coordinate system. It also supports circular curves, following elements named (but not fully defined) within the original WKT: CircularString, CompoundCurve, CurvePolygon and CompoundSurface.{{Cite web|title=Chapter 4: Using PostGIS: Data Management and Queries|url=https://postgis.net/docs/manual-1.4/ch04.html|access-date=2021-07-30|website=postgis.net}}

; AGF TextAutodesk Geometry Format : An extension to OGC's Standard (at the time), to include curved elements; most notably used in MapGuide.{{Cite web |url=https://mapguide.ca/mapguide/help/webapi/da/dc0/group___agf_text.htm |title=MapGuide API Reference: AGF Text |access-date=2023-09-14 }}

See also

References