Skip to content

EncDotNet.S57: attribute catalogue, object codes 161+ and long-name helpers #49

Closed

Description

@philliphoff

EncDotNet.S100 builds S-57 cells in memory (philliphoff/EncDotNet.S100#1210, the S-101 → S-57 translator) and writes them with S57DocumentWriter from 0.9.0 (philliphoff/EncDotNet.S100#1213). That work found three gaps in the EncDotNet.S57 types. 0.9.0 doesn't close any of them, so EncDotNet.S100 keeps a local workaround for each.

1. No attribute catalogue (ATTL → acronym and type)

There is no S57ObjectCode-style lookup for attributes. A caller can't turn an ATTL into its acronym (116 → OBJNAM), or the reverse, and can't get its type (E/L/F/I/A/S) or whether it is a national attribute (ATTL 300+, NATF).

Why it matters: a writer of S-57 needs to know which attributes are Lists (comma-joined values) and which are Enumerated (one value), and which go in NATF. A reader needs it to show attribute names.

Workaround in EncDotNet.S100: hand-written acronym → ATTL tables (S101ToS57Rules.S57AttributeCodes, plus a KnownAttls table in the round-trip test), and a list-attribute set.

Suggested shape: S57AttributeCode (enum, or a catalogue class) from the S-57 Appendix A Object Catalogue, with the acronym, ATTL, type and national flag.

2. S57ObjectCode stops at 160 (TS_FEB)

The S-57 Edition 3.1 Object Catalogue defines object classes 161–167 (TS_PRH, TS_PNH, TS_PAD, TS_TIS, T_HMON, T_NHMN, T_TIMS). NOAA cells use them: the local corpus has OBJL 163. The cartographic $ classes (500+, for example $CSYMB, $TEXTS) are also missing. The writer already counts that range for DSSI NOCR.

Why it matters: these codes can't be named, so Enum.IsDefined is false and the codes show up as bare numbers.

Workaround in EncDotNet.S100: cast the raw OBJL to S57ObjectCode and fall back to the number when naming it.

3. No helper to build a FOID/LNAM from its parts

  • S57RecordName.FromLongName(int agencyCode, int featureId, int featureSubdivision) takes FIDN as int. FIDN is a b14 (unsigned), so a FIDN above int.MaxValue needs unchecked((int)fidn). S57LongName holds it as uint. The two types disagree.
  • There's no conversion between S57LongName and S57RecordName, or to and from the packed 8-byte LNAM (AGEN b12, FIDN b14, FIDS b12) that FFPT holds.

Workaround in EncDotNet.S100: unchecked((int)fidn) when setting S57RecordName.FeatureId, and new S57LongName((ushort)agen, unchecked((uint)fidn), (ushort)fids) for FFPT.

Suggested shape: S57RecordName.FromLongName(S57LongName), an S57LongName property on feature record names that round-trips through uint, and S57LongName.ToLnam()/FromLnam(ReadOnlySpan<byte>).

Smaller, nice to have

  • Typed values for the DSID/DSPM codes a new base cell sets: EXPP, PRSP, PROF, DSTR, HDAT, DUNI/HUNI/PUNI, COUN. They are plain int today.
  • A helper that picks the lowest AALL/NALL that encodes a set of strings. EncDotNet.S100 has its own (S101ToS57LexicalLevels).

Activity

  1. philliphoff commented on Nov 3, 2026

    @philliphoff
    OwnerAuthor

    Done in #51 and #52. They aren't in a release yet; v0.9.0 predates them.

    1. Attribute catalogue. S57ObjectCatalogue.Iho maps attribute code ↔ acronym (116 ↔ OBJNAM), with Type (S57AttributeType: E/L/F/I/A/S) and enumerated values (#45). #51 adds Class (S57AttributeClass: Feature, National, Spatial, Cartographic) and IsNational for attributes that go in NATF. S57Document.GetObjectCatalogue() and S57Chart.GetObjectCatalogue() pick the right catalogue for a data set.

    2. Object codes above 160 (#51). A correction to the issue: TS_PRH, TS_PNH, TS_PAD, TS_TIS, T_HMON, T_NHMN and T_TIMS are codes 136–142 in S-57 Appendix A, and S57ObjectCode already had them. The codes that were actually missing are now members:

    • 161 ARCSLN, 162 ASLXIS and 163 NEWOBJ, from the Edition 3.1 supplement. The OBJL 163 in the NOAA corpus is NEWOBJ.

    • The cartographic $ classes, renamed because C# names can't contain $:

      Code Acronym Enum member
      500 $AREAS CartographicArea
      501 $LINES CartographicLine
      502 $CSYMB CartographicSymbol
      503 $COMPS CartographicCompass
      504 $TEXTS CartographicText

    3. Long names (#51).

    • S57RecordName.FromLongName(S57LongName) keeps a FIDN above int.MaxValue as the int with the same bits.
    • S57LongName.ToLnam(), TryWriteLnam(Span<byte>) and FromLnam(ReadOnlySpan<byte>) convert to and from the packed 8-byte LNAM: AGEN, FIDN and FIDS, each little-endian.
    • The reader and writer use these helpers for FFPT.

    Nice to have (#52).

    • Enums for the DSID/DSPM codes, valid in both directions with the existing int properties: S57ExchangePurpose, S57ProductSpecification, S57ApplicationProfile, S57DataStructure, S57HorizontalDatum, S57VerticalDatum, S57DepthUnits, S57HeightUnits, S57PositionalAccuracyUnits and S57CoordinateUnits.
    • S57LexicalLevels.Lowest(...) picks the lowest lexical level that encodes a set of strings. CanEncode(...) checks one string. WithLowestLevels(document) sets AALL/NALL from a document's values.

    EncDotNet.S100 can drop each of its workarounds once it moves to the release that includes these:

    Workaround Replacement
    S57AttributeCodes, KnownAttls and the list-attribute set S57ObjectCatalogue.Iho
    Casting a raw OBJL to S57ObjectCode The new enum members
    unchecked FIDN casts FromLongName(S57LongName) and ToLnam()/FromLnam()
    S101ToS57LexicalLevels S57LexicalLevels

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions