MarshalTWKB fails for Z or M geometries when the XY precision is negative

オープン 初心者向け
#726 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, wasm
領域
backend

調査の方向性

ZとMの精度のデフォルト値は、simplefeaturesパッケージのTWKBエンコードコードにあるMarshalTWKBで設定されています。まずそこから始め、検証メッセージ 'TWKB got precZ = -1, expected it to be between 0 and +7' を確認してください。precXYが-1の状態でPOINT Z (10 20 3) を使って再現し、precXYが負の場合にデフォルト値が0になることを確認してください。その呼び出しが成功し、明示的なTWKBPrecisionZ(-1)が引き続き拒否され、デフォルト値を示すようにdocコメントが更新されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug

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.

主要言語
Go
スター
176
フォーク
27
平均マージ
1日 14時間
マージ済み PR(30日)
4

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

peterstace/simplefeatures のほかの issue

peterstace/simplefeatures の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。