What does WKT stand for?
WKT stands for Well-Known Text and is a text representation of geographic features, including points, lines, and polygons, used in GIS (Geographic Information Systems). WKT is widely used to describe the geometry of geographic features in vector data, as well as in many GIS software applications and web mapping APIs.
WKT uses a standard syntax to represent the geometries, making it a human-readable and easy-to-use format for data exchange. For example, a point can be represented in WKT as: “POINT(x y)” where x and y are the coordinates of the point. Similarly, a polygon can be represented in WKT as: “POLYGON((x1 y1, x2 y2, x3 y3, …, x1 y1))”, where each pair of x and y values represents a vertex of the polygon.
The use of WKT makes it easy to share and exchange geographic information between different GIS software and platforms, making it a key component of the GIS landscape.
Want to stay ahead of the geospatial curve? Listen to our podcast!
Here is a table showing WKT examples of various geometries, along with a description of each:
Geometry Type | WKT Example | Description |
---|---|---|
Point | POINT(30 10) | A single point with x coordinate 30 and y coordinate 10 |
LineString | LINESTRING(30 10, 10 30, 40 40) | A line connecting three points with x and y coordinates (30 10), (10 30), and (40 40) |
Polygon | POLYGON((30 10, 40 40, 20 40, 10 20, 30 10)) | A polygon with five vertices and an interior ring with x and y coordinates (30 10), (40 40), (20 40), (10 20), and (30 10) |
MultiPoint | MULTIPOINT((10 40), (40 30), (20 20), (30 10)) | A collection of four points with x and y coordinates (10 40), (40 30), (20 20), and (30 10) |
MultiLineString | MULTILINESTRING((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10)) | A collection of two line strings, each connecting multiple points |
MultiPolygon | MULTIPOLYGON(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5))) | A collection of two polygons |
GeometryCollection | GEOMETRYCOLLECTION(POINT(10 40), LINESTRING(30 10, 10 30, 40 40), POLYGON((30 10, 40 40, 20 40, 10 20, 30 10))) | A collection of point, linestring, and polygon geometries |
Point ZM | POINT ZM (1 2 3 4) | A point with x, y, z, and m values of 1, 2, 3, and 4, respectively |
Point M | POINT M (1 2 3) | A point with x, y, and m values of 1, 2, and 3, respectively |
Note: The x and y values in these examples are just for illustration purposes and don’t represent real-world coordinates.
WKT for Coordinate systems
Also known as “WKT for CRS” (Coordinate Reference System), is a text representation of coordinate system definitions that can be used to exchange information between GIS software and other systems.
GEODCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84", 6378137, 298.257223563, LENGTHUNIT["metre", 1]]],
CS[ellipsoidal, 2],
AXIS["Latitude (lat)", north, ORDER[1]],
AXIS["Longitude (lon)", east, ORDER[2]],
ANGLEUNIT["degree", 0.0174532925199433]]
Creating WKT in GIS software
The process for creating WKT in GIS software depends on the specific software you are using. Here are some general steps for creating WKT in some common GIS software:
- QGIS:
- Start QGIS and open a new map document.
- Add any necessary data layers to the map view.
- Right-click on a layer and select “Save As.”
- In the “Save Vector Layer As” dialog box, select “Comma Separated Values” as the format.
- In the “Geometry” section, select “Well Known Text (WKT)” as the “Type” option.
- Click “OK” and QGIS will create a new .csv file with the WKT representation of the layer’s geometries.
- ArcGIS:
- Start ArcGIS and open a new map document.
- Add any necessary data layers to the map view.
- Right-click on a layer and select “Data” > “Export Data.”
- In the “Export Data” dialog box, select “Well Known Text (WKT)” as the format.
- Choose a location to save the WKT file and click “OK.”
- ArcGIS will create a new .txt file with the WKT representation of the layer’s geometries.
PostGIS and WKT
PostGIS is a spatial database extension for the PostgreSQL database management system, and it provides support for storing, querying, and manipulating geographic data. Here are the steps to create WKT in PostGIS:
- Connect to a PostgreSQL database with PostGIS enabled.
- Create a table to store the WKT data:
CREATE TABLE wkt_data (
id serial PRIMARY KEY,
geom geometry(Point, 4326),
name text
);
- Insert some WKT data into the table:
INSERT INTO wkt_data (geom, name)
VALUES (ST_GeomFromText('POINT(30 10)', 4326), 'Point 1'),
(ST_GeomFromText('POINT(40 20)', 4326), 'Point 2');
- Select the WKT representation of the geometries:
SELECT ST_AsText(geom), name
FROM wkt_data;
This will return the following output:
POINT(30 10) | Point 1 POINT(40 20) | Point 2
Note that the ST_GeomFromText
and ST_AsText
functions are used to convert between WKT and PostGIS geometry data types. The first argument to ST_GeomFromText
is the WKT representation of the geometry, and the second argument is the SRID (Spatial Reference ID) of the coordinate system used for the geometry. The ST_AsText
function returns the WKT representation of a PostGIS geometry.
Ogr2ogr and WKT
ogr2ogr is a command line tool that is part of the GDAL (Geospatial Data Abstraction Library) library. It can be used to convert between various vector data formats, including WKT. Here are the steps to create a WKT file using ogr2ogr:
- Open a command prompt or terminal window.
- Navigate to the directory where you want to create the WKT file.
- Run the following command to create a WKT file from a source vector data file (e.g. Shapefile, GeoJSON, etc.):
ogr2ogr -f "CSV" output.csv input.shp -lco GEOMETRY=AS_WKT
This will convert the source vector data file (input.shp) to a comma-separated values (CSV) file (output.csv) with the geometries represented as WKT. The -f
option specifies the output format, and the -lco
option sets a layer creation option, in this case to specify that the geometries should be represented as WKT.
Note that the input and output file formats can be different, and ogr2ogr supports many different vector data formats. You can refer to the ogr2ogr documentation for more information on the supported formats and options.