uber / h3

Hexagonal hierarchical geospatial indexing system
https://h3geo.org
Apache License 2.0
4.92k stars 468 forks source link

cellToChildren error #807

Closed hello-willy closed 10 months ago

hello-willy commented 10 months ago

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

isaacbrodsky commented 10 months ago

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);
}
hello-willy commented 10 months ago
H3Index

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