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

Đang mở Phù hợp với người mới
#726 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, wasm
Lĩnh vực
backend

Hướng nghiên cứu

Giá trị mặc định cho độ chính xác của Z và M được gán trong MarshalTWKB, nằm trong mã mã hóa TWKB của gói simplefeatures. Hãy bắt đầu từ đó và kiểm tra thông báo xác thực 'TWKB got precZ = -1, expected it to be between 0 and +7'. Tái hiện bằng POINT Z (10 20 3) với precXY là -1, rồi xác nhận giá trị mặc định về không khi precXY là số âm. Hoàn thành khi lệnh gọi đó thành công, TWKBPrecisionZ(-1) tường minh vẫn bị từ chối, và comment tài liệu được cập nhật để nêu rõ các giá trị mặc định.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Go
Star
176
Fork
27
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của peterstace/simplefeatures

Tất cả issue của peterstace/simplefeatures

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.