Class WKBReader
Converts a Well-Known Binary byte data to a Geometry
.
Inherited Members
Namespace: NetTopologySuite.IO
Assembly: NetTopologySuite.dll
Syntax
public class WKBReader
Remarks
This class reads the format describe in {@link WKBWriter}. It partially handles theExtended WKB format used by PostGIS, by parsing and storing optional SRID values. If a SRID is not specified in an element geometry, it is inherited from the parent's SRID. The default SRID value depends on DefaultSRID.
Although not defined in the WKB spec, empty points
are handled if they are represented as a Point with NaN
X and Y ordinates.
The reader repairs structurally-invalid input (specifically, LineStrings and LinearRings which contain too few points have vertices added, and non-closed rings are closed).
The reader handles most errors caused by malformed or malicious WKB data.
It checks for obviously excessive values of the fields
numElems
, numRings
, and numCoords
.
It also checks that the reader does not read beyond the end of the data supplied.
A ParseException is thrown if this situation is detected.
Constructors
| Improve this Doc View SourceWKBReader()
Initialize reader with a standard NtsGeometryServices.
Declaration
public WKBReader()
WKBReader(NtsGeometryServices)
Creates an instance of this class using the provided NtsGeometryServices
Declaration
public WKBReader(NtsGeometryServices services)
Parameters
Type | Name | Description |
---|---|---|
NtsGeometryServices | services |
Properties
| Improve this Doc View SourceAllowedOrdinates
Gets a value indicating which ordinates can be handled.
Declaration
public Ordinates AllowedOrdinates { get; }
Property Value
Type | Description |
---|---|
Ordinates |
HandleOrdinates
Gets a value indicating which ordinates should be handled.
Declaration
public Ordinates HandleOrdinates { get; set; }
Property Value
Type | Description |
---|---|
Ordinates |
HandleSRID
Gets or sets a value indicating if a possibly encoded SRID value should be handled.
Declaration
public bool HandleSRID { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
IsStrict
Gets or sets a value indicating if the reader should attempt to repair malformed input.
Declaration
public bool IsStrict { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
Malformed in this case means the ring has too few points (4), or is not closed.
RepairRings
Gets or sets whether invalid linear rings should be fixed
Declaration
[Obsolete("Use !IsStrict")]
public bool RepairRings { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc View SourceHexToBytes(String)
Converts a hexadecimal string to a byte array. The hexadecimal digit symbols are case-insensitive.
Declaration
public static byte[] HexToBytes(string hex)
Parameters
Type | Name | Description |
---|---|---|
String | hex | A string containing hex digits |
Returns
Type | Description |
---|---|
Byte[] | An array of bytes with the value of the hex string |
Read(Byte[])
Declaration
public Geometry Read(byte[] data)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | data | The byte array to read from |
Returns
Type | Description |
---|---|
Geometry | The geometry read |
Exceptions
Type | Condition |
---|---|
ParseException | if the WKB data is ill-formed. |
Read(BinaryReader)
Declaration
protected Geometry Read(BinaryReader reader)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader |
Returns
Type | Description |
---|---|
Geometry |
Read(Stream)
Declaration
public virtual Geometry Read(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read from |
Returns
Type | Description |
---|---|
Geometry | The geometry read |
Exceptions
Type | Condition |
---|---|
ParseException | if the WKB data is ill-formed. |
ReadCoordinateSequence(BinaryReader, Int32, WKBReader.CoordinateSystem)
Function to read a coordinate sequence.
Declaration
protected CoordinateSequence ReadCoordinateSequence(BinaryReader reader, int size, WKBReader.CoordinateSystem cs)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
Int32 | size | The number of ordinates |
WKBReader.CoordinateSystem | cs | The coordinate system |
Returns
Type | Description |
---|---|
CoordinateSequence | The read coordinate sequence. |
ReadCoordinateSequenceLineString(BinaryReader, Int32, WKBReader.CoordinateSystem)
Function to read a coordinate sequence that is supposed to serve a line string.
Declaration
protected CoordinateSequence ReadCoordinateSequenceLineString(BinaryReader reader, int size, WKBReader.CoordinateSystem cs)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
Int32 | size | The number of ordinates |
WKBReader.CoordinateSystem | cs | The coordinate system |
Returns
Type | Description |
---|---|
CoordinateSequence | The read coordinate sequence. |
ReadCoordinateSequenceRing(BinaryReader, Int32, WKBReader.CoordinateSystem)
Function to read a coordinate sequence that is supposed to form a ring.
Declaration
protected CoordinateSequence ReadCoordinateSequenceRing(BinaryReader reader, int size, WKBReader.CoordinateSystem cs)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
Int32 | size | The number of ordinates |
WKBReader.CoordinateSystem | cs | The coordinate system |
Returns
Type | Description |
---|---|
CoordinateSequence | The read coordinate sequence. |
ReadGeometryCollection(BinaryReader, WKBReader.CoordinateSystem, Int32)
Reads a GeometryCollection geometry.
Declaration
protected Geometry ReadGeometryCollection(BinaryReader reader, WKBReader.CoordinateSystem cs, int srid)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
WKBReader.CoordinateSystem | cs | The coordinate system |
Int32 | srid | The spatial reference id for the geometry. |
Returns
Type | Description |
---|---|
Geometry | A GeometryCollection geometry |
ReadLinearRing(BinaryReader, WKBReader.CoordinateSystem, Int32)
Reads a LinearRing geometry.
Declaration
protected LinearRing ReadLinearRing(BinaryReader reader, WKBReader.CoordinateSystem cs, int srid)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
WKBReader.CoordinateSystem | cs | The coordinate system |
Int32 | srid | The spatial reference id for the geometry. |
Returns
Type | Description |
---|---|
LinearRing | A LinearRing geometry |
ReadLineString(BinaryReader, WKBReader.CoordinateSystem, Int32)
Reads a LineString geometry.
Declaration
protected Geometry ReadLineString(BinaryReader reader, WKBReader.CoordinateSystem cs, int srid)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
WKBReader.CoordinateSystem | cs | The coordinate system |
Int32 | srid | The spatial reference id for the geometry. |
Returns
Type | Description |
---|---|
Geometry | A LineString geometry |
ReadMultiLineString(BinaryReader, WKBReader.CoordinateSystem, Int32)
Reads a MultiLineString geometry.
Declaration
protected Geometry ReadMultiLineString(BinaryReader reader, WKBReader.CoordinateSystem cs, int srid)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
WKBReader.CoordinateSystem | cs | The coordinate system |
Int32 | srid | The spatial reference id for the geometry. |
Returns
Type | Description |
---|---|
Geometry | A MultiLineString geometry |
ReadMultiPoint(BinaryReader, WKBReader.CoordinateSystem, Int32)
Reads a MultiPoint geometry.
Declaration
protected Geometry ReadMultiPoint(BinaryReader reader, WKBReader.CoordinateSystem cs, int srid)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
WKBReader.CoordinateSystem | cs | The coordinate system |
Int32 | srid | The spatial reference id for the geometry. |
Returns
Type | Description |
---|---|
Geometry | A MultiPoint geometry |
ReadMultiPolygon(BinaryReader, WKBReader.CoordinateSystem, Int32)
Reads a MultiPolygon geometry.
Declaration
protected Geometry ReadMultiPolygon(BinaryReader reader, WKBReader.CoordinateSystem cs, int srid)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
WKBReader.CoordinateSystem | cs | The coordinate system |
Int32 | srid | The spatial reference id for the geometry. |
Returns
Type | Description |
---|---|
Geometry | A MultiPolygon geometry |
ReadPoint(BinaryReader, WKBReader.CoordinateSystem, Int32)
Reads a Point geometry.
Declaration
protected Geometry ReadPoint(BinaryReader reader, WKBReader.CoordinateSystem cs, int srid)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
WKBReader.CoordinateSystem | cs | The coordinate system |
Int32 | srid | The spatial reference id for the geometry. |
Returns
Type | Description |
---|---|
Geometry | A Point geometry |
ReadPolygon(BinaryReader, WKBReader.CoordinateSystem, Int32)
Reads a Polygon geometry.
Declaration
protected Geometry ReadPolygon(BinaryReader reader, WKBReader.CoordinateSystem cs, int srid)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The reader |
WKBReader.CoordinateSystem | cs | The coordinate system |
Int32 | srid | The spatial reference id for the geometry. |
Returns
Type | Description |
---|---|
Geometry | A Polygon geometry |