Hello!
It seems that having multi-geometries in a GeometryCollection leads to some issues.
These are some simplified test cases to show the behaviour. They were tested using spatialite 5.0.1 with a Geopackage file opened.
The geometrycollection used is the following:
'GEOMETRYCOLLECTION (MULTIPOLYGON (((100.01 100, 100.01 110, 110 110, 110 100, 100.01 100)), ((20 20, 20 30, 21 30, 30 30, 30 20, 20 20), (22 22, 22 28, 28 28, 28 22, 22 22))), POLYGON ((100.01 100, 100.01 110, 110 110, 110 100, 100.01 100)))'
ST_GeomFromText()
When the geometrycollection is parsed using ST_GeomFromText(), the result is similar GeometryCollection, but the MultiPolygon is "flattened", which isn't ideal:
Sql statement:
SELECT ST_AsText(ST_GeomFromText('GEOMETRYCOLLECTION (MULTIPOLYGON (((100.01 100, 100.01 110, 110 110, 110 100, 100.01 100)), ((20 20, 20 30, 21 30, 30 30, 30 20, 20 20), (22 22, 22 28, 28 28, 28 22, 22 22))), POLYGON ((100.01 100, 100.01 110, 110 110, 110 100, 100.01 100)))')) AS geom;
Result:
GEOMETRYCOLLECTION (POLYGON ((100.01 100, 100.01 110, 110 110, 110 100, 100.01 100)), POLYGON ((20 20, 20 30, 21 30, 30 30, 30 20, 20 20), (22 22, 22 28, 28 28, 28 22, 22 22)), POLYGON ((100.01 100, 100.01 110, 110 110, 110 100, 100.01 100)))
ST_GeomFromWKB()
When the geometrycollection is parsed using ST_GeomFromWKB(), the result is a lot worse: a point
Sql statement:
SELECT ST_AsText(ST_GeomFromWKB(x'01070000000200000001060000000200000001030000000100000005000000713D0AD7A30059400000000000005940713D0AD7A30059400000000000805B400000000000805B400000000000805B400000000000805B400000000000005940713D0AD7A30059400000000000005940010300000002000000060000000000000000003440000000000000344000000000000034400000000000003E4000000000000035400000000000003E400000000000003E400000000000003E400000000000003E40000000000000344000000000000034400000000000003440050000000000000000003640000000000000364000000000000036400000000000003C400000000000003C400000000000003C400000000000003C4000000000000036400000000000003640000000000000364001030000000100000005000000713D0AD7A30059400000000000005940713D0AD7A30059400000000000805B400000000000805B400000000000805B400000000000805B400000000000005940713D0AD7A30059400000000000005940')) AS geom;
Result:
GEOMETRYCOLLECTION (POINT (0 0))
It would be great if this could be fixed.
Regards,
Pieter