SFCValue support function

/*****************************************************************************
**
** Function name:
**
**      MyShapeSFCvalue
**
** Description:
**
**      This is an R-Tree support function which enables the
**      server to use a fast method of building an R-Tree index.
**
** Special Comments:
**
**      The SQL function signature for this function is
**      “SFCvalue (UDT, integer, pointer)”. This requires an explanation:
**
**      The purpose of the first argument is to provide function signature 
**      uniqueness, since you must declare a separate ObjectLength function
**      for each subtype in that can participate in the opclass. In reality
**      the server will pass an lvarchar containing an array of UDTs.
**
**      The second argument is an integer containing the size of the
**      arrays in the first and third arguments.
**
**      The third argument is declared to be an SQL pointer (i.e. void *);
**      in reality it is a pointer to an array of spatial keys. This
**      array is allocated for you by the server. The array element size
**      will be the size that you returned in the SFCbits support function.
**
** Parameters:
**
**      mi_lvarchar *objects     Array of UDTs, wrapped in an mi_lvarchar.
**      mi_integer  *array_size  Size of arrays.
**      void        *keys        Array of spatial keys to be computed.
**      MI_FPARAM   *fp          UDR function parameter & state info.
**
** Return value:
**
**      mi_integer               MI_OK if success, MI_ERROR if problems.
**
*****************************************************************************/

UDREXPORT mi_integer
MyShapeSFCvalue (mi_lvarchar *objects,
                 mi_integer   array_size,
                 void        *keys,
                 MI_FPARAM   *fp)
{
    mi_unsigned_integer  *key_ptr = (mi_unsigned_integer *) keys;
    mi_lvarchar **shape_array = (mi_lvarchar **) mi_get_vardata (objects);
    mi_integer  i;

    SHAPE_TRACE_ENTER (MyShapeSFCvalue);

    for (i = 0; i < array_size; i++)
    {
#ifdef USE_HILBERT_KEY
        Compute32BitHilbertKey (shape_array[i], &key_ptr[i]);
#else
        Compute32BitMortonKey (shape_array[i], &key_ptr[i]);
#endif
    }

    SHAPE_TRACE_EXIT (MyShapeSFCvalue);

    return MI_OK;
}

Copyright© 2019 HCL Technologies Limited