h2gis icon indicating copy to clipboard operation
h2gis copied to clipboard

ST_MemSize

Open ebocher opened this issue 3 years ago • 5 comments

Implement ST_MemSize as PostGIS does to help people to know the memory size of the Geometry

https://postgis.net/docs/ST_MemSize.html

ebocher avatar Jan 14 '22 14:01 ebocher

Fixed.

ebocher avatar Jan 18 '22 11:01 ebocher

I think you should change argument of this function from Geometry to Value to avoid expensive conversion to Geometry and back and use its octetLength() method. Nulls are passed as ValueNull.INSTANCE in that case.

katzyn avatar Jan 18 '22 12:01 katzyn

Thanks

ebocher avatar Jan 18 '22 13:01 ebocher

So ST_MenSize will return the size of any value. Right ?

ebocher avatar Jan 18 '22 13:01 ebocher

You can check its type by yourself and throw an exception if it isn't a geometry, or you can force conversion to ValueGeometry:

return v == ValueNull.INSTANCE ? null : v.convertToGeometry(null).octetLength() + SOME_EXTRA_BYTES;

katzyn avatar Jan 18 '22 13:01 katzyn