[postgis-devel] Questions about exposing `uint32_hilbert` API

Darafei "Komяpa" Praliaskouski me at komzpa.net
Sun Jun 20 05:35:07 PDT 2021


Hi,

On Sat, Jun 19, 2021 at 1:43 PM Han Wang <hanwgeek at gmail.com> wrote:

> Hi Darafei,
>
> Thanks for your answer!
> I thought about calling `gbox_get_sortable_hash
> <https://github.com/postgis/postgis/blob/main/liblwgeom/gbox.c#L893:1>`
> directly before. But the definition of the GiST op class
> <https://github.com/postgis/postgis/blob/main/postgis/postgis.sql.in#L781>,
> it seems that the GiST uses `*box2df*` as a simple representation of
> geometry types. And all of the other support functions accept `*BOX2DF*`
> datum for further process.
>
> Can you get the original datum to reuse it?
>>
> As of right now, I am unable to locate the API of getting the
> original `GSERIALIZED` datum. And I will pull the request after more
> research and some detailed tests.
>
> If you have any suggestions or questions, please let me know.
>

It seems that original gserialized is indeed inaccessible.

To make the float point Hilbert curve nice and smooth, you need to push
everything into a float point interval that does not have an exponent jump.
A nice one is 1..2, there are no float point anomalies in it and thus no
jitter. To not lose the lower bits, I've also previously rounded them up to
the closest power of 2 - that generally should translate to just making the
geometry fixed-point within the float-point data type.

To make the push effective, you need to know the bounds of all the input.
For standalone GSERIALIIZED, that will be a SRID which suggests a natural
interval from the planet's bounds.

For a set of records another option exists: you can measure that directly
on the dataset.
https://postgis.net/docs/ST_EstimatedExtent.html will prepare the thing for
you in advance.

So a nicer algorithm for building the index will be:
 - ANALYZE the relation (can we trigger that from inside CREATE INDEX if
not present already?)
 - precalculate the scales and offsets for the boxes and store them to some
shared structure (what can it be?)
 - sort the boxes using the adjusted scales.



>
> Best regards,
> Han
>
> On Sat, Jun 19, 2021 at 6:10 PM Darafei "Komяpa" Praliaskouski <
> me at komzpa.net> wrote:
>
>> Hello,
>>
>> There is already exposed gbox_get_sortable_hash. In that function the
>> SRID of geometry is also considered, as the generated Hilbert curve without
>> normalization is very jittery around lat=0 and lon=0 lines, so popular
>> SRIDs are special-cased.
>>
>> Can you get the original datum to reuse it?
>>
>> Otherwise, please expose whatever you need and get the pull request
>> posted somewhere (I like github). Whether to expose it or move around will
>> be best seen after you get something working on the flamegraph of the index
>> creation.
>>
>>
>> On Sat, Jun 19, 2021 at 11:29 AM Han Wang <hanwgeek at gmail.com> wrote:
>>
>>> HI all,
>>>
>>> Currently, I have to apply only the `*uint32_hilbert*
>>> <https://github.com/postgis/postgis/blob/b3874ecb488c3e04bcc26f701864a188788c472a/liblwgeom/gbox.c#L815>`
>>> to hash `*BOX2DF*` objects of geometry data. Would it be okay to
>>> include the `uint32_hilbert` function signature in the `liblwgeom.h` for
>>> the outside calls?
>>>
>>> Best regards,
>>> Han
>>> _______________________________________________
>>> postgis-devel mailing list
>>> postgis-devel at lists.osgeo.org
>>> https://lists.osgeo.org/mailman/listinfo/postgis-devel
>>>
>>
>>
>> --
>> Darafei "Komяpa" Praliaskouski
>> OSM BY Team - http://openstreetmap.by/
>> _______________________________________________
>> postgis-devel mailing list
>> postgis-devel at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/postgis-devel
>>
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-devel
>


-- 
Darafei "Komяpa" Praliaskouski
OSM BY Team - http://openstreetmap.by/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20210620/bd6530df/attachment.html>


More information about the postgis-devel mailing list