in src/apps/miscapps/h3ToGeoBoundaryHier.c [98:173]
int main(int argc, char *argv[]) {
int res;
H3Index parentIndex = 0;
Arg helpArg = ARG_HELP;
Arg resArg = {.names = {"-r", "--resolution"},
.scanFormat = "%d",
.valueName = "res",
.value = &res,
.helpText =
"Resolution, if less than the resolution of the parent "
"only the parent is printed. Default the resolution of "
"the parent."};
Arg parentArg = {
.names = {"-p", "--parent"},
.scanFormat = "%" PRIx64,
.valueName = "parent",
.value = &parentIndex,
.required = true,
.helpText = "Print cell boundaries descendent from this index."};
Arg kmlArg = ARG_KML;
DEFINE_KML_NAME_ARG(userKmlName, kmlNameArg);
DEFINE_KML_DESC_ARG(userKmlDesc, kmlDescArg);
Arg *args[] = {&helpArg, &resArg, &parentArg,
&kmlArg, &kmlNameArg, &kmlDescArg};
const int numArgs = 6;
const char *helpText = "Print cell boundaries for descendants of an index";
if (parseArgs(argc, argv, numArgs, args, &helpArg, helpText)) {
return helpArg.found ? 0 : 1;
}
if (res > MAX_H3_RES) {
printHelp(stderr, argv[0], helpText, numArgs, args,
"Resolution exceeds maximum resolution.", NULL);
return 1;
}
if (!H3_EXPORT(h3IsValid)(parentIndex)) {
printHelp(stderr, argv[0], helpText, numArgs, args,
"Parent index is invalid.", NULL);
return 1;
}
int rootRes = H3_GET_RESOLUTION(parentIndex);
if (kmlArg.found) {
char *kmlName;
if (kmlNameArg.found) {
kmlName = strdup(userKmlName);
} else {
kmlName = calloc(BUFF_SIZE, sizeof(char));
sprintf(kmlName, "Cell %" PRIx64 " Res %d", parentIndex,
((res <= rootRes) ? rootRes : res));
}
char *kmlDesc = "Generated by h3ToGeoBoundaryHier";
if (kmlDescArg.found) kmlDesc = userKmlDesc;
kmlBoundaryHeader(kmlName, kmlDesc);
free(kmlName);
}
// generate the points
if (res <= rootRes) {
doCell(parentIndex, kmlArg.found);
} else {
H3_SET_RESOLUTION(parentIndex, res);
recursiveH3IndexToGeo(parentIndex, rootRes + 1, kmlArg.found);
}
if (kmlArg.found) kmlBoundaryFooter();
}