uber / h3-py

Python bindings for H3, a hierarchical hexagonal geospatial indexing system
https://uber.github.io/h3-py
Apache License 2.0
815 stars 130 forks source link

v4: improve memory management tooling #249

Open ajfriend opened 2 years ago

ajfriend commented 2 years ago

I'd like a better Cython primitive for allocating, filling, and converting from an H3 index array to a Cython memview than our current approach of paired function calls to create_ptr and create_mv.

Example:

cpdef H3int[:] get_pentagon_indexes(int res):
    cdef:
        h3lib.H3Error err

    check_res(res)

    n = h3lib.pentagonCount()

    ptr = create_ptr(n)
    err = h3lib.getPentagons(res, ptr)
    mv = create_mv(ptr, n)

    return mv

Ideas:

Other kinds of arrays

This pattern also doesn't cover when we have to allocate space for non-H3Index arrays.

ajfriend commented 2 years ago

Another idea if this ends up being a Cython class: we could use the class to do handy things like removing H3_NULL values and freeing the extra memory, or canonicalizing the array.