MarshalTWKB writes incorrect output for empty geometries
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- data-engineering
Research direction
The bug is in the TWKB encoder: start with writeAdditionalHeaders and writeMultiPoint in the TWKB marshalling code, and check how w.isEmpty is set. Reproduce with MarshalTWKB on POINT EMPTY and MULTIPOINT(EMPTY,5 5) and round-trip through UnmarshalTWKB. Done means empty geometries emit no size or bounding box bytes, and the MultiPoint empty-point case is resolved (skip or error) with tests covering the ID-list interaction.
Written by the indexing model from the issue text.
Description
MarshalTWKB has two bugs involving empty geometries. Both reproduce on master at ce2170a.
Stray size and bounding box bytes after an empty geometry
An empty geometry is written with only the "is empty" bit set in its metadata header, so the header doesn't declare a size or a bounding box. writeAdditionalHeaders still runs afterwards and appends them when TWKBSizeHeader() or TWKBBoundingBoxHeader() is used.
| Geometry | Option | Output | Expected |
|---|---|---|---|
POINT EMPTY |
size | 011000 |
0110 |
POINT EMPTY |
bbox | 011000000000 |
0110 |
GEOMETRYCOLLECTION EMPTY |
bbox | 071000000000 |
0710 |
At the top level the extra bytes trail the geometry and UnmarshalTWKB ignores them. Inside a collection they sit in front of the next child and break parsing:
g, _ := geom.UnmarshalWKT("GEOMETRYCOLLECTION(POINT EMPTY,POINT(1 1))")
b, _ := geom.MarshalTWKB(g, 0, geom.TWKBSizeHeader())
// b is 070209020110000102020202. The empty point is written as 01 10 00.
_, err := geom.UnmarshalTWKB(b)
// TWKB parsing error at byte 12: unsupported geometry type 0
A likely fix is for writeAdditionalHeaders to return early when w.isEmpty is set.
Empty points in a MultiPoint are written as (0 0)
writeMultiPoint writes the coordinates of every point without checking whether the point is empty, so an empty point comes out as zeros:
g, _ := geom.UnmarshalWKT("MULTIPOINT(EMPTY,5 5)")
b, _ := geom.MarshalTWKB(g, 0)
// b is 04000200000a0a
back, _ := geom.UnmarshalTWKB(b)
// back is MULTIPOINT((0 0),(5 5))
With TWKBBoundingBoxHeader() the bounding box is (0 0)-(5 5) instead of (5 5)-(5 5). Once #720 is merged, that box also widens the bounding box of an enclosing GeometryCollection.
TWKB stores a MultiPoint as a count followed by coordinates, so it doesn't have a way to mark one of the points as empty. The options are to skip empty points or to return an error. Skipping changes the point count, which matters when TWKBIDList is used, because the ID list has to match the number of points.
- Dominant language
- Go
- Stars
- 176
- Forks
- 27
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from peterstace/simplefeatures
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
peterstace/simplefeatures#726 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
peterstace/simplefeatures#725 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 58/100
peterstace/simplefeatures#724 ·
-
cleanup
Difficulty 3/5 1-2 days Newbie friendliness 35/100
peterstace/simplefeatures#722 ·
-
jtsport
Difficulty 5/5 Over a week Newbie friendliness 35/100
peterstace/simplefeatures#700 ·
All issues in peterstace/simplefeatures
Similar issues
-
area: import bug go good first issue priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
fukubie/StockLlama#69 ·
-
enhancement help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloverworks-hq/rumpty-cli#95 ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 88/100
pulseaiclub/phi#615 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day