TWKB / Specification

An effort to come up with a compressed binary vector geometry specification
86 stars 10 forks source link

Clarify the scope of delta values for geometries in a GeometryCollection #23

Closed airbreather closed 4 years ago

airbreather commented 4 years ago

https://github.com/TWKB/Specification/blob/351dd1e1de0629a9dc2e49dab26bf70faea93b8c/twkb.md#calculate-delta-values says this:

Every coordinate value in a geometry except the very first one is a delta value relative to the previous value processed.

https://github.com/TWKB/Specification/blob/351dd1e1de0629a9dc2e49dab26bf70faea93b8c/twkb.md#geometrycollection-type-7 says this:

  • for each geometry there will be a complete TWKB geometry, readable using the rules set out above

This creates an apparent ambiguity: if a GeometryCollection contains a Polygon followed by a Linestring, then is the first coordinate of the Linestring treated as:

nicklasaven commented 4 years ago

I see your point

This was also discussed when we designed the format.

The result was that the subgeometries in a geomoetrycollection is "complete twkb geometries". In other words, each subgeometry has it's own absolute starting value.

But for multigeometries like multipoint, multiline and multipolygon it is only one absolute value in the beginning.

This can be seen in the PostGIS-implementation:

SELECT 
length(
   st_astwkb(
      'multipoint((1000000 1000000),(1000001 1000001))'::geometry
      )
   )

which gives a twkb length of 11 bytes while the corresponding geoemtry collection:

SELECT 
length(
   st_astwkb(
      'geometrycollection(point(1000000 1000000),point(1000001 1000001))'::geometry
      )
   )

gives a twkb-length of 19 bytes.

The reason was if I recall correct mostly was that it is easier to implement this way. When creating or reading a geometry-collection it just iterates a bunch of geometries that is complete. The function for reading a polygon from a geometrycollection is the same as the function reading a plain polygon.

I have added a note in the specification to clearify. Does this help?

airbreather commented 4 years ago

I have added a note in the specification to clearify. Does this help?

Yes, thanks for the clarification. Closing.