Class Wkb
- Namespace
- SpatialNET.IO
- Assembly
- SpatialNET.IO.dll
Reading and writing WKB (ADR 0016). Reading accepts ISO WKB and EWKB in either byte order and creates the geometries through the geometry factory; writing produces ISO WKB in little endian.
public static class WkbInheritance
Inherited Members
Remarks
Type mapping as for WKT (ADR 0009): Point → SpatialNET.IPoint2D, a point with NaN coordinates and MultiPoint → SpatialNET.IMultiPoint2D, (Multi)LineString → SpatialNET.IPolyline2D, (Multi)Polygon → SpatialNET.IPolygon2D. An SRID in an EWKB header is read and discarded. Curves and other surface types are not supported.
Methods
Read(ReadOnlySpan<byte>, IGeometryFactory?)
Reads a geometry.
public static IGeometry2D Read(ReadOnlySpan<byte> wkb, IGeometryFactory? factory = null)Parameters
wkbReadOnlySpan<byte>-
The WKB bytes.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
Exceptions
- FormatException
-
The data is not valid WKB; the message names the byte offset.
- NotSupportedException
-
The data is a GeometryCollection (use SpatialNET.IO.Wkb.ReadAll(System.ReadOnlySpan{System.Byte},SpatialNET.IGeometryFactory) instead), a curve or another unsupported type.
- InvalidOperationException
-
Neither
factorynor SpatialNET.GeometryFactory.Default is set.
Read<T>(ReadOnlySpan<byte>, IGeometryFactory?)
Reads a geometry of an expected kind.
public static T Read<T>(ReadOnlySpan<byte> wkb, IGeometryFactory? factory = null) where T : IGeometry2DParameters
wkbReadOnlySpan<byte>-
The WKB bytes.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
- T
Type Parameters
T-
The expected geometry kind, e.g. SpatialNET.IPolygon2D.
Exceptions
- FormatException
-
The data is not valid WKB or not a geometry of kind
T.
ReadAll(ReadOnlySpan<byte>, IGeometryFactory?)
Reads all geometries; a GeometryCollection is flattened.
public static IReadOnlyList<IGeometry2D> ReadAll(ReadOnlySpan<byte> wkb, IGeometryFactory? factory = null)Parameters
wkbReadOnlySpan<byte>-
The WKB bytes.
factoryIGeometryFactory?-
The factory;
null= SpatialNET.GeometryFactory.Default.
Returns
Exceptions
- FormatException
-
The data is not valid WKB.
ToWkb(IGeometry2D, WkbOptions?)
Writes the geometry as ISO WKB (little endian): leanest type (Polygon for one part, LineString for one path; a multipoint stays MultiPoint), rings closed, shells counter-clockwise and holes clockwise, degenerate rings dropped. No SRID is written.
public static byte[] ToWkb(this IGeometry2D geometry, WkbOptions? options = null)Parameters
geometryIGeometry2D-
The geometry.
optionsWkbOptions?-
The options;
null= SpatialNET.IO.WkbOptions.Default.
Returns
- byte[]
Exceptions
- ArgumentNullException
-
geometryisnull. - ArgumentException
-
A coordinate has a non-finite X or Y, or an infinite Z or M.
- NotSupportedException
-
geometryis not a known geometry kind.