Skip to content

Support curved, TIN, PolyhedralSurface and empty-point geometries in WKB/WKT/TWKB #404

Closed

Description

@trasch

Context

mvt-postgis#29 tracks SQL-side conversions for geometry types that GISTools cannot decode. Native WKB/WKT/TWKB support belongs in this package.

Current state:

  • WKB: WKBCoder understands type codes 1–7 and 17 (Triangle, decoded as Polygon). Curves (8–12), PolyhedralSurface (15) and TIN (16) throw WKBCoderError.unexpectedType.
  • WKT: WKTCoder parses Point, MultiPoint, LineString, LinearRing, Polygon, MultiPolygon, GeometryCollection and Triangle. Curves, TIN and PolyhedralSurface are not recognized.
  • TWKB: TWKBCoder decodes type codes 1–7 only.
  • Empty Point: WKB stores POINT EMPTY as NaN coordinates, which WKBCoder rejects as invalidGeometry. Point has no empty representation, while the other empty geometries decode with zero parts.

Proposed work

Curves

Add decoding/encoding for WKB types 8–12 and the matching WKT names:

Type WKB WKT
CircularString 8 CIRCULARSTRING
CompoundCurve 9 COMPOUNDCURVE
CurvePolygon 10 CURVEPOLYGON
MultiCurve 11 MULTICURVE
MultiSurface 12 MULTISURFACE

Decide between:

  • native curve types in the geometry model, or
  • linearizing into LineString/Polygon/Multi* with a documented tolerance.

TIN and PolyhedralSurface

  • TIN is WKB type 16; PolyhedralSurface is 15.
  • Proposed mapping: decode TIN patches as Polygon triangles and PolyhedralSurface patches as polygons, then return a MultiPolygon or GeometryCollection.
  • Add WKT parsing/serialization for both.
  • Confirm whether TWKB can represent them; if not, document the limitation.

Empty Point

Choose a representation:

  • an EmptyGeometry type, or
  • an optional/empty coordinate on Point, or
  • an explicit decode error with a documented rule.

If a representation is added, make empty handling consistent across Point, LineString, Polygon, the multi-types and GeometryCollection in WKB, WKT and TWKB.

Coders and dimensions

  • Keep Z, M and ZM handling consistent with the existing WKB flag decoding.
  • Preserve SRID handling for WKB and TWKB.
  • Ensure encoding is the inverse of decoding where the mapping is lossless.

Acceptance criteria

  • Deterministic WKB, WKT and TWKB fixtures for every type above.
  • Decode and encode tests, including Z/M/ZM and SRID variants.
  • Lossy mappings are documented and asserted.
  • Empty Point behavior is explicit in all three coders.
  • DocC support matrix updated.
  • mvt-postgis#29 can either drop its SQL fallback or keep it as compatibility.

Out of scope

  • Abstract Curve and Surface types: they cannot appear as concrete geometry values.
  • PostGIS-specific SQL conversion functions (ST_CurveToLine, ST_UnaryUnion, ST_Dump) — those stay in mvt-postgis#29.

References

  • mvt-postgis#29, mvt-postgis#15
  • Sources/GISTools/GeoJson/WKBCoder.swift
  • Sources/GISTools/GeoJson/WKTCoder.swift
  • Sources/GISTools/GeoJson/TWKBCoder.swift

Activity

  1. added
    enhancement
    on Oct 28, 2026
  2. trasch commented on Oct 28, 2026

    @trasch
    ContributorAuthor

    Follow-up from Outdooractive/mvt-postgis#29: the SQL-side conversions (ST_CurveToLine, ST_UnaryUnion, ST_Dump/ST_Collect) stay in mvt-postgis; this issue covers native WKB/WKT/TWKB support.

  3. self-assigned this
    on Oct 28, 2026
  4. trasch commented on Oct 28, 2026

    @trasch
    ContributorAuthor

    Implemented in #405.

    • WKB/WKT decode curves by linearizing into LineString/Polygon/Multi*.
    • TIN and PolyhedralSurface decode to MultiPolygon.
    • POINT EMPTY decodes to an empty MultiPoint; WKT supports EMPTY for all types and encodes it as TYPE EMPTY.
    • WKB accepts ISO SQL/MM dimension codes in addition to EWKB flags.
    • TWKB empty metadata decodes to the matching empty geometry; TIN arrives as a GeometryCollection because that is how PostGIS encodes it. Curves and PolyhedralSurface are explicitly unsupported in TWKB.

    Verification: 3057 tests, 90.34% coverage, DocC clean, no new formatting violations.

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

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions