int main(int argc, char* argv[]) { // check command line args if (argc != 2) { fprintf(stderr, "usage: %s [k]\n", argv[0]); exit(1); } int k = 0; if (argc > 1) { if (!sscanf(argv[1], "%d", &k)) error("k must be an integer"); } // process the indexes on stdin char buff[BUFF_SIZE]; while (1) { // get an index from stdin if (!fgets(buff, BUFF_SIZE, stdin)) { if (feof(stdin)) break; else error("reading H3 index from stdin"); } H3Index h3 = H3_EXPORT(stringToH3)(buff); doCell(h3, k); } }
int main(int argc, char* argv[]) { // check command line args if (argc < 2 || argc > 5) { fprintf(stderr, "usage: %s H3Index [resolution outputMode]\n", argv[0]); exit(1); } H3Index rootCell = H3_EXPORT(stringToH3)(argv[1]); int baseCell = H3_GET_BASE_CELL(rootCell); int rootRes = H3_GET_RESOLUTION(rootCell); if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) { error("invalid base cell number"); } int res = 0; int isKmlOut = 0; if (argc > 2) { if (!sscanf(argv[2], "%d", &res)) error("resolution must be an integer"); if (res > MAX_H3_RES) error("specified resolution exceeds max resolution"); if (argc > 3) { if (!sscanf(argv[3], "%d", &isKmlOut)) error("outputMode must be an integer"); if (isKmlOut != 0 && isKmlOut != 1) error("outputMode must be 0 or 1"); if (isKmlOut) { char index[BUFF_SIZE]; char name[BUFF_SIZE]; char desc[BUFF_SIZE]; H3_EXPORT(h3ToString)(rootCell, index, BUFF_SIZE); sprintf(name, "Cell %s Res %d", index, ((res <= rootRes) ? rootRes : res)); sprintf(desc, "cell boundary"); kmlBoundaryHeader(name, desc); } } } // generate the points if (res <= rootRes) { doCell(rootCell, isKmlOut); } else { H3_SET_RESOLUTION(rootCell, res); recursiveH3IndexToGeo(rootCell, rootRes + 1, isKmlOut); } if (isKmlOut) kmlBoundaryFooter(); }
void Fixture::doCells(Parse *cells) { for (int i = 0; cells != 0; ++i) { try { doCell(cells, i); } catch (const std::exception &e) { exception(cells, e); } cells = cells->more; } }
void recursiveH3IndexToGeo(H3Index h, int res, int isKmlOut) { for (int d = 0; d < 7; d++) { H3_SET_INDEX_DIGIT(h, res, d); // skip the pentagonal deleted subsequence if (_isBaseCellPentagon(H3_GET_BASE_CELL(h)) && _h3LeadingNonZeroDigit(h) == 1) { continue; } if (res == H3_GET_RESOLUTION(h)) { doCell(h, isKmlOut); } else { recursiveH3IndexToGeo(h, res + 1, isKmlOut); } } }