You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MarshalTWKB fails for Z or M geometries when the XY precision is negative #726
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 +7b, _:=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.
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.
Activity