Table of Contents

Class S57DocumentWriter

Namespace
EncDotNet.S57
Assembly
EncDotNet.S57.dll

Provides methods to write an S57Document as an S-57 Edition 3.1 base cell (a .000 file) in the ISO/IEC 8211 binary implementation.

public static class S57DocumentWriter
Inheritance
S57DocumentWriter
Inherited Members

Remarks

The writer is the inverse of S57DocumentReader: a cell it writes reads back as an equal document. It writes, in order:

  1. The data descriptive record (DDR), with the field definitions of the ENC product specification and the ATTF and NATF lexical levels in their field controls (S-57 Part 3, Annex A and Annex B.2).
  2. The data set general information record: DSID and DSSI (clause 7.3.1). The DSSI record counts are computed from the document's records.
  3. The data set geographic reference record: DSPM (clause 7.3.2).
  4. Each vector record, in document order: VRID, ATTV, VRPT, then SG2D or SG3D, then each ARCC with its AR2D, EL2D and CT2D fields (clause 7.7). The DDR declares the arc/curve fields only when a vector record has them.
  5. Each feature record, in document order: FRID, FOID, ATTF, NATF, FFPT, then FSPT (clause 7.6).

Every data record starts with the 0001 record identifier field, numbered from 1. Fields with no content (no attributes, pointers or coordinates) are omitted.

The output depends only on the document: the writer reads no clock, so writing the same document always produces the same bytes. Dates such as the issue date (ISDT) are written as the document holds them.

Only base cells are supported. Every record must have the update instruction Insert and no update control fields (FSPC, FFPC, VRPC or SGCC); update cells (ER) aren't written.

ATTF values are encoded at the DSSI lexical level AttfLexicalLevel (0 = ASCII, 1 = ISO 8859-1), and NATF values at NatfLexicalLevel (0, 1, or 2 = UCS-2). The DSID, DSPM and FFPT comments (COMT) are ISO 8859-1, which reads the same as ASCII for conforming comments and round-trips the Latin-1 characters some producers (NATO AML cells, for example) put there. All other character data is ASCII (S-57 Part 3, clause 2.4). A value its encoding can't represent is an error rather than being replaced.

Methods

Write(S57Document)

Writes an S-57 document to a byte array.

public static byte[] Write(S57Document document)

Parameters

document S57Document

The document to write.

Returns

byte[]

The encoded base cell.

Exceptions

ArgumentException

The document can't be encoded as a base cell; the message names the record and subfield.

Write(Stream, S57Document)

Writes an S-57 document to a stream.

public static void Write(Stream stream, S57Document document)

Parameters

stream Stream

The destination stream.

document S57Document

The document to write.

Exceptions

ArgumentException

The document can't be encoded as a base cell. Nothing is written to the stream.

WriteAsync(Stream, S57Document, CancellationToken)

Asynchronously writes an S-57 document to a stream.

public static Task WriteAsync(Stream stream, S57Document document, CancellationToken cancellationToken = default)

Parameters

stream Stream

The destination stream.

document S57Document

The document to write.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task

A task that represents the asynchronous write operation.

Exceptions

ArgumentException

The document can't be encoded as a base cell. Nothing is written to the stream.

WriteToFile(string, S57Document)

Writes an S-57 document to a file.

public static void WriteToFile(string path, S57Document document)

Parameters

path string

The destination file path.

document S57Document

The document to write.

Exceptions

ArgumentException

The document can't be encoded as a base cell. The file isn't created or changed.

WriteToFileAsync(string, S57Document, CancellationToken)

Asynchronously writes an S-57 document to a file.

public static Task WriteToFileAsync(string path, S57Document document, CancellationToken cancellationToken = default)

Parameters

path string

The destination file path.

document S57Document

The document to write.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task

A task that represents the asynchronous write operation.

Exceptions

ArgumentException

The document can't be encoded as a base cell. The file isn't created or changed.