← Back to Pull requests

Keep the Z and M of empty geometries in UnmarshalTWKB #723

Closed
unknown closed this pull request without merging on Nov 24, 2026 19:58 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 00:59 UTC
Author

UnmarshalTWKB reads the extended dimensions byte for empty geometries, and the Point and LineString parsers keep it, but an empty Polygon, MultiPoint, MultiLineString, MultiPolygon or GeometryCollection came back as XY. A collection holding one of them was then narrowed to XY, which dropped the Z and M of its other members.

PostGIS writes that byte for empty Z/M geometries. Decoding ST_AsTWKB(..., 0, 3, 0) output from PostGIS 3.5.2:

                     before                                         after
03180d               POLYGON EMPTY                                  POLYGON Z EMPTY
07180d               GEOMETRYCOLLECTION EMPTY                       GEOMETRYCOLLECTION Z EMPTY
07080d0203180d...    GEOMETRYCOLLECTION(POLYGON EMPTY,POINT(1 2))   GEOMETRYCOLLECTION Z (POLYGON Z EMPTY,POINT Z (1 2 3))
07080f0204180f...    GEOMETRYCOLLECTION(MULTIPOINT EMPTY,           GEOMETRYCOLLECTION ZM (MULTIPOINT ZM EMPTY,
                       LINESTRING(1 2,5 6))                           LINESTRING ZM (1 2 3 4,5 6 7 8))

The empty branches now use ForceCoordinatesType(p.ctype), as the WKB parser does, and so does a count of zero (the only empty form of a polygon inside a MultiPolygon). A non-empty collection keeps its children's types. XY empties are unchanged.

The new TWKBTestCases rows fail without the change and pass with it (all but the zero-count MultiPolygon row use skipEncode, since MarshalTWKB writes no extended byte for empty geometries, see #724); removing any one of the checks fails its rows. make unit (golang:1.19) and make lint (golangci-lint v1.61.0) pass. I didn't run the geos, pgscan or cmp jobs.

This only changes the parser. The writer still drops the dimensions of empty geometries, as the comment in writeIsEmptyHeader says it does, so a Z collection with an empty member does not round trip through MarshalTWKB; that is separate from #721.

Author Motivation

I found this by reading the TWKB parser with an AI assistant, not as a user of simplefeatures: the Point and LineString branches kept the dimensions of an empty geometry and the others didn't. I then checked the bytes against PostGIS's ST_AsTWKB.

Written with AI assistance (Claude); I have reviewed the change.

Diff: 281 lines (+210 / -71) across 3 files Reviewer: youdie006 Review duration: 6899m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 281 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.338
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #723"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.7% (MEDIUM) · Higher = larger blast radius
39.7%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.2% · Safe to merge
17.2%