Skip to content

Support extended geometry types in WKB, WKT and TWKB - #405

Merged
trasch merged 1 commit into
mainfrom
feature/extended-geometry-coders
Oct 28, 2026
Merged

trasch merged 1 commit into
mainfrom
feature/extended-geometry-coders

Conversation

@trasch

@trasch trasch commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #404.

Adds WKB, WKT and TWKB support for the extended geometry types that PostGIS can emit, using the lossy mappings agreed in the issue:

Input Decoded as
CircularString LineString
CompoundCurve LineString
CurvePolygon Polygon
MultiCurve MultiLineString
MultiSurface MultiPolygon
TIN MultiPolygon
PolyhedralSurface MultiPolygon
POINT EMPTY empty MultiPoint

Circular arcs are sampled with 32 segments per quadrant by a new internal CurveLinearization helper. Linearization happens in the source projection before reprojection, and Z/M values are interpolated along the arc.

WKB

  • Added type codes 8–12, 15 and 16, plus ISO SQL/MM dimension offsets (+1000 Z, +2000 M, +3000 ZM) used by PostGIS alongside EWKB dimension flags.
  • CircularString, CompoundCurve, CurvePolygon, MultiCurve and MultiSurface linearize into the existing model types.
  • TIN and PolyhedralSurface decode to MultiPolygon; triangle patches reuse the existing type-17 decoder.
  • POINT EMPTY (NaN coordinates) decodes to an empty MultiPoint instead of failing.

WKT

  • Parses CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON, MULTICURVE, MULTISURFACE, TIN and POLYHEDRALSURFACE, including nested dimension suffixes such as MULTISURFACE Z (CURVEPOLYGON Z (...)).
  • Accepts EMPTY for every geometry type, and empty geometries now encode as TYPE EMPTY instead of TYPE().
  • POINT EMPTY decodes to an empty MultiPoint.

TWKB

  • Empty metadata decodes to the matching empty geometry (POINT EMPTY becomes an empty MultiPoint).
  • PostGIS encodes TIN as a GeometryCollection in TWKB, so it decodes as a collection. TWKB has no curve or PolyhedralSurface type code; unsupported types now fail explicitly.

Verification

  • 3057 tests pass with --traits EnableGraphAPI.
  • Coverage: 90.34% weighted line coverage, above the 87.5% floor.
  • DocC builds without warnings.
  • The changed-file SwiftFormat gate reports no new violations.
  • Fixtures are deterministic PostGIS-generated WKB hex, TWKB hex and WKT strings.

Behavior changes

  • POINT EMPTY no longer throws in WKB/WKT; it decodes as an empty MultiPoint.
  • WKT encodes empty geometries with the EMPTY keyword rather than empty parentheses.
  • Curves and surfaces re-encode as their linear model types, which is documented in the DocC coder article.

@trasch trasch self-assigned this Oct 28, 2026
@trasch trasch added the enhancement New feature or request label Oct 28, 2026
@trasch
trasch merged commit 056aa06 into main Oct 28, 2026
6 checks passed
@trasch
trasch deleted the feature/extended-geometry-coders branch October 28, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant