This is a unit-tested NuGet C# library that can convert Well Known Text (WKT) / Well Known Binary (WKB) to and from ESRI's ArcGIS Runtime Geometry.
The motivation for this library is a no-dependency and small footprint WKT/WKB parser for Runtime Geometry. It has some limited-functionality but serves as a viable alternative to (albeit more robust but bloated) libraries such as SharpMap
This library is to be used in conjection with NuGet package Esri.ArcGISRuntime for .NET
Install NuGet package https://www.nuget.org/packages/ArcGISRuntimeWKT/ (note: it is pre-release)
or via Package Manager Console: Install-Package ArcGISRuntimeWKT -Pre
using Esri.ArcGISRuntime.Geometry;
using ArcGISRuntimeWKT;
Geometry geometry = Parser.GeometryFromWkt("LINESTRING(9.3 26.93,21 34,27 30)");
Console.Write(geometry.GetType()); //Esri.ArcGISRuntime.Geometry.Polyline
var point = new MapPoint(30, 20);
string wkt = Parser.GeometryToWkt(point);
Console.Write(wkt); //POINT(30 20)
The following WKT and WKB are not supported at this time: MultiPoint, GeometryCollection, CircularString, CompoundCurve, CurvePolygon, MultiCurve, MultiSurface, Curve, Surface, PolyhedralSurface, TIN, Triangle,
Created on Windows 10, Visual Studio 2015, with ArcGISRuntime version 10.2.7.1234 and .NET framework 4.5.2. Additionally tested on Windows 7 and ArcGISRuntime version 10.2.4+ and .NET framework 4.5
The Well-known Binary (WKB) representation for Geometry provides a portable representation of a Geometry value as a contiguous stream of bytes. It permits Geometry values to be exchanged between an ODBC client and an SQL database in binary form.
The Well-known Binary Representation for Geometry is obtained by serializing a Geometry instance as a sequence of numeric types drawn from the set {Unsigned Integer, Double} and then serializing each numeric type as a sequence of bytes using one of two well defined, standard, binary representations for numeric types (NDR, XDR). The specific binary encoding (NDR or XDR) used for a geometry byte stream is described by a one byte tag that precedes the serialized bytes. The only difference between the two encodings of geometry is one of byte order, the XDR encoding is Big Endian, the NDR encoding is Little Endian.
The Well-Known Text (WKT) representation of Geometry is designed to exchange geometry data in ASCII form. Examples of WKT representations of the most geometry objects are:
Representation | WKT | Supported |
---|---|---|
Point | POINT(15 20) | True |
LineString with four points | LINESTRING(0 0, 10 10, 20 25, 50 60) | True |
Polygon with one exterior ring and one interior ring | POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5)) | True |
MultiPoint with three Point values | MULTIPOINT(0 0, 20 20, 60 60) | False |
MultiLineString with two LineString values | MULTILINESTRING((10 10, 20 20), (15 15, 30 15)) | True |
MultiPolygon with two Polygon values | MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5))) | True |
GeometryCollection consisting of two Point values and one LineString | GEOMETRYCOLLECTION(POINT(10 10),POINT(30 30),LINESTRING(15 15, 20 20)) | False |
GeometryFromWkb(bytes) method
#
Creates a Geometry from the supplied byte[] containing the Well-known Binary representation.
A Geometry bases on the supplied Well-known Binary representation.
Name | Type | Description |
---|---|---|
bytes | System.Byte[] | byte[] containing the Well-known Binary representation. |
GeometryFromWkb(reader) method
#
Creates a Geometry based on the Well-known binary representation.
A Geometry based on the Well-known binary representation.
Name | Type | Description |
---|---|---|
reader | System.IO.BinaryReader | A BinaryReader used to read the Well-known binary representation. |
GeometryFromWkt(wellKnownText) method
#
Converts a Well-known text representation to a Geometry.
Returns a Geometry specified by wellKnownText. Throws an exception if there is a parsing problem.
Name | Type | Description |
---|---|---|
wellKnownText | System.String | A Geometry tagged text string ( see the OpenGIS Simple Features Specification. ) |
GeometryFromWkt(reader) method
#
Converts a Well-known Text representation to a Geometry.
Returns a Geometry read from StreamReader. An exception will be thrown if there is a parsing problem.
Name | Type | Description |
---|---|---|
reader | System.IO.TextReader | A Reader which will return a Geometry Tagged Text string (see the OpenGIS Simple Features Specification) |
GeometryToWkb(g) method
#
Writes a geometry to a byte array using little endian byte encoding
WKB representation of the geometry
Name | Type | Description |
---|---|---|
g | Esri.ArcGISRuntime.Geometry | The geometry to write |
GeometryToWkb(g,wkbByteOrder) method
#
Writes a geometry to a byte array using the specified encoding.
WKB representation of the geometry
Name | Type | Description |
---|---|---|
g | Esri.ArcGISRuntime.Geometry | The geometry to write |
wkbByteOrder | ArcGISRuntimeWKT.WkbByteOrder | Byte order |
GeometryToWkt(geometry) method
#
Converts a Geometry to its Well-known Text representation.
A string (see the OpenGIS Simple Features Specification)
Name | Type | Description |
---|---|---|
geometry | Esri.ArcGISRuntime.Geometry | A Geometry to write. |
GeometryToWkt(geometry,writer) method
#
Converts a Geometry to its Well-known Text representation.
Name | Type | Description |
---|---|---|
geometry | Esri.ArcGISRuntime.Geometry | A geometry to process. |
writer | System.IO.StringWriter | Stream to write out the geometry's text representation. |
Geometry is written to the output stream as string (see the OpenGIS Simple Features Specification).
WkbByteOrder #
ArcGISRuntimeWKT
Specifies the specific binary encoding (NDR or XDR) used for a geometry byte stream
Ndr constants
#
NDR (Little Endian) Encoding of Numeric Types
The NDR representation of an Unsigned Integer is Little Endian (least significant byte first).
The NDR representation of a Double is Little Endian (sign bit is last byte).
Xdr constants
#
XDR (Big Endian) Encoding of Numeric Types
The XDR representation of an Unsigned Integer is Big Endian (most significant byte first).
The XDR representation of a Double is Big Endian (sign bit is first byte).