# Package org.apache.sis.io.wkt

package org.apache.sis.io.wkt
Well Known Text (WKT) parsing and formatting. This package implements the services provided by various convenience methods:

- `CRS​.fromWKT(String)` (SIS parsing static method)
- `CRSFactory​.createFromWKT(String)` (GeoAPI parsing method)
- `MathTransformFactory​.createFromWKT(String)` (GeoAPI parsing method)
- `IdentifiedObject​.toWKT()` (GeoAPI formatting method)

However the `WKTFormat` class provided in this package gives more control. For example this package allows to:

- Format projection and parameters using the names of a chosen authority. For example the "Mercator (variant A)" projection is named `"Mercator_1SP"` by OGC 01-009 and `"CT_Mercator"` by GeoTIFF.
- Format the elements with different quote characters or brackets style. For example both `ID["EPSG",4326]` and `ID("EPSG",4326)` are legal WKT.
- Format with a different indentation or format the whole WKT on a single line.
- Apply syntactic coloring on terminal supporting ANSI escape codes (a.k.a. ECMA-48, ISO/IEC 6429 and X3.64).
- Alter the parsing in a way compatible with non-standard (but commonly used) WKT. For example some others software products ignore the `AXIS[…]` elements at parsing time.
- Report warnings that occurred during parsing or formatting.

## Referencing WKT

Referencing WKT is defined using Extended Backus Naur Form (EBNF) in two versions:

- ISO 19162 defines the current format, also known as “WKT 2”. The specification is also made available online by OGC.
- The previous format — “WKT 1” — was defined in the OGC document 01-009. This definition is shown on GeoAPI.

The WKT 1 format has been interpreted differently by various implementers. One noticeable difference is the unit of measurement of prime meridians and projection parameters. The WKT 2 format aims to solve the inter-operability problem caused by such mismatches, but not all software products support this new format. Consequently importing or exporting data from/to a software with the WKT syntax require knowledge of the WKT variant used by that software. This variant can be specified by the `Convention` enumeration.

## Geometry WKT

The `GeneralEnvelope` and `GeneralDirectPosition` classes provide their own, limited, WKT parsing and formatting services for the `BOX` and `POINT` elements. A description for this WKT format can be found on Wikipedia.

## Where to find WKT examples

An excellent source of well-formed WKT is the online EPSG Geodetic Parameter Registry. The WKT of many Coordinate Reference System object can be viewed using the pattern below (replace `3395` by the EPSG code of the desired CRS):

> Example: "WGS 84 / World Mercator": https://epsg.org/crs/wkt/id/3395

Readers should be aware that some popular other sources of WKT are actually invalid, since many of them do not comply with EPSG definitions (especially on axis order). The above-cited EPSG repository is the authoritative source of CRS definitions in the EPSG namespace.

Since:
  0.4
See Also:
  - WKT 2 specification
  - Legacy WKT 1

Defined in the `sis-referencing` module

- Related Packages
  Package
  Description
  org.apache.sis.io
  Extensions to standard Java I/O (`Reader`, `Writer`, `Appendable`) and `Format`.
- Class
  Description
  Colors
  The colors to use for formatting Well Known Text (WKT) objects.
  Convention
  The convention to use for WKT formatting.
  ElementKind
  Kind of an element in a Well Known Text.
  FormattableObject
  Base class for objects that can be formatted as Well Known Text (WKT).
  Formatter
  Provides support methods for formatting a Well Known Text (WKT).
  KeywordCase
  Whether WKT keywords shall be written with lower, upper or camel case styles.
  KeywordStyle
  Whether to use short or long WKT keywords.
  Parser
  A parser or a factory capable to create an object from a string in the WKT format.
  Symbols
  The set of symbols to use for Well Known Text (WKT) parsing and formatting.
  Transliterator
  Controls the replacement of characters, abbreviations and names between the objects in memory and their WKT representations.
  UnformattableObjectException
  Thrown by `FormattableObject​.toWKT()` when an object can not be formatted as WKT.
  UnparsableObjectException
  Thrown when a Well Known Text (WKT) can not be parsed.
  Warnings
  Warnings that occurred during a Well Known Text (WKT) parsing or formatting.
  WKTDictionary
  A factory providing CRS objects parsed from WKT definitions associated to authority codes.
  WKTFormat
  Parser and formatter for Well Known Text (WKT) strings.