ST_Reduceprecision crash on EMPTY geometry in Geopackage

67 views
Skip to first unread message

Pieter Roggemans

unread,
Jan 25, 2024, 6:13:04 AMJan 25
to SpatiaLite Users
Hello there!

When ST_ReducePrecision is ran on an EMPTY geometry in a Geopackage a crash occurs.

Other functions I tested work fine with it.

I'm using this construction now as a workaround, but a fix would be nicer :-)...
    IIF(geom IS NULL OR ST_IsEmpty(geom) <> 0, NULL, ST_ReducePrecision(geom, 0.001))


Eg.:

-- Init

SELECT load_extension('mod_spatialite');

SELECT EnableGpkgMode();


SELECT * FROM "130_diss_bufp_diss_bufm";

-- Returns 16 which is a bit weird, but it isn't 0 so OK enough for me.

SELECT ST_IsEmpty(geom) FROM "130_diss_bufp_diss_bufm";

SELECT ST_NPoints(geom) FROM "130_diss_bufp_diss_bufm";

-- Returns "GEOMETRYCOLLECTION()"

SELECT ST_AsText(geom) FROM "130_diss_bufp_diss_bufm";

SELECT ST_Intersection(geom, ST_Point(0, 1)) FROM "130_diss_bufp_diss_bufm";

SELECT ST_Buffer(geom, 1) FROM "130_diss_bufp_diss_bufm";

-- Crash!

SELECT ST_ReducePrecision(geom, 0.001) FROM "130_diss_bufp_diss_bufm";


Regards,

Pieter

Pieter Roggemans

unread,
Feb 20, 2024, 11:52:28 AMFeb 20
to SpatiaLite Users
GEOSMakeValid seems to have the same issue...

Op donderdag 25 januari 2024 om 12:13:04 UTC+1 schreef Pieter Roggemans:

a.fu...@lqt.it

unread,
Feb 26, 2024, 4:13:05 AMFeb 26
to spatiali...@googlegroups.com
On Tue, 20 Feb 2024 08:52:27 -0800 (PST), Pieter Roggemans wrote:
> GEOSMakeValid seems to have the same issue...
>
>> When ST_ReducePrecision is ran on an EMPTY geometry in a Geopackage
>> a crash occurs.
>

Hi Pieter,

there is nothing wrong with ST_ReducePrecision() or
GeosMakeValid()

The real cause of the crashes is a bug present in the
routine that converts the BLOB geometries from the
GPKG format to the SpatiaLite's one.

In more detail; GPKG geometries not supported by
SpatiaLite (typically, Empty Geometries) were
wrongly translated into a completely empty
GeometryCollection without even a single element.
But a geometry of this type is completely illegal
in SpatiaLite and must be represented as NULL.

Counterproof:
SELECT GeomFromText('GeometryCollection()');
NULL

Conclusion: the bug affecting the translation
of GPKG geometries can easily cause crashes in
practically all SpatiaLite functions accepting
an argument of the Geometry type.

Solution: the patch that solves the problem has
already been committed into the Fossil repository.

bye Sandro

Pieter Roggemans

unread,
Feb 27, 2024, 9:29:40 AMFeb 27
to SpatiaLite Users
Hmm... odd, I had tested some other functions and they seemed not to give the crash, but I must have done something wrong.

Thanks for fixing it!

Regards,
Pieter

Op maandag 26 februari 2024 om 10:13:05 UTC+1 schreef a.fu...@lqt.it:
Reply all
Reply to author
Forward
0 new messages