uber / h3

Hexagonal hierarchical geospatial indexing system

Home Page:https://h3geo.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cellToChildren error

hello-willy opened this issue · comments

hi all:
when i use h3 lib, an error occur by call the api cellToChildren, my code as follow:

double lat = 123.7873877731234;
double lon = -23.7882992388383;

H3Index h6 = h3_latlng(lat, lon, 6);
H3Index h12 = h3_latlng(lat, lon, 12);

H3Index h12_1;
cellToChildren(h7, 12, &h12_1); // error occured!!!

H3 Version:4.1.0

i don't known why? Is there a problem with my writing style? plz help me, thank you very much!!!

1

This is not a correct call because cellToChildren expects the last argument to be an array, not a pointer to a single value. There are many child hexagons for the parent hexagon. You may need something like the following:

uint64_t h12_1_size;
H3Error sizeError = cellToChildrenSize(h7, 12, &h12_1_size);
if (!sizeError) {
    H3Index *h12_1 = calloc(h12_1_size, sizeof(H3Index));

    H3Error childrenError = cellToChildren(h7, 12, h12_1);
    if (!childrenError) {
        // use h12_1
    } else {
        // handle error
    }

    free(h12_1);
}
H3Index

thanks for your reply, it work! thank you!!!