Hello Sandro,
I'm not sure it this is the same, but I encountered a similar but possibly slightly different issue.
When running the following query in GDAL on an empty geometry the xmin returned is the max int value (1.7976931348623157e+308).
> SELECT ST_MinX(CastToXYZ(geom)) AS minx FROM "src_lyr"
However, when I run this query in plain SQLite + Spatialite this does return the expected NULL, so I'm not able to reproduce it "standalone".
The ~reason of this difference is that ST_MinX is implemented in GDAL as well..., so when I run this query using GDAL it is the GDAL version that takes precedence, and that version returns maxint.
Rouault looked into it, and apparently CastToXYZ returns odd data when ran on an empty geometry with EnableGpkgMode enabled.
Quote from Rouault: "It returns a GeoPackage header that with the Empty bit set to 0 (so a non-empty geometry) and the ExtentXY bit set (whereas the minx,miny,maxx,maxy are set to +/- DBL_MAX)"
He implemented a workaround in GDAL to catch this case, but it would be a lot better if this would be fixed at the source.
In the following geopackage fid=47 is an empty geometry:
Here a script that gives some info, but doesn't reproduce the problem ;-).
> -- Init
> SELECT load_extension('mod_spatialite');
> SELECT EnableGpkgMode();
>
> SELECT GeomFromText('GeometryCollection()');
>
> SELECT * FROM "parcels";
> -- Returns 16 which is a bit weird, but it isn't 0 so OK enough for me.
> SELECT ST_IsEmpty(geom) FROM "parcels" WHERE fid = 47;
> SELECT ST_NPoints(geom) FROM "parcels" WHERE fid = 47;
> -- Returns "GEOMETRYCOLLECTION()"
> SELECT ST_AsText(geom) FROM "parcels" WHERE fid = 47;
> -- Returns NULL in when ran in SQLITE, but apparently the data returned by CastToXYZ(geom)
> -- is pretty weird
> SELECT ST_MinX(CastToXYZ(geom)) FROM "parcels" WHERE fid = 47;
> -- I reported a crash on empty geometries in the beginning of 2024 which was fixed but hasn't
> -- been released yet... so this stil crashes.
> SELECT ST_ReducePrecision(geom, 0.001) FROM "parcels" WHERE fid = 47;
Regards,
Pieter