Supriya Ghosh (Editor)

Well known text

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems. A binary equivalent, known as well-known binary (WKB), is used to transfer and store the same information on databases. The formats were originally defined by the Open Geospatial Consortium (OGC) and described in their Simple Feature Access and Coordinate Transformation Service specifications. The current standard definition is in the ISO/IEC 13249-3:2016 standard, "Information technology – Database languages – SQL multimedia and application packages – Part 3: Spatial" (SQL/MM) and ISO 19162:2015, "Geographic information – Well-known text representation of coordinate reference systems".

Contents

Geometric objects

WKT can represent the following distinct geometric objects:

  • Geometry
  • Point, MultiPoint
  • LineString, MultiLineString
  • Polygon, MultiPolygon, Triangle
  • CircularString
  • Curve, MultiCurve, CompoundCurve
  • CurvePolygon
  • Surface, MultiSurface, 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 contains functions that can convert geometries to and from a WKT representation, making them human readable.

    It's useful to note that 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 counter clockwise direction 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.)

    Well-known binary

    Well-known binary (WKB) representations are typically shown in hexadecimal strings.

    The first byte indicates the byte order for the data:

  • 00 : big endian
  • 01 : little endian
  • The second part is an 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 double-precision floating-point format (double).

    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
  • Coordinate operations

    A WKT format is defined to describe the operation methods and parameters used to convert or transform coordinates between two different coordinate reference systems. The WKT 1 and WKT 2 formats are incompatible regarding coordinate operations, because of differences in the modelling. Below is an example of a concatenation of two WKT 1 transformation descriptions, where the Mercator projection is applied first and then an affine transform is applied on the result:

    Below is an example of a datum shift operation in WKT 2 format. Contrarily to an equivalent description in WKT 1 format, the WKT 2 description specifies the source and target coordinate reference systems, together with the domain of validity and the accuracy (in metres) that we can expect from this operation:

    RDBMS Engines that provide support

  • Apache Solr enterprise search server since 4.0 through JTS
  • PostgreSQL with PostGIS Module 2.0
  • Kinetica GPU-accelerated geospatial database
  • Oracle Spatial 9i, 10g, 11g
  • MarkLogic Server since 4.2
  • MemSQL since 4
  • MySQL since 4.1
  • MariaDB, all versions
  • Neo4j>
  • IBM DB2 LUW 9, 10 with Spatial Extender
  • IBM DB2 for z/OS 9, 10 with Spatial Support
  • IBM Netezza with Netezza Spatial
  • IBM Informix 9,10,11 with Spatial datablade module
  • Microsoft SQL Server 2008, 2008 R2, 2012, 2014, 2016
  • SpatiaLite
  • Teradata 6.1, 6.2, 12, 13 (native in 13 through add-in in previous versions)
  • Ingres GeoSpatial
  • Altibase 5.x
  • SQL Anywhere 12
  • SAP HANA SP07,SP08
  • H2 since 1.3.173 (2013-07-28)
  • APIs that provide support

  • Apache Spatial Information System: parses and formats WKT versions 1 and 2 for coordinate reference systems and coordinate operations
  • Boost C++ libraries (C++): See Geometry io/wkt headers
  • Esri geometry-api-java
  • GEOS (C/C++)
  • Shapely (Python): See Shapely Documentation and Shapely in PyPI
  • GeoPHP (PHP)
  • GDAL (C/C++ with bindings to Java, Python, and others)
  • GeoRust: rust-wkt (Rust bindings)
  • JTS Topology Suite (Java)
  • NetTopologySuite (.NET)
  • OpenLayers (JavaScript)
  • OpenScales (ActionScript)
  • parsewkt (Python) is a peg parser from WKT to python dictionaries
  • pygeoif (Python) parses wkt with regular expressions
  • rgeo (Ruby)
  • Terraformer (JavaScript)
  • WkbDecoder (C# .Net) WKB Parser
  • Protocols that provide support

  • GeoSPARQL
  • SensorThings API
  • 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). For example: SRID=4326;POINT(-44.3 60.1) to locate a longitude/latitude coordinate using the WGS 84 reference coordinate system.
  • AGF Text – Autodesk Geometry Format – An extension to OGC's Standard (at the time), to include curved elements; most notably used in MapGuide.
  • References

    Well-known text Wikipedia