WellKnownText Class
Reads and writes the Well-Known Text (WKT) representation of a geometry, such as POINT (2.35 48.86), as defined by the OGC Simple Features and ISO 19125.
public static class WellKnownTextRemarks
The reader accepts the seven geometry types, in any case and with any whitespace, the Z, M and ZM tags, also written after the type as in PostGIS (POINTZ), positions of 3 numbers without a tag (an altitude) or of 4 numbers (an altitude and a measure), the multipoints with and without parentheses around their points (MULTIPOINT ((1 2), (3 4)) and MULTIPOINT (1 2, 3 4)) and the SRID=4326; prefix of the extended WKT of PostGIS (EWKT), which WellKnownText.Parse returns. It keeps the Z values as GeoPosition.Altitude and the M values as GeoPosition.Measure. A child of a GEOMETRYCOLLECTION without a tag uses the tag of the collection.
POINT EMPTY becomes an empty GeoMultiPoint, as a GeoPoint always has a position, and the empty points of a MULTIPOINT are skipped. The other types are rejected, such as CIRCULARSTRING, TRIANGLE or TIN.
The writer writes the ISO form (POINT Z (1 2 3), POINT ZM (1 2 3 4), MULTIPOINT ((1 2), (3 4))) with the shortest numbers that read back to the same values. A geometry has a single number of dimensions: when a position of the geometry has an altitude, every position is written with one, and a missing altitude is written as 0; the same goes for the measures (M or ZM). The times of the positions are not written, as WKT has no place for them.
Methods
| Name | Description |
|---|---|
| Format(GeoGeometry) | Writes the WKT of a geometry, such as POINT (2.35 48.86). |
| Parse(string) | Reads the WKT, or the extended WKT of PostGIS, of a geometry. |
| Parse(string, int?) | Reads the WKT, or the extended WKT of PostGIS, of a geometry, and the SRID of the extended WKT. |
Format(GeoGeometry)
WellKnownText.csWrites the WKT of a geometry, such as POINT (2.35 48.86).
public static string Format(GeoGeometry geometry)Parameters
geometryGeoGeometry- The geometry.
Returns
string The WKT of the geometry.
Exceptions
ArgumentException- A position is not finite.
Parse overloads
Parse(string)
WellKnownText.csReads the WKT, or the extended WKT of PostGIS, of a geometry.
public static GeoGeometry Parse(string text)Parameters
textstring- The text, such as
POINT (2.35 48.86)orSRID=4326;LINESTRING Z (0 0 10, 1 1 20).
Returns
GeoGeometry The geometry.
Exceptions
FormatException- The text is not the WKT of a supported geometry. The message gives the position of the error in the text.
Parse(string, int?)
WellKnownText.csReads the WKT, or the extended WKT of PostGIS, of a geometry, and the SRID of the extended WKT.
public static GeoGeometry Parse(string text, out int? srid)Parameters
textstring- The text, such as
SRID=2154;POINT (652310.72 6862414.64). sridint?- The SRID of the
SRID=prefix, usually an EPSG code thatCoordinateReferenceSystem.FromEpsgconverts to a coordinate reference system, ornullwhen the text has no prefix.
Returns
GeoGeometry The geometry, with the coordinates of the text: they are not converted.
Exceptions
FormatException- The text is not the WKT of a supported geometry. The message gives the position of the error in the text.