Issues working with multi-geometries in GeometryCollection

67 views
Skip to first unread message

Pieter Roggemans

unread,
Sep 13, 2023, 8:57:33 AM9/13/23
to SpatiaLite Users
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

Alessandro Furieri

unread,
Sep 26, 2023, 3:34:52 AM9/26/23
to SpatiaLite Users
Hi Pieter,

I apologize for my late response.

First of all, a preliminary clarification is needed
to correctly understand the problem.
SpatiaLite's Geometry Collections are very particular,
and do not correspond exactly to the most usual standard.

In SpatiaLite a Collection is simply any arbitrary mix of
SinglaPart Geometries; MultiPart Geometries (as MultiPoint
or MultiPolygons) will always be resolved into their
individual members before being inserted into a Collection.

You may like it or not, but it's something profoundly
structural because this is precisely the binary BLOB
format of SpatiaLite Geometries.
Any attempt to change this area would simply mean
rewriting the entire code base from scratch.

-------------------

Moving on to your other questions.
It seems quite clear that the WKB parser fails to correctly
interpret the more complex Geometry Collections, and this
is definitely a bug that needs to be corrected.
I'll try to resolve this issue before releasing the next
version.

Thank you anyway for pointing out this critical issue which
had never emerged before in the first 15 years of life of
the project..

best regards,
Sandro

Pieter Roggemans

unread,
Sep 27, 2023, 5:54:03 PM9/27/23
to spatiali...@googlegroups.com
Hey Sandro,

Thanks for the background information. The GeometryCollection contents being flattened is not ideal, but definitely no deal breaker.

For the ST_GeomFromWKB, it would be great if that could be fixed. I'm flattening the geometries now in advance as a workaround, which works fine, but it took some time before I noticed that I got some wrong data results due to this... and wrong data results are always a bit of a pain.
For the bug never surfacing before, I suppose GeometryCollections just aren't that popular (luckily ;-))... 

Regards,
Pieter

a.fu...@lqt.it

unread,
Sep 29, 2023, 5:24:28 AM9/29/23
to spatiali...@googlegroups.com
On Wed, 27 Sep 2023 23:53:50 +0200, Pieter Roggemans wrote:
> For the ST_GeomFromWKB, it would be great if that could be fixed.
>

since my last commit in the source repository the problem has been
definitively solved; we now have a WKB parser perfectly aligned
with PostGIS

and the same applies to GeomFromEWKB as well

> For the bug never surfacing before, I suppose GeometryCollections
> just aren't that popular (luckily ;-))... 
>

certainly yes: but above all I believe that the WKB is used very
little for the exchange of geometries between different systems,
I am tempted to say that even today the obsolete but immortal
Shapefile remains the favorite

regards,
Sandro

Bart Bautista

unread,
May 7, 2024, 2:45:57 PMMay 7
to SpatiaLite Users
I accidentally closed the scripting window of Spatialite_Gui. How can I open it again. I cannot find the button to open it again. Please help.

a.fu...@lqt.it

unread,
May 8, 2024, 6:10:46 AMMay 8
to spatiali...@googlegroups.com
On Mon, 6 May 2024 18:08:09 -0700 (PDT), Bart Bautista wrote:
> I accidentally closed the scripting window of Spatialite_Gui. How can
> I open it again. I cannot find the button to open it again. Please
> help.
>

Hi Bart,

the layout of the various panels of the GUI (their size and
relative position) is permanently stored into the System
Registry, so that the last configuration is automatically
proposed again later.

unfortunately if something goes decidedly wrong (as seems
to have happened in your case) the only possible solution
is to directly change the System Registry.

It should be noted that this step is completely different
on Windows and Linux.

Windows
=================
- open the "regedit" system tool
- go to the <HKEY_CURRENT_USER> node and expand it
- then go to the <SOFTWARE> node and
expand it
- now you'll find a <SpatialiteGui>
node, where are stored all permanent settings for
this program
- completely delete the whole node.

the next time you'll open the GUI it will be as if a
brand new installation were carried out, and the default
configuration will therefore be automatically installed.
At this point everything should go back to normal as usual.


LINUX
================
- go to your Home Directory
- then execute the "ls -la" shell command
- you'll find an hidden file named .SpatialiteGui
here is stored the whole permanente configuration
of this program.
- just delete the whole file, as in
rm .SpatialiteGui

bye Sandro
Reply all
Reply to author
Forward
0 new messages