WKT
The plain-text geometry syntax behind every spatial SQL database.
- Specification
- OGC Simple Features Access (ISO 19125)
- Released
- 1999
- When to use
- Use WKT when you need to express a single geometry as a string — for inclusion in SQL statements, log messages, configuration files, REST request bodies, or test fixtures. WKT is also the lingua franca for CRS definitions (the contents of every .prj file are WKT). For datasets containing many features with attributes, WKT is the wrong tool; use GeoJSON or GeoPackage.
What is WKT?
WKT (Well-Known Text) is the human-readable companion to WKB (Well-Known Binary), defined together by the OGC Simple Features Access specification and ISO 19125. A WKT string declares a geometry type followed by parenthesised coordinate lists: POINT(10.0 53.5), LINESTRING(10 53, 11 54, 12 55), POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)). Supported types are POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION, and the empty variants thereof. Coordinates are space-separated; tuples are comma-separated; rings in a polygon are nested in another layer of parentheses with the first and last point identical. Three- and four-dimensional variants exist (POINT Z, POINT M, POINT ZM) for elevation and measure. EWKT (Extended WKT) is the PostGIS extension that prefixes a string with SRID=<n>; to carry the coordinate reference system. WKT is also used in an entirely different role to express CRS definitions themselves — the WKT2 (ISO 19162) format describes a CRS as a nested tree of GEOGCS, PROJCS, DATUM, and so on; that is the content of every Shapefile's .prj file.
Supported by
- PostGIS, Oracle Spatial, MS SQL Server Spatial, SpatiaLite
- GDAL/OGR (built into every driver)
- QGIS, ArcGIS, FME
- Python shapely, GEOS, PROJ libraries
- Java JTS Topology Suite
- Most CRS handling libraries (WKT2 for projections)
Strengths
- Human-readable — paste into a SQL editor and read it back
- OGC standard, supported by every spatial database
- Compact for a single geometry; no parsing library needed for simple cases
- EWKT extension carries the CRS inline
- WKT2 is the standard CRS exchange format
Weaknesses
- No attribute support — geometry only
- Verbose for large geometries (millions of coordinates as text)
- Floating-point precision depends on the writer; not byte-stable
- EWKT is not in the OGC standard, just PostGIS convention
- WKT for geometry and WKT2 for CRS share a name but are different grammars
Converters for WKT
Convert FROM WKT
Convert TO WKT
Validator
WKT Validator
Validate WKT geometry strings for syntax correctness and coordinate completeness.
Frequently Asked Questions
What's the difference between WKT and WKB?
Both encode the same geometry types from the OGC Simple Features standard. WKT is the human-readable text form (POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))). WKB is the compact binary form, used as the on-disk geometry encoding in PostGIS and GeoPackage. Tools convert freely between them with ST_AsText() and ST_GeomFromText().
What does EWKT add to WKT?
EWKT (Extended WKT) is a PostGIS-specific extension that prepends SRID=<epsg-code>; to a WKT string so the geometry carries its coordinate reference system. SRID=4326;POINT(10.0 53.5) is EWKT for the same point in WGS 84. Strip the prefix before passing to a strict OGC WKT parser.
How do I store multiple WKT geometries in a file?
Convention is one WKT per line in a plain text file with a .wkt or .txt extension. To carry attributes alongside, use CSV with a WKT column — most GIS tools recognise it via the GEOMETRY=AS_WKT option when reading.
Why does my polygon WKT throw a validation error?
Most likely the exterior ring is not closed. WKT requires the first and last coordinates of every polygon ring to be identical. POLYGON((0 0, 1 0, 1 1, 0 1)) is invalid; POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)) is valid.
Are WKT (geometry) and WKT2 (CRS) the same format?
No. They share a name and a parenthesised syntax but describe entirely different things. WKT for geometry encodes shapes (POINT, POLYGON, etc.); WKT2 — defined by ISO 19162 — encodes coordinate reference systems (GEOGCRS, PROJCRS, DATUM). The contents of a .prj sidecar file are WKT2.