MarshalTWKB fails for Z or M geometries when the XY precision is negative
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
The defaults for the Z and M precisions are assigned in MarshalTWKB, which lives in the TWKB encoding code of the simplefeatures package. Start there, and check the validation message 'TWKB got precZ = -1, expected it to be between 0 and +7'. Reproduce with POINT Z (10 20 3) at precXY -1, then confirm the default falls to zero when precXY is negative. Done when that call succeeds and an explicit TWKBPrecisionZ(-1) is still rejected, with the doc comment updated to state the defaults.
Written by the indexing model from the issue text.
Description
MarshalTWKB returns an error for a geometry with Z or M when precXY is negative, unless the caller also passes TWKBPrecisionZ or TWKBPrecisionM. This reproduces on master at a5aec8d.
g, _ := geom.UnmarshalWKT("POINT Z (10 20 3)")
_, err := geom.MarshalTWKB(g, -1)
// TWKB got precZ = -1, expected it to be between 0 and +7
b, _ := geom.MarshalTWKB(g, -1, geom.TWKBPrecisionZ(0))
// b is 110801020406
A geometry with M fails the same way on precM. Empty geometries with Z or M fail too, although no coordinates are written for them.
Cause
The Z and M precisions default to precXY. The XY precision can be between -8 and +7, but the Z and M precisions have to be between 0 and +7, so a negative precXY gives a default that fails validation.
Likely fix
Default the Z and M precisions to zero when precXY is negative. Zero is the closest valid value, and it is the default for prec_z and prec_m in PostGIS's ST_AsTWKB. The defaults are assigned before the options are applied, so an explicit TWKBPrecisionZ(-1) would still be rejected.
The doc comment on MarshalTWKB doesn't say what the Z and M precisions default to, and the fix could add that.
Interaction with #723
Before #723, UnmarshalTWKB returned XY for some empty Z/M geometries, so the result could be passed back to MarshalTWKB at a negative precision. With #723 they keep Z and M and reach this error. For example, 131801 decodes as POLYGON Z EMPTY with #723 and as POLYGON EMPTY without it, and MarshalTWKB(g, -1) fails on the first.
- 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 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 ·
-
bug
Difficulty 3/5 Half a day Newbie friendliness 45/100
peterstace/simplefeatures#721 ·
-
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