MarshalTWKB writes incorrect output for empty geometries

Aperta
#721 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

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.

Lingua principale
Go
Stelle
176
Fork
27
Merge medio
1g 14h
PR unite (30g)
4

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di peterstace/simplefeatures

Tutte le issue di peterstace/simplefeatures

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.