From cae83f46abbc3cabf2dddfcdb941ac11b8e65d5b Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 17 Oct 2024 00:43:28 -0500 Subject: [PATCH 1/5] Update the cli output to be controllable, when possible, and always produce JSON-compliant output by default --- src/apps/filters/h3.c | 1012 ++++++++++++++++------ tests/cli/cellToBoundary.txt | 2 +- tests/cli/cellToCenterChild.txt | 2 +- tests/cli/cellToLatLng.txt | 2 +- tests/cli/cellToParent.txt | 2 +- tests/cli/cellToVertex.txt | 2 +- tests/cli/cellToVertexes.txt | 2 +- tests/cli/cellsToDirectedEdge.txt | 2 +- tests/cli/cellsToMultiPolygon.txt | 20 +- tests/cli/childPosToCell.txt | 2 +- tests/cli/compactCells.txt | 18 +- tests/cli/directedEdgeToBoundary.txt | 2 +- tests/cli/getDirectedEdgeDestination.txt | 2 +- tests/cli/getDirectedEdgeOrigin.txt | 2 +- tests/cli/getIcosahedronFaces.txt | 2 +- tests/cli/getPentagons.txt | 2 +- tests/cli/getRes0Cells.txt | 2 +- tests/cli/gridDiskDistances.txt | 2 +- tests/cli/latLngToCell.txt | 2 +- tests/cli/localIjToCell.txt | 2 +- tests/cli/maxPolygonToCellsSize.txt | 12 +- tests/cli/polygonToCells.txt | 16 +- tests/cli/uncompactCells.txt | 18 +- tests/cli/vertexToLatLng.txt | 2 +- 24 files changed, 808 insertions(+), 324 deletions(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index ac03f2459..fc767447a 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -113,11 +113,22 @@ bool has(char *subcommand, int level, char *argv[]) { Arg helpArg = ARG_HELP; +#define DEFINE_FORMAT_ARG(desc) \ + char format[8] = {0}; \ + Arg formatArg = {.names = {"-f", "--format"}, \ + .scanFormat = "%s", \ + .value = format, \ + .valueName = "FMT", \ + .helpText = desc} + /// Indexing subcommands -SUBCOMMAND(cellToLatLng, "Convert an H3Cell to a WKT POINT coordinate") { +SUBCOMMAND(cellToLatLng, "Convert an H3Cell to a coordinate") { + DEFINE_FORMAT_ARG( + "'json' for [lat, lng], 'wkt' for a WKT POINT, 'newline' for " + "lat\\nlng\\n (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&cellToLatLngArg, &helpArg, &cellArg}; + Arg *args[] = {&cellToLatLngArg, &helpArg, &cellArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); LatLng ll; int valid = H3_EXPORT(isValidCell)(cell); @@ -128,15 +139,28 @@ SUBCOMMAND(cellToLatLng, "Convert an H3Cell to a WKT POINT coordinate") { if (err) { return err; } - // Using WKT formatting for the output. TODO: Add support for JSON - // formatting - printf("POINT(%.10lf %.10lf)\n", H3_EXPORT(radsToDegs)(ll.lng), - H3_EXPORT(radsToDegs)(ll.lat)); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("[%.10lf, %.10lf]\n", H3_EXPORT(radsToDegs)(ll.lat), + H3_EXPORT(radsToDegs)(ll.lng)); + } else if (strcmp(format, "wkt") == 0) { + // Using WKT formatting for the output. TODO: Add support for JSON + // formatting + printf("POINT(%.10lf %.10lf)\n", H3_EXPORT(radsToDegs)(ll.lng), + H3_EXPORT(radsToDegs)(ll.lat)); + } else if (strcmp(format, "newline") == 0) { + printf("%.10lf\n%.10lf\n", H3_EXPORT(radsToDegs)(ll.lat), + H3_EXPORT(radsToDegs)(ll.lng)); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(latLngToCell, "Convert degrees latitude/longitude coordinate to an H3 cell") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n " + "(Default: json)"); int res = 0; double lat = 0; double lng = 0; @@ -160,28 +184,35 @@ SUBCOMMAND(latLngToCell, .value = &lng, .helpText = "Longitude in degrees."}; - Arg *args[] = {&latLngToCellArg, &helpArg, &resArg, &latArg, &lngArg}; + Arg *args[] = {&latLngToCellArg, &helpArg, &resArg, + &latArg, &lngArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); LatLng ll = {.lat = H3_EXPORT(degsToRads)(lat), .lng = H3_EXPORT(degsToRads)(lng)}; H3Index c; - H3Error e = H3_EXPORT(latLngToCell)(&ll, res, &c); + H3Error err = H3_EXPORT(latLngToCell)(&ll, res, &c); + if (err) { + return err; + } - // TODO: Add support for JSON formatting - if (e == E_SUCCESS) { + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", c); + } else if (strcmp(format, "newline") == 0) { h3Println(c); } else { - h3Println( - H3_NULL); // TODO: Should we print a better error message here? + return E_FAILED; } - return e; + return E_SUCCESS; } SUBCOMMAND(cellToBoundary, - "Convert an H3 cell to a WKT POLYGON defining its boundary") { + "Convert an H3 cell to a polygon defining its boundary") { + DEFINE_FORMAT_ARG( + "'json' for [[lat, lng], ...], 'wkt' for a WKT POLYGON, 'newline' for " + "lat\\nlng\\n... (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&cellToBoundaryArg, &helpArg, &cellArg}; + Arg *args[] = {&cellToBoundaryArg, &helpArg, &cellArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); CellBoundary cb; int valid = H3_EXPORT(isValidCell)(cell); @@ -192,17 +223,35 @@ SUBCOMMAND(cellToBoundary, if (err) { return err; } - // Using WKT formatting for the output. TODO: Add support for JSON - // formatting - printf("POLYGON(("); - for (int i = 0; i < cb.numVerts; i++) { - LatLng *ll = &cb.verts[i]; - printf("%.10lf %.10lf, ", H3_EXPORT(radsToDegs)(ll->lng), - H3_EXPORT(radsToDegs)(ll->lat)); - } - // WKT has the first and last points match, so re-print the first one - printf("%.10lf %.10lf))\n", H3_EXPORT(radsToDegs)(cb.verts[0].lng), - H3_EXPORT(radsToDegs)(cb.verts[0].lat)); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("["); + for (int i = 0; i < cb.numVerts - 1; i++) { + LatLng *ll = &cb.verts[i]; + printf("[%.10lf, %.10lf], ", H3_EXPORT(radsToDegs)(ll->lat), + H3_EXPORT(radsToDegs)(ll->lng)); + } + printf("[%.10lf, %.10lf]]\n", + H3_EXPORT(radsToDegs)(cb.verts[cb.numVerts - 1].lat), + H3_EXPORT(radsToDegs)(cb.verts[cb.numVerts - 1].lng)); + } else if (strcmp(format, "wkt") == 0) { + printf("POLYGON(("); + for (int i = 0; i < cb.numVerts; i++) { + LatLng *ll = &cb.verts[i]; + printf("%.10lf %.10lf, ", H3_EXPORT(radsToDegs)(ll->lng), + H3_EXPORT(radsToDegs)(ll->lat)); + } + // WKT has the first and last points match, so re-print the first one + printf("%.10lf %.10lf))\n", H3_EXPORT(radsToDegs)(cb.verts[0].lng), + H3_EXPORT(radsToDegs)(cb.verts[0].lat)); + } else if (strcmp(format, "newline") == 0) { + for (int i = 0; i < cb.numVerts; i++) { + LatLng *ll = &cb.verts[i]; + printf("%.10lf\n%.10lf\n", H3_EXPORT(radsToDegs)(ll->lat), + H3_EXPORT(radsToDegs)(ll->lng)); + } + } else { + return E_FAILED; + } return E_SUCCESS; } @@ -287,18 +336,28 @@ SUBCOMMAND(intToString, "Converts an H3 index in int form to string form") { } SUBCOMMAND(isValidCell, "Checks if the provided H3 index is actually valid") { + DEFINE_FORMAT_ARG( + "'json' for true or false, 'numeric' for 1 or 0 (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&isValidCellArg, &helpArg, &cellArg}; + Arg *args[] = {&isValidCellArg, &helpArg, &cellArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); bool isValid = H3_EXPORT(isValidCell)(cell); - printf("%s\n", isValid ? "true" : "false"); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("%s\n", isValid ? "true" : "false"); + } else if (strcmp(format, "numeric") == 0) { + printf("%d\n", isValid); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(isResClassIII, "Checks if the provided H3 index has a Class III orientation") { + DEFINE_FORMAT_ARG( + "'json' for true or false, 'numeric' for 1 or 0 (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&isResClassIIIArg, &helpArg, &cellArg}; + Arg *args[] = {&isResClassIIIArg, &helpArg, &cellArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); // TODO: Should there be a general `isValidIndex`? H3Error cellErr = H3_EXPORT(isValidCell)(cell); @@ -311,15 +370,23 @@ SUBCOMMAND(isResClassIII, // few functions that doesn't do any error handling (for some reason? I // don't see how this would ever be in a hot loop anywhere. bool isClassIII = H3_EXPORT(isResClassIII)(cell); - printf("%s\n", isClassIII ? "true" : "false"); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("%s\n", isClassIII ? "true" : "false"); + } else if (strcmp(format, "numeric") == 0) { + printf("%d\n", isClassIII); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND( isPentagon, "Checks if the provided H3 index is a pentagon instead of a hexagon") { + DEFINE_FORMAT_ARG( + "'json' for true or false, 'numeric' for 1 or 0 (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&isPentagonArg, &helpArg, &cellArg}; + Arg *args[] = {&isPentagonArg, &helpArg, &cellArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); // TODO: Should there be a general `isValidIndex`? H3Error cellErr = H3_EXPORT(isValidCell)(cell); @@ -332,15 +399,24 @@ SUBCOMMAND( // few functions that doesn't do any error handling (for some reason? I // don't see how this would ever be in a hot loop anywhere. bool is = H3_EXPORT(isPentagon)(cell); - printf("%s\n", is ? "true" : "false"); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("%s\n", is ? "true" : "false"); + } else if (strcmp(format, "numeric") == 0) { + printf("%d\n", is); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(getIcosahedronFaces, "Returns the icosahedron face numbers (0 - 19) that the H3 index " "intersects") { + DEFINE_FORMAT_ARG( + "'json' for [faceNum, ...], 'newline' for faceNum\\n... (Default: " + "json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&getIcosahedronFacesArg, &helpArg, &cellArg}; + Arg *args[] = {&getIcosahedronFacesArg, &helpArg, &cellArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); int faceCount; H3Error err = H3_EXPORT(maxFaceCount)(cell, &faceCount); @@ -357,23 +433,35 @@ SUBCOMMAND(getIcosahedronFaces, free(faces); return err; } - bool hasPrinted = false; - for (int i = 0; i < faceCount - 1; i++) { - if (faces[i] != -1) { + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + bool hasPrinted = false; + printf("["); + for (int i = 0; i < faceCount - 1; i++) { + if (faces[i] != -1) { + if (hasPrinted) { + printf(", "); + } + printf("%i", faces[i]); + hasPrinted = true; + } + } + if (faces[faceCount - 1] != -1) { if (hasPrinted) { printf(", "); } - printf("%i", faces[i]); - hasPrinted = true; + printf("%i", faces[faceCount - 1]); } - } - if (faces[faceCount - 1] != -1) { - if (hasPrinted) { - printf(", "); + printf("]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int i = 0; i < faceCount; i++) { + if (faces[i] != -1) { + printf("%i\n", faces[i]); + } } - printf("%i", faces[faceCount - 1]); + } else { + free(faces); + return E_FAILED; } - printf("\n"); free(faces); return E_SUCCESS; } @@ -382,7 +470,9 @@ SUBCOMMAND(getIcosahedronFaces, SUBCOMMAND( gridDisk, - "Returns a JSON array of a H3 cells within 'k' steps of the origin cell") { + "Returns an array of a H3 cells within 'k' steps of the origin cell") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); int k = 0; Arg kArg = {.names = {"-k"}, @@ -391,7 +481,7 @@ SUBCOMMAND( .valueName = "distance", .value = &k, .helpText = "Maximum grid distance for the output set"}; - Arg *args[] = {&gridDiskArg, &helpArg, &cellArg, &kArg}; + Arg *args[] = {&gridDiskArg, &helpArg, &cellArg, &kArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); int64_t len = 0; H3Error err = H3_EXPORT(maxGridDiskSize)(k, &len); @@ -408,31 +498,47 @@ SUBCOMMAND( free(out); return err; } - // Since we don't know *actually* how many cells are in the output (usually - // the max, but sometimes not), we need to do a quick scan to figure out the - // true length in order to properly serialize to a JSON array - int64_t trueLen = 0; - for (int64_t i = 0; i < len; i++) { - if (out[i] != 0) { - trueLen++; + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Since we don't know *actually* how many cells are in the output + // (usually the max, but sometimes not), we need to do a quick scan to + // figure out the true length in order to properly serialize to a JSON + // array + int64_t trueLen = 0; + for (int64_t i = 0; i < len; i++) { + if (out[i] != 0) { + trueLen++; + } } - } - printf("[ "); - for (int64_t i = 0, j = 0; i < len; i++) { - if (out[i] != 0) { - j++; - printf("\"%" PRIx64 "\"%s", out[i], j == trueLen ? "" : ", "); + printf("[ "); + for (int64_t i = 0, j = 0; i < len; i++) { + if (out[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", out[i], j == trueLen ? "" : ", "); + } } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < len; i++) { + if (out[i] != 0) { + h3Println(out[i]); + } + } + } else { + free(out); + return E_FAILED; } + free(out); - printf(" ]\n"); return E_SUCCESS; } SUBCOMMAND( gridDiskDistances, - "Returns a JSON array of arrays of H3 cells, each array containing cells " + "Returns an array of arrays of H3 cells, each array containing cells " "'k' steps away from the origin cell, based on the outer array index") { + DEFINE_FORMAT_ARG( + "'json' for [[\"CELL\", ...], ...], 'newline' for CELL\\n with an " + "extra newline between rings (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); int k = 0; Arg kArg = {.names = {"-k"}, @@ -441,15 +547,9 @@ SUBCOMMAND( .valueName = "distance", .value = &k, .helpText = "Maximum grid distance for the output set"}; - Arg prettyArg = { - .names = {"-p", "--pretty-print"}, - .required = false, - .helpText = - "Determine if the JSON output should be pretty printed or not"}; Arg *args[] = {&gridDiskDistancesArg, &helpArg, &cellArg, &kArg, - &prettyArg}; + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); - bool pretty = prettyArg.found; int64_t len = 0; H3Error err = H3_EXPORT(maxGridDiskSize)(k, &len); if (err) { @@ -471,55 +571,67 @@ SUBCOMMAND( free(distances); return err; } - // Man, I wish JSON allowed trailing commas - printf("[%s", pretty ? "\n" : ""); - for (int i = 0; i <= k; i++) { - printf("%s[%s", /* prefix */ pretty ? " " : "", - /* suffix */ pretty ? "\n" : ""); - // We need to figure out how many cells are in each ring. Because of - // pentagons, we can't hardwire this, unfortunately - int count = 0; - for (int j = 0; j < len; j++) { - if (distances[j] == i && out[j] != 0) { - count++; + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Man, I wish JSON allowed trailing commas + printf("["); + for (int i = 0; i <= k; i++) { + printf("["); + // We need to figure out how many cells are in each ring. Because of + // pentagons, we can't hardwire this, unfortunately + int count = 0; + for (int j = 0; j < len; j++) { + if (distances[j] == i && out[j] != 0) { + count++; + } } - } - // On the second loop, we output cells with a comma except for the last - // one, which we now know - int cellNum = 0; - for (int j = 0; j < len; j++) { - if (distances[j] == i && out[j] != 0) { - cellNum++; - printf("%s\"%" PRIx64 "\"", pretty ? " " : "", out[j]); - if (cellNum == count) { - if (pretty) { - printf("\n"); + // On the second loop, we output cells with a comma except for the + // last one, which we now know + int cellNum = 0; + for (int j = 0; j < len; j++) { + if (distances[j] == i && out[j] != 0) { + cellNum++; + printf("\"%" PRIx64 "\"", out[j]); + if (cellNum != count) { + printf(", "); } - } else { - printf(",%s", pretty ? "\n" : ""); } } + // Similarly, we need to check which iteration of the outer array + // we're on and include a comma or not + if (i == k) { + printf("]"); + } else { + printf("], "); + } } - // Similarly, we need to check which iteration of the outer array we're - // on and include a comma or not - if (i == k) { - printf("%s]%s", /* prefix */ pretty ? " " : "", - /* suffix */ pretty ? "\n" : ""); - } else { - printf("%s],%s", /* prefix */ pretty ? " " : "", - /* suffix */ pretty ? "\n" : ""); + printf("]\n"); // Always print the newline here so the terminal prompt + // gets its own line + } else if (strcmp(format, "newline") == 0) { + for (int i = 0; i <= k; i++) { + for (int j = 0; j < len; j++) { + if (distances[j] == i && out[j] != 0) { + h3Println(out[j]); + } + } + if (i < k) { + printf("\n"); + } } + } else { + free(out); + free(distances); + return E_FAILED; } - printf("]\n"); // Always print the newline here so the terminal prompt gets - // its own line free(out); free(distances); return E_SUCCESS; } SUBCOMMAND(gridRing, - "Returns a JSON array of H3 cells, each cell 'k' steps away from " + "Returns an array of H3 cells, each cell 'k' steps away from " "the origin cell") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); int k = 0; Arg kArg = {.names = {"-k"}, @@ -528,7 +640,7 @@ SUBCOMMAND(gridRing, .valueName = "distance", .value = &k, .helpText = "Maximum grid distance for the output set"}; - Arg *args[] = {&gridRingArg, &helpArg, &cellArg, &kArg}; + Arg *args[] = {&gridRingArg, &helpArg, &cellArg, &kArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); int64_t len = k == 0 ? 1 : 6 * k; // The length is fixed for gridRingUnsafe // since it doesn't support pentagons @@ -592,20 +704,31 @@ SUBCOMMAND(gridRing, free(distances); } // Now that we have the correct data, however we got it, we can print it out - printf("[ \"%" PRIx64 "\"", out[0]); - for (int64_t i = 1; i < len; i++) { - if (out[i] != 0) { - printf(", \"%" PRIx64 "\"", out[i]); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("[ \"%" PRIx64 "\"", out[0]); + for (int64_t i = 1; i < len; i++) { + if (out[i] != 0) { + printf(", \"%" PRIx64 "\"", out[i]); + } + } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < len; i++) { + h3Println(out[i]); } + } else { + free(out); + return E_FAILED; } free(out); - printf(" ]\n"); return E_SUCCESS; } SUBCOMMAND(gridPathCells, - "Returns a JSON array of H3 cells from the origin cell to the " + "Returns an array of H3 cells from the origin cell to the " "destination cell (inclusive)") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); H3Index origin = 0; Arg originArg = {.names = {"-o", "--origin"}, .required = true, @@ -620,7 +743,8 @@ SUBCOMMAND(gridPathCells, .valueName = "cell", .value = &destination, .helpText = "The destination H3 cell"}; - Arg *args[] = {&gridPathCellsArg, &helpArg, &originArg, &destinationArg}; + Arg *args[] = {&gridPathCellsArg, &helpArg, &originArg, &destinationArg, + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); int64_t len = 0; H3Error err = H3_EXPORT(gridPathCellsSize)(origin, destination, &len); @@ -637,14 +761,23 @@ SUBCOMMAND(gridPathCells, free(out); return err; } - printf("[ \"%" PRIx64 "\"", out[0]); - for (int64_t i = 1; i < len; i++) { - if (out[i] != 0) { - printf(", \"%" PRIx64 "\"", out[i]); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("[ \"%" PRIx64 "\"", out[0]); + for (int64_t i = 1; i < len; i++) { + if (out[i] != 0) { + printf(", \"%" PRIx64 "\"", out[i]); + } + } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < len; i++) { + h3Println(out[i]); } + } else { + free(out); + return E_FAILED; } free(out); - printf(" ]\n"); return E_SUCCESS; } @@ -678,6 +811,8 @@ SUBCOMMAND(gridDistance, SUBCOMMAND(cellToLocalIj, "Returns the IJ coordinate for a cell anchored to an origin cell") { + DEFINE_FORMAT_ARG( + "'json' for [I, J], 'newline' for I\\nJ\\n (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); H3Index origin = 0; Arg originArg = {.names = {"-o", "--origin"}, @@ -686,20 +821,29 @@ SUBCOMMAND(cellToLocalIj, .valueName = "cell", .value = &origin, .helpText = "The origin H3 cell"}; - Arg *args[] = {&cellToLocalIjArg, &helpArg, &cellArg, &originArg}; + Arg *args[] = {&cellToLocalIjArg, &helpArg, &cellArg, &originArg, + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); CoordIJ out = {0}; H3Error err = H3_EXPORT(cellToLocalIj)(origin, cell, 0, &out); if (err) { return err; } - printf("[%i, %i]\n", out.i, out.j); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("[%i, %i]\n", out.i, out.j); + } else if (strcmp(format, "newline") == 0) { + printf("%i\n%i\n", out.i, out.j); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(localIjToCell, "Returns the H3 index from a local IJ coordinate anchored to an " "origin cell") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n (Default: json)"); H3Index origin = 0; Arg originArg = {.names = {"-o", "--origin"}, .required = true, @@ -720,7 +864,8 @@ SUBCOMMAND(localIjToCell, .valueName = "j", .value = &j, .helpText = "The J dimension of the IJ coordinate"}; - Arg *args[] = {&localIjToCellArg, &helpArg, &originArg, &iArg, &jArg}; + Arg *args[] = {&localIjToCellArg, &helpArg, &originArg, &iArg, &jArg, + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); CoordIJ in = {.i = i, .j = j}; H3Index out = 0; @@ -728,7 +873,13 @@ SUBCOMMAND(localIjToCell, if (err) { return err; } - h3Println(out); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", out); + } else if (strcmp(format, "newline") == 0) { + h3Println(out); + } else { + return E_FAILED; + } return E_SUCCESS; } @@ -737,6 +888,8 @@ SUBCOMMAND(localIjToCell, SUBCOMMAND(cellToParent, "Returns the H3 index that is the parent (or higher) of the " "provided cell") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); int res = 0; Arg resArg = {.names = {"-r", "--resolution"}, @@ -747,7 +900,7 @@ SUBCOMMAND(cellToParent, .helpText = "Resolution, 0-14 inclusive, excluding 15 as it can " "never be a parent"}; - Arg *args[] = {&cellToParentArg, &helpArg, &cellArg, &resArg}; + Arg *args[] = {&cellToParentArg, &helpArg, &cellArg, &resArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index parent; int valid = H3_EXPORT(isValidCell)(cell); @@ -758,15 +911,23 @@ SUBCOMMAND(cellToParent, if (err) { return err; } - h3Println(parent); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", parent); + } else if (strcmp(format, "newline") == 0) { + h3Println(parent); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(cellToChildren, - "Returns a JSON array of H3 indexes that are the children (or " + "Returns an array of H3 indexes that are the children (or " "lower) of the provided cell") { // TODO: This function contains a lot of code that is very similar to // `gridDisk`. If this happens again we should DRY them. + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); int res = 0; Arg resArg = {.names = {"-r", "--resolution"}, @@ -777,7 +938,7 @@ SUBCOMMAND(cellToChildren, .helpText = "Resolution, 1-15 inclusive, excluding 0 as it can " "never be a child"}; - Arg *args[] = {&cellToChildrenArg, &helpArg, &cellArg, &resArg}; + Arg *args[] = {&cellToChildrenArg, &helpArg, &cellArg, &resArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); int64_t len = 0; H3Error err = H3_EXPORT(cellToChildrenSize)(cell, res, &len); @@ -794,24 +955,37 @@ SUBCOMMAND(cellToChildren, free(out); return err; } - // Since we don't know *actually* how many cells are in the output (usually - // the max, but sometimes not), we need to do a quick scan to figure out the - // true length in order to properly serialize to a JSON array - int64_t trueLen = 0; - for (int64_t i = 0; i < len; i++) { - if (out[i] != 0) { - trueLen++; + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Since we don't know *actually* how many cells are in the output + // (usually the max, but sometimes not), we need to do a quick scan to + // figure out the true length in order to properly serialize to a JSON + // array + int64_t trueLen = 0; + for (int64_t i = 0; i < len; i++) { + if (out[i] != 0) { + trueLen++; + } } - } - printf("[ "); - for (int64_t i = 0, j = 0; i < len; i++) { - if (out[i] != 0) { - j++; - printf("\"%" PRIx64 "\"%s", out[i], j == trueLen ? "" : ", "); + printf("[ "); + for (int64_t i = 0, j = 0; i < len; i++) { + if (out[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", out[i], j == trueLen ? "" : ", "); + } } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < len; i++) { + if (out[i] != 0) { + h3Println(out[i]); + } + } + } else { + free(out); + return E_FAILED; } + free(out); - printf(" ]\n"); return E_SUCCESS; } @@ -847,6 +1021,8 @@ SUBCOMMAND( cellToCenterChild, "Returns the H3 index that is the centrally-placed child (or lower) of the " "provided cell") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); int res = 0; Arg resArg = {.names = {"-r", "--resolution"}, @@ -857,7 +1033,8 @@ SUBCOMMAND( .helpText = "Resolution, 1-15 inclusive, excluding 0 as it can " "never be a child"}; - Arg *args[] = {&cellToCenterChildArg, &helpArg, &cellArg, &resArg}; + Arg *args[] = {&cellToCenterChildArg, &helpArg, &cellArg, &resArg, + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index centerChild; int valid = H3_EXPORT(isValidCell)(cell); @@ -868,7 +1045,13 @@ SUBCOMMAND( if (err) { return err; } - h3Println(centerChild); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", centerChild); + } else if (strcmp(format, "newline") == 0) { + h3Println(centerChild); + } else { + return E_FAILED; + } return E_SUCCESS; } @@ -900,6 +1083,8 @@ SUBCOMMAND( SUBCOMMAND(childPosToCell, "Returns the child cell at a given position and resolution within " "an ordered list of all children of the parent cell") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); int res = 0; Arg resArg = {.names = {"-r", "--resolution"}, @@ -919,7 +1104,8 @@ SUBCOMMAND(childPosToCell, .value = &pos, .helpText = "The child position within the set of children of the parent cell"}; - Arg *args[] = {&childPosToCellArg, &helpArg, &cellArg, &resArg, &posArg}; + Arg *args[] = {&childPosToCellArg, &helpArg, &cellArg, &resArg, &posArg, + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index child; int valid = H3_EXPORT(isValidCell)(cell); @@ -930,7 +1116,13 @@ SUBCOMMAND(childPosToCell, if (err) { return err; } - h3Println(child); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", child); + } else if (strcmp(format, "newline") == 0) { + h3Println(child); + } else { + return E_FAILED; + } return E_SUCCESS; } @@ -1010,11 +1202,12 @@ H3Index *readCellsFromFile(FILE *fp, char *buffer, size_t *totalCells) { SUBCOMMAND(compactCells, "Compacts the provided set of cells as best as possible. The set of " - "input cells must all share the same resolution. The compacted " - "cells will be printed one per line to stdout.") { + "input cells must all share the same resolution.") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); char filename[1024] = {0}; // More than Windows, lol Arg filenameArg = { - .names = {"-f", "--file"}, + .names = {"-i", "--file"}, .scanFormat = "%1023c", .valueName = "FILENAME", .value = &filename, @@ -1030,7 +1223,8 @@ SUBCOMMAND(compactCells, .helpText = "The cells to compact. Up to 100 cells if provided " "as hexadecimals with zero padding."}; - Arg *args[] = {&compactCellsArg, &helpArg, &filenameArg, &cellStrsArg}; + Arg *args[] = {&compactCellsArg, &helpArg, &filenameArg, &cellStrsArg, + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); if (!filenameArg.found && !cellStrsArg.found) { fprintf(stderr, @@ -1074,13 +1268,38 @@ SUBCOMMAND(compactCells, free(compactedSet); return err; } - // We have a compacted set! Let's print them out - for (int i = 0; i < cellsOffset; i++) { - if (compactedSet[i] == 0) { - continue; + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Since we don't know *actually* how many cells are in the output + // (usually the max, but sometimes not), we need to do a quick scan to + // figure out the true length in order to properly serialize to a JSON + // array + int64_t trueLen = 0; + for (int64_t i = 0; i < cellsOffset; i++) { + if (compactedSet[i] != 0) { + trueLen++; + } + } + printf("[ "); + for (int64_t i = 0, j = 0; i < cellsOffset; i++) { + if (compactedSet[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", compactedSet[i], + j == trueLen ? "" : ", "); + } } - h3Println(compactedSet[i]); + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < cellsOffset; i++) { + if (compactedSet[i] != 0) { + h3Println(compactedSet[i]); + } + } + } else { + free(cells); + free(compactedSet); + return E_FAILED; } + free(cells); free(compactedSet); return E_SUCCESS; @@ -1092,9 +1311,11 @@ SUBCOMMAND(uncompactCells, "cells will be printed one per line to stdout.") { // TODO: *Most* of this logic is shared with compactCells. See about DRYing // it. + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); char filename[1024] = {0}; // More than Windows, lol Arg filenameArg = { - .names = {"-f", "--file"}, + .names = {"-i", "--file"}, .scanFormat = "%1023c", .valueName = "FILENAME", .value = &filename, @@ -1120,8 +1341,8 @@ SUBCOMMAND(uncompactCells, "Resolution, 0-15 inclusive, that the compacted set " "should be uncompacted to. Must be greater than or equal " "to the highest resolution within the compacted set."}; - Arg *args[] = {&uncompactCellsArg, &helpArg, &filenameArg, &cellStrsArg, - &resArg}; + Arg *args[] = {&uncompactCellsArg, &helpArg, &filenameArg, + &cellStrsArg, &resArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); if (!filenameArg.found && !cellStrsArg.found) { fprintf(stderr, @@ -1185,13 +1406,38 @@ SUBCOMMAND(uncompactCells, free(uncompactedSet); return err; } - // We have a compacted set! Let's print them out - for (int i = 0; i < uncompactedSize; i++) { - if (uncompactedSet[i] == 0) { - continue; + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Since we don't know *actually* how many cells are in the output + // (usually the max, but sometimes not), we need to do a quick scan to + // figure out the true length in order to properly serialize to a JSON + // array + int64_t trueLen = 0; + for (int64_t i = 0; i < uncompactedSize; i++) { + if (uncompactedSet[i] != 0) { + trueLen++; + } + } + printf("[ "); + for (int64_t i = 0, j = 0; i < uncompactedSize; i++) { + if (uncompactedSet[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", uncompactedSet[i], + j == trueLen ? "" : ", "); + } + } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < uncompactedSize; i++) { + if (uncompactedSet[i] != 0) { + h3Println(uncompactedSet[i]); + } } - h3Println(uncompactedSet[i]); + } else { + free(cells); + free(uncompactedSet); + return E_FAILED; } + free(cells); free(uncompactedSet); return E_SUCCESS; @@ -1364,9 +1610,11 @@ SUBCOMMAND( polygonToCells, "Converts a polygon (array of lat, lng points, or array of arrays of lat, " "lng points) into a set of covering cells at the specified resolution") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); char filename[1024] = {0}; // More than Windows, lol Arg filenameArg = { - .names = {"-f", "--file"}, + .names = {"-i", "--file"}, .scanFormat = "%1023c", .valueName = "FILENAME", .value = &filename, @@ -1389,8 +1637,8 @@ SUBCOMMAND( .helpText = "Resolution, 0-15 inclusive, that the polygon " "should be converted to."}; - Arg *args[] = {&polygonToCellsArg, &helpArg, &filenameArg, &polygonStrArg, - &resArg}; + Arg *args[] = {&polygonToCellsArg, &helpArg, &filenameArg, + &polygonStrArg, &resArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); if (filenameArg.found == polygonStrArg.found) { fprintf(stderr, @@ -1441,13 +1689,36 @@ SUBCOMMAND( free(cells); return err; } - // We can print out the cells - for (int i = 0; i < cellsSize; i++) { - if (cells[i] == 0) { - continue; + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Since we don't know *actually* how many cells are in the output + // (usually the max, but sometimes not), we need to do a quick scan to + // figure out the true length in order to properly serialize to a JSON + // array + int64_t trueLen = 0; + for (int64_t i = 0; i < cellsSize; i++) { + if (cells[i] != 0) { + trueLen++; + } } - h3Println(cells[i]); + printf("[ "); + for (int64_t i = 0, j = 0; i < cellsSize; i++) { + if (cells[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", cells[i], j == trueLen ? "" : ", "); + } + } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < cellsSize; i++) { + if (cells[i] != 0) { + h3Println(cells[i]); + } + } + } else { + free(cells); + return E_FAILED; } + free(cells); return E_SUCCESS; } @@ -1458,7 +1729,7 @@ SUBCOMMAND( "the polygon. Will always be equal or more than actually necessary") { char filename[1024] = {0}; // More than Windows, lol Arg filenameArg = { - .names = {"-f", "--file"}, + .names = {"-i", "--file"}, .scanFormat = "%1023c", .valueName = "FILENAME", .value = &filename, @@ -1534,9 +1805,11 @@ SUBCOMMAND( SUBCOMMAND(cellsToMultiPolygon, "Returns a polygon (array of arrays of " "lat, lng points) for a set of cells") { + DEFINE_FORMAT_ARG( + "'json' for [[[[lat, lng],...],...],...] 'wkt' for a WKT MULTIPOLYGON"); char filename[1024] = {0}; // More than Windows, lol Arg filenameArg = { - .names = {"-f", "--file"}, + .names = {"-i", "--file"}, .scanFormat = "%1023c", .valueName = "FILENAME", .value = &filename, @@ -1552,7 +1825,7 @@ SUBCOMMAND(cellsToMultiPolygon, "The cells to convert. Up to 100 cells if provided " "as hexadecimals with zero padding."}; Arg *args[] = {&cellsToMultiPolygonArg, &helpArg, &filenameArg, - &cellStrsArg}; + &cellStrsArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); if (filenameArg.found == cellStrsArg.found) { fprintf(stderr, @@ -1595,38 +1868,77 @@ SUBCOMMAND(cellsToMultiPolygon, H3_EXPORT(destroyLinkedMultiPolygon)(&out); return err; } - printf("["); - LinkedGeoPolygon *currPoly = &out; - while (currPoly) { + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { printf("["); - LinkedGeoLoop *currLoop = currPoly->first; - while (currLoop) { + LinkedGeoPolygon *currPoly = &out; + while (currPoly) { printf("["); - LinkedLatLng *currLatLng = currLoop->first; - while (currLatLng) { - printf("[%f, %f]", - H3_EXPORT(radsToDegs)(currLatLng->vertex.lat), - H3_EXPORT(radsToDegs)(currLatLng->vertex.lng)); - currLatLng = currLatLng->next; - if (currLatLng) { - printf(", "); + LinkedGeoLoop *currLoop = currPoly->first; + while (currLoop) { + printf("["); + LinkedLatLng *currLatLng = currLoop->first; + while (currLatLng) { + printf("[%f, %f]", + H3_EXPORT(radsToDegs)(currLatLng->vertex.lat), + H3_EXPORT(radsToDegs)(currLatLng->vertex.lng)); + currLatLng = currLatLng->next; + if (currLatLng) { + printf(", "); + } + } + currLoop = currLoop->next; + if (currLoop) { + printf("], "); + } else { + printf("]"); } } - currLoop = currLoop->next; - if (currLoop) { + currPoly = currPoly->next; + if (currPoly) { printf("], "); } else { printf("]"); } } - currPoly = currPoly->next; - if (currPoly) { - printf("], "); - } else { - printf("]"); + printf("]\n"); + } else if (strcmp(format, "wkt") == 0) { + printf("MULTIPOLYGON ("); + LinkedGeoPolygon *currPoly = &out; + while (currPoly) { + printf("("); + LinkedGeoLoop *currLoop = currPoly->first; + while (currLoop) { + printf("("); + LinkedLatLng *currLatLng = currLoop->first; + while (currLatLng) { + printf("%f %f", + H3_EXPORT(radsToDegs)(currLatLng->vertex.lng), + H3_EXPORT(radsToDegs)(currLatLng->vertex.lat)); + currLatLng = currLatLng->next; + if (currLatLng) { + printf(", "); + } + } + currLoop = currLoop->next; + if (currLoop) { + printf("), "); + } else { + printf(")"); + } + } + currPoly = currPoly->next; + if (currPoly) { + printf("), "); + } else { + printf(")"); + } } + printf(")\n"); + } else { + free(cells); + H3_EXPORT(destroyLinkedMultiPolygon)(&out); + return E_FAILED; } - printf("]\n"); free(cells); H3_EXPORT(destroyLinkedMultiPolygon)(&out); return E_SUCCESS; @@ -1637,6 +1949,8 @@ SUBCOMMAND(cellsToMultiPolygon, SUBCOMMAND(areNeighborCells, "Determines if the provided H3 cells are neighbors (have a shared " "border)") { + DEFINE_FORMAT_ARG( + "'json' for true or false, 'numeric' for 1 or 0 (Default: json)"); H3Index origin, destination; Arg originCellArg = {.names = {"-o", "--origin"}, .required = true, @@ -1651,7 +1965,7 @@ SUBCOMMAND(areNeighborCells, .value = &destination, .helpText = "Destination H3 Cell"}; Arg *args[] = {&areNeighborCellsArg, &originCellArg, &destinationCellArg, - &helpArg}; + &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); int areNeighbors = 0; H3Error err = @@ -1659,13 +1973,22 @@ SUBCOMMAND(areNeighborCells, if (err != E_SUCCESS) { return err; } - printf(areNeighbors ? "true\n" : "false\n"); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("%s\n", areNeighbors ? "true" : "false"); + } else if (strcmp(format, "numeric") == 0) { + printf("%d\n", areNeighbors); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(cellsToDirectedEdge, "Converts neighboring cells into a directed edge index (or errors " "if they are not neighbors)") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n " + "(Default: json)"); H3Index origin, destination; Arg originCellArg = {.names = {"-o", "--origin"}, .required = true, @@ -1680,74 +2003,117 @@ SUBCOMMAND(cellsToDirectedEdge, .value = &destination, .helpText = "Destination H3 Cell"}; Arg *args[] = {&cellsToDirectedEdgeArg, &originCellArg, &destinationCellArg, - &helpArg}; + &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index out = 0; H3Error err = H3_EXPORT(cellsToDirectedEdge)(origin, destination, &out); if (err != E_SUCCESS) { return err; } - printf("%" PRIx64 "\n", out); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", out); + } else if (strcmp(format, "newline") == 0) { + h3Println(out); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(isValidDirectedEdge, "Checks if the provided H3 directed edge is actually valid") { + DEFINE_FORMAT_ARG( + "'json' for true or false, 'numeric' for 1 or 0 (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&isValidDirectedEdgeArg, &helpArg, &cellArg}; + Arg *args[] = {&isValidDirectedEdgeArg, &helpArg, &cellArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); bool isValid = H3_EXPORT(isValidDirectedEdge)(cell); - printf("%s", isValid ? "true\n" : "false\n"); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("%s\n", isValid ? "true" : "false"); + } else if (strcmp(format, "numeric") == 0) { + printf("%d\n", isValid); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(getDirectedEdgeOrigin, "Returns the origin cell from the directed edge") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n " + "(Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&getDirectedEdgeOriginArg, &cellArg, &helpArg}; + Arg *args[] = {&getDirectedEdgeOriginArg, &cellArg, &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index out = 0; H3Error err = H3_EXPORT(getDirectedEdgeOrigin)(cell, &out); if (err != E_SUCCESS) { return err; } - printf("%" PRIx64 "\n", out); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", out); + } else if (strcmp(format, "newline") == 0) { + h3Println(out); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(getDirectedEdgeDestination, "Returns the destination cell from the directed edge") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n " + "(Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&getDirectedEdgeDestinationArg, &cellArg, &helpArg}; + Arg *args[] = {&getDirectedEdgeDestinationArg, &cellArg, &helpArg, + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index out = 0; H3Error err = H3_EXPORT(getDirectedEdgeDestination)(cell, &out); if (err != E_SUCCESS) { return err; } - printf("%" PRIx64 "\n", out); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", out); + } else if (strcmp(format, "newline") == 0) { + h3Println(out); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND( directedEdgeToCells, "Returns the origin, destination pair of cells from the directed edge") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&directedEdgeToCellsArg, &cellArg, &helpArg}; + Arg *args[] = {&directedEdgeToCellsArg, &cellArg, &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index out[2] = {0}; H3Error err = H3_EXPORT(directedEdgeToCells)(cell, &out[0]); if (err != E_SUCCESS) { return err; } - printf("[\"%" PRIx64 "\", \"%" PRIx64 "\"]\n", out[0], out[1]); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("[\"%" PRIx64 "\", \"%" PRIx64 "\"]\n", out[0], out[1]); + } else if (strcmp(format, "newline") == 0) { + printf("%" PRIx64 "\n%" PRIx64 "\n", out[0], out[1]); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(originToDirectedEdges, "Returns all of the directed edges from the specified origin cell") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&originToDirectedEdgesArg, &cellArg, &helpArg}; + Arg *args[] = {&originToDirectedEdgesArg, &cellArg, &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index out[6] = {0}; // This one is pretty loose about the inputs it accepts, so let's validate @@ -1760,42 +2126,73 @@ SUBCOMMAND(originToDirectedEdges, if (err != E_SUCCESS) { return err; } - printf("["); - bool hasPrinted = false; - for (int i = 0; i < 6; i++) { - if (out[i] > 0) { - if (hasPrinted) { - printf(", "); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("["); + bool hasPrinted = false; + for (int i = 0; i < 6; i++) { + if (out[i] > 0) { + if (hasPrinted) { + printf(", "); + } + printf("\"%" PRIx64 "\"", out[i]); + hasPrinted = true; + } + } + printf("]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int i = 0; i < 6; i++) { + if (out[i] != 0) { + h3Println(out[i]); } - printf("\"%" PRIx64 "\"", out[i]); - hasPrinted = true; } + } else { + return E_FAILED; } - printf("]\n"); return E_SUCCESS; } SUBCOMMAND(directedEdgeToBoundary, "Provides the coordinates defining the directed edge") { + DEFINE_FORMAT_ARG( + "'json' for [[lat, lng], ...], 'wkt' for a WKT POLYGON, 'newline' for " + "lat\\nlng\\n... (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&directedEdgeToBoundaryArg, &cellArg, &helpArg}; + Arg *args[] = {&directedEdgeToBoundaryArg, &cellArg, &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); CellBoundary cb = {0}; H3Error err = H3_EXPORT(directedEdgeToBoundary)(cell, &cb); if (err) { return err; } - // Using WKT formatting for the output. TODO: Add support for JSON - // formatting - printf("POLYGON(("); - for (int i = 0; i < cb.numVerts; i++) { - LatLng *ll = &cb.verts[i]; - printf("%.10lf %.10lf, ", H3_EXPORT(radsToDegs)(ll->lng), - H3_EXPORT(radsToDegs)(ll->lat)); - } - // WKT has the first and last points match, so re-print the first one - printf("%.10lf %.10lf))\n", H3_EXPORT(radsToDegs)(cb.verts[0].lng), - H3_EXPORT(radsToDegs)(cb.verts[0].lat)); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("["); + for (int i = 0; i < cb.numVerts - 1; i++) { + LatLng *ll = &cb.verts[i]; + printf("[%.10lf, %.10lf], ", H3_EXPORT(radsToDegs)(ll->lat), + H3_EXPORT(radsToDegs)(ll->lng)); + } + printf("[%.10lf, %.10lf]]\n", + H3_EXPORT(radsToDegs)(cb.verts[cb.numVerts - 1].lat), + H3_EXPORT(radsToDegs)(cb.verts[cb.numVerts - 1].lng)); + } else if (strcmp(format, "wkt") == 0) { + printf("LINESTRING ("); + for (int i = 0; i < cb.numVerts - 1; i++) { + LatLng *ll = &cb.verts[i]; + printf("%.10lf %.10lf, ", H3_EXPORT(radsToDegs)(ll->lng), + H3_EXPORT(radsToDegs)(ll->lat)); + } + printf("%.10lf %.10lf)\n", + H3_EXPORT(radsToDegs)(cb.verts[cb.numVerts - 1].lng), + H3_EXPORT(radsToDegs)(cb.verts[cb.numVerts - 1].lat)); + } else if (strcmp(format, "newline") == 0) { + for (int i = 0; i < cb.numVerts; i++) { + LatLng *ll = &cb.verts[i]; + printf("%.10lf\n%.10lf\n", H3_EXPORT(radsToDegs)(ll->lat), + H3_EXPORT(radsToDegs)(ll->lng)); + } + } else { + return E_FAILED; + } return E_SUCCESS; } @@ -1804,6 +2201,9 @@ SUBCOMMAND(directedEdgeToBoundary, SUBCOMMAND(cellToVertex, "Returns the vertex for the specified cell and vertex index. Must " "be 0-5 for hexagons, 0-4 for pentagons") { + DEFINE_FORMAT_ARG( + "'json' for \"CELL\"\\n, 'newline' for CELL\\n " + "(Default: json)"); DEFINE_CELL_ARG(cell, cellArg); int vertIndex = 0; Arg vertIndexArg = { @@ -1813,7 +2213,8 @@ SUBCOMMAND(cellToVertex, .valueName = "INDEX", .value = &vertIndex, .helpText = "Vertex index number. 0-5 for hexagons, 0-4 for pentagons"}; - Arg *args[] = {&cellToVertexArg, &cellArg, &vertIndexArg, &helpArg}; + Arg *args[] = {&cellToVertexArg, &cellArg, &vertIndexArg, &helpArg, + &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); // This function also doesn't sanitize its inputs correctly bool isValid = H3_EXPORT(isValidCell)(cell); @@ -1825,14 +2226,22 @@ SUBCOMMAND(cellToVertex, if (err) { return err; } - printf("%" PRIx64 "\n", out); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("\"%" PRIx64 "\"\n", out); + } else if (strcmp(format, "newline") == 0) { + h3Println(out); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(cellToVertexes, "Returns all of the vertexes from the specified cell") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&cellToVertexesArg, &cellArg, &helpArg}; + Arg *args[] = {&cellToVertexesArg, &cellArg, &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index out[6] = {0}; // This one is pretty loose about the inputs it accepts, so let's validate @@ -1845,24 +2254,43 @@ SUBCOMMAND(cellToVertexes, if (err != E_SUCCESS) { return err; } - printf("["); - bool hasPrinted = false; - for (int i = 0; i < 6; i++) { - if (out[i] > 0) { - if (hasPrinted) { - printf(", "); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Since we don't know *actually* how many cells are in the output + // (usually the max, but sometimes not), we need to do a quick scan to + // figure out the true length in order to properly serialize to a JSON + // array + int64_t trueLen = 0; + for (int64_t i = 0; i < 6; i++) { + if (out[i] != 0) { + trueLen++; + } + } + printf("[ "); + for (int64_t i = 0, j = 0; i < 6; i++) { + if (out[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", out[i], j == trueLen ? "" : ", "); + } + } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < 6; i++) { + if (out[i] != 0) { + h3Println(out[i]); } - printf("\"%" PRIx64 "\"", out[i]); - hasPrinted = true; } + } else { + return E_FAILED; } - printf("]\n"); return E_SUCCESS; } SUBCOMMAND(vertexToLatLng, "Returns the lat, lng pair for the given vertex") { + DEFINE_FORMAT_ARG( + "'json' for [lat, lng], 'wkt' for a WKT POINT, 'newline' for " + "lat\\nlng\\n (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&vertexToLatLngArg, &cellArg, &helpArg}; + Arg *args[] = {&vertexToLatLngArg, &cellArg, &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); bool isValid = H3_EXPORT(isValidVertex)(cell); if (!isValid) { @@ -1873,20 +2301,38 @@ SUBCOMMAND(vertexToLatLng, "Returns the lat, lng pair for the given vertex") { if (err) { return err; } - // Using WKT formatting for the output. TODO: Add support for JSON - // formatting - printf("POINT(%.10lf %.10lf)\n", H3_EXPORT(radsToDegs)(ll.lng), - H3_EXPORT(radsToDegs)(ll.lat)); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("[%.10lf, %.10lf]\n", H3_EXPORT(radsToDegs)(ll.lat), + H3_EXPORT(radsToDegs)(ll.lng)); + } else if (strcmp(format, "wkt") == 0) { + // Using WKT formatting for the output. TODO: Add support for JSON + // formatting + printf("POINT(%.10lf %.10lf)\n", H3_EXPORT(radsToDegs)(ll.lng), + H3_EXPORT(radsToDegs)(ll.lat)); + } else if (strcmp(format, "newline") == 0) { + printf("%.10lf\n%.10lf\n", H3_EXPORT(radsToDegs)(ll.lat), + H3_EXPORT(radsToDegs)(ll.lng)); + } else { + return E_FAILED; + } return E_SUCCESS; } SUBCOMMAND(isValidVertex, "Checks if the provided H3 vertex is actually valid") { + DEFINE_FORMAT_ARG( + "'json' for true or false, 'numeric' for 1 or 0 (Default: json)"); DEFINE_CELL_ARG(cell, cellArg); - Arg *args[] = {&isValidVertexArg, &helpArg, &cellArg}; + Arg *args[] = {&isValidVertexArg, &helpArg, &cellArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); bool isValid = H3_EXPORT(isValidVertex)(cell); - printf("%s", isValid ? "true\n" : "false\n"); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + printf("%s\n", isValid ? "true" : "false"); + } else if (strcmp(format, "numeric") == 0) { + printf("%d\n", isValid); + } else { + return E_FAILED; + } return E_SUCCESS; } @@ -2144,7 +2590,9 @@ SUBCOMMAND(getNumCells, } SUBCOMMAND(getRes0Cells, "Returns all of the resolution 0 cells") { - Arg *args[] = {&getRes0CellsArg, &helpArg}; + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); + Arg *args[] = {&getRes0CellsArg, &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index *out = calloc(122, sizeof(H3Index)); H3Error err = H3_EXPORT(getRes0Cells)(out); @@ -2152,24 +2600,43 @@ SUBCOMMAND(getRes0Cells, "Returns all of the resolution 0 cells") { free(out); return err; } - printf("["); - bool hasPrinted = false; - for (int i = 0; i < 122; i++) { - if (out[i] > 0) { - if (hasPrinted) { - printf(", "); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Since we don't know *actually* how many cells are in the output + // (usually the max, but sometimes not), we need to do a quick scan to + // figure out the true length in order to properly serialize to a JSON + // array + int64_t trueLen = 0; + for (int64_t i = 0; i < 122; i++) { + if (out[i] != 0) { + trueLen++; } - printf("\"%" PRIx64 "\"", out[i]); - hasPrinted = true; } + printf("[ "); + for (int64_t i = 0, j = 0; i < 122; i++) { + if (out[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", out[i], j == trueLen ? "" : ", "); + } + } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < 122; i++) { + if (out[i] != 0) { + h3Println(out[i]); + } + } + } else { + free(out); + return E_FAILED; } - printf("]\n"); free(out); return E_SUCCESS; } SUBCOMMAND(getPentagons, "Returns all of the pentagons at the specified resolution") { + DEFINE_FORMAT_ARG( + "'json' for [\"CELL\", ...], 'newline' for CELL\\n... (Default: json)"); int res = 0; Arg resArg = {.names = {"-r", "--resolution"}, .required = true, @@ -2177,7 +2644,7 @@ SUBCOMMAND(getPentagons, .valueName = "res", .value = &res, .helpText = "Resolution, 0-15 inclusive."}; - Arg *args[] = {&getPentagonsArg, &resArg, &helpArg}; + Arg *args[] = {&getPentagonsArg, &resArg, &helpArg, &formatArg}; PARSE_SUBCOMMAND(argc, argv, args); H3Index *out = calloc(12, sizeof(H3Index)); H3Error err = H3_EXPORT(getPentagons)(res, out); @@ -2185,18 +2652,35 @@ SUBCOMMAND(getPentagons, free(out); return err; } - printf("["); - bool hasPrinted = false; - for (int i = 0; i < 12; i++) { - if (out[i] > 0) { - if (hasPrinted) { - printf(", "); + if (strcmp(format, "json") == 0 || strcmp(format, "") == 0) { + // Since we don't know *actually* how many cells are in the output + // (usually the max, but sometimes not), we need to do a quick scan to + // figure out the true length in order to properly serialize to a JSON + // array + int64_t trueLen = 0; + for (int64_t i = 0; i < 12; i++) { + if (out[i] != 0) { + trueLen++; } - printf("\"%" PRIx64 "\"", out[i]); - hasPrinted = true; } + printf("[ "); + for (int64_t i = 0, j = 0; i < 12; i++) { + if (out[i] != 0) { + j++; + printf("\"%" PRIx64 "\"%s", out[i], j == trueLen ? "" : ", "); + } + } + printf(" ]\n"); + } else if (strcmp(format, "newline") == 0) { + for (int64_t i = 0; i < 12; i++) { + if (out[i] != 0) { + h3Println(out[i]); + } + } + } else { + free(out); + return E_FAILED; } - printf("]\n"); free(out); return E_SUCCESS; } diff --git a/tests/cli/cellToBoundary.txt b/tests/cli/cellToBoundary.txt index 43535d658..0b7fcb64c 100644 --- a/tests/cli/cellToBoundary.txt +++ b/tests/cli/cellToBoundary.txt @@ -1 +1 @@ -add_h3_cli_test(testCliCellToBoundary "cellToBoundary -c 8928342e20fffff" "POLYGON((-122.4990471431 37.4997389893, -122.4979805011 37.5014245698, -122.4992373065 37.5029321860, -122.5015607527 37.5027541980, -122.5026273256 37.5010686174, -122.5013705214 37.4995610248, -122.4990471431 37.4997389893))") +add_h3_cli_test(testCliCellToBoundary "cellToBoundary -c 8928342e20fffff -f wkt" "POLYGON((-122.4990471431 37.4997389893, -122.4979805011 37.5014245698, -122.4992373065 37.5029321860, -122.5015607527 37.5027541980, -122.5026273256 37.5010686174, -122.5013705214 37.4995610248, -122.4990471431 37.4997389893))") diff --git a/tests/cli/cellToCenterChild.txt b/tests/cli/cellToCenterChild.txt index a7212b3c3..dc5f46079 100644 --- a/tests/cli/cellToCenterChild.txt +++ b/tests/cli/cellToCenterChild.txt @@ -1 +1 @@ -add_h3_cli_test(testCliCellToCenterChild "cellToCenterChild -c 85283473fffffff --resolution 7" "872834700ffffff") +add_h3_cli_test(testCliCellToCenterChild "cellToCenterChild -c 85283473fffffff --resolution 7 -f newline" "872834700ffffff") diff --git a/tests/cli/cellToLatLng.txt b/tests/cli/cellToLatLng.txt index 1fb89fd98..7700fcb4e 100644 --- a/tests/cli/cellToLatLng.txt +++ b/tests/cli/cellToLatLng.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliCellToLatLng "cellToLatLng -c 8928342e20fffff" "POINT(-122.5003039349 37.5012466151)") +add_h3_cli_test(testCliCellToLatLng "cellToLatLng -c 8928342e20fffff -f wkt" "POINT(-122.5003039349 37.5012466151)") add_h3_cli_test(testCliInvalidCellToLatLng "cellToLatLng -c asdf 2>&1" "Error 5: Cell argument was not valid") diff --git a/tests/cli/cellToParent.txt b/tests/cli/cellToParent.txt index 8ecd61423..d17f0c70a 100644 --- a/tests/cli/cellToParent.txt +++ b/tests/cli/cellToParent.txt @@ -1 +1 @@ -add_h3_cli_test(testCliCellToParent "cellToParent -c 8928342e20fffff --resolution 3" "832834fffffffff") +add_h3_cli_test(testCliCellToParent "cellToParent -c 8928342e20fffff --resolution 3 -f newline" "832834fffffffff") diff --git a/tests/cli/cellToVertex.txt b/tests/cli/cellToVertex.txt index 3efa6d2fd..fd6cdcdbf 100644 --- a/tests/cli/cellToVertex.txt +++ b/tests/cli/cellToVertex.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliCellToVertex "cellToVertex -c 85283473fffffff -v 0" "22528340bfffffff") +add_h3_cli_test(testCliCellToVertex "cellToVertex -c 85283473fffffff -v 0 -f newline" "22528340bfffffff") add_h3_cli_test(testCliNotCellToVertex "cellToVertex -c 115283473fffffff -v 0 2>&1" "Error 5: Cell argument was not valid") diff --git a/tests/cli/cellToVertexes.txt b/tests/cli/cellToVertexes.txt index c5a8153d4..9c7b1d76a 100644 --- a/tests/cli/cellToVertexes.txt +++ b/tests/cli/cellToVertexes.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliCellToVertexes "cellToVertexes -c 85283473fffffff" "[\"22528340bfffffff\", \"235283447fffffff\", \"205283463fffffff\", \"255283463fffffff\", \"22528340ffffffff\", \"23528340bfffffff\"]") +add_h3_cli_test(testCliCellToVertexes "cellToVertexes -c 85283473fffffff" "[ \"22528340bfffffff\", \"235283447fffffff\", \"205283463fffffff\", \"255283463fffffff\", \"22528340ffffffff\", \"23528340bfffffff\" ]") add_h3_cli_test(testCliNotCellToVertexes "cellToVertexes -c 115283473fffffff 2>&1" "Error 5: Cell argument was not valid") diff --git a/tests/cli/cellsToDirectedEdge.txt b/tests/cli/cellsToDirectedEdge.txt index 9e0c8656b..5f4d2e91b 100644 --- a/tests/cli/cellsToDirectedEdge.txt +++ b/tests/cli/cellsToDirectedEdge.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliCellsToDirectedEdge "cellsToDirectedEdge -o 85283473fffffff -d 85283477fffffff" "115283473fffffff") +add_h3_cli_test(testCliCellsToDirectedEdge "cellsToDirectedEdge -o 85283473fffffff -d 85283477fffffff -f newline" "115283473fffffff") add_h3_cli_test(testCliCellsNotToDirectedEdge "cellsToDirectedEdge -o 85283473fffffff -d 85283472fffffff 2>&1" "Error 11: Cell arguments were not neighbors") diff --git a/tests/cli/cellsToMultiPolygon.txt b/tests/cli/cellsToMultiPolygon.txt index 705114069..5d1466de4 100644 --- a/tests/cli/cellsToMultiPolygon.txt +++ b/tests/cli/cellsToMultiPolygon.txt @@ -1,13 +1,13 @@ -add_h3_cli_test(testCliCellsToMultiPolygonFile1 "cellsToMultiPolygon -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test1.txt" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonFile2 "cellsToMultiPolygon -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test2.txt" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]], [[[38.231228, -123.642760], [38.229797, -123.658996], [38.218020, -123.666324], [38.207675, -123.657418], [38.209105, -123.641184], [38.220882, -123.633853]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonFile3 "cellsToMultiPolygon -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test3.txt" "[[[[37.106073, -122.020493], [37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726]], [[37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101], [37.337556, -122.090429], [37.420129, -122.037735]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonFile4 "cellsToMultiPolygon -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test4.txt" "[[[[37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726], [37.106073, -122.020493]], [[37.337556, -122.090429], [37.420129, -122.037735], [37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101]]], [[[43.431278, -115.975237], [43.508096, -115.912429], [43.581386, -115.974912], [43.577810, -116.100258], [43.500970, -116.162919], [43.427727, -116.100382]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonFile5 "cellsToMultiPolygon -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test5.txt" "[[[[37.893933, -120.851267], [37.968684, -120.912560], [37.961273, -121.028117], [38.035842, -121.089514], [38.028243, -121.205013], [38.102628, -121.266514], [38.094842, -121.381953], [38.169044, -121.443555], [38.161070, -121.558932], [38.235088, -121.620634], [38.226927, -121.735948], [38.300760, -121.797749], [38.292411, -121.912997], [38.366059, -121.974896], [38.357522, -122.090075], [38.275391, -122.143187], [38.266721, -122.258129], [38.184513, -122.311004], [38.175712, -122.425707], [38.093428, -122.478345], [38.084496, -122.592809], [38.002138, -122.645211], [37.993077, -122.759435], [37.910647, -122.811600], [37.901458, -122.925582], [37.818957, -122.977512], [37.809642, -123.091252], [37.727072, -123.142946], [37.653813, -123.081070], [37.571172, -123.132698], [37.497785, -123.070917], [37.415075, -123.122480], [37.341561, -123.060795], [37.258782, -123.112292], [37.185142, -123.050702], [37.102296, -123.102134], [37.028530, -123.040638], [36.945618, -123.092005], [36.871727, -123.030604], [36.788751, -123.081906], [36.714736, -123.020599], [36.723641, -122.907984], [36.649445, -122.846765], [36.658170, -122.734072], [36.583794, -122.672942], [36.592340, -122.560174], [36.517784, -122.499133], [36.526150, -122.386293], [36.451416, -122.325343], [36.459602, -122.212431], [36.384689, -122.151573], [36.392695, -122.038593], [36.317605, -121.977827], [36.325432, -121.864780], [36.408404, -121.812338], [36.416106, -121.699065], [36.499012, -121.646395], [36.506587, -121.532897], [36.589424, -121.479999], [36.596872, -121.366277], [36.679638, -121.313150], [36.686957, -121.199205], [36.769651, -121.145849], [36.776840, -121.031683], [36.859460, -120.978099], [36.866518, -120.863712], [36.949062, -120.809899], [37.024556, -120.870629], [37.107030, -120.816743], [37.182402, -120.877566], [37.264805, -120.823607], [37.340054, -120.884523], [37.422384, -120.830491], [37.497511, -120.891502], [37.579767, -120.837396], [37.654769, -120.898500], [37.736951, -120.844321], [37.811828, -120.905520]]], [[[37.490250, -121.006554], [37.565196, -121.067667], [37.647458, -121.013720], [37.722279, -121.074928], [37.804467, -121.020908], [37.879162, -121.082210], [37.871614, -121.197541], [37.789422, -121.251401], [37.714782, -121.190091], [37.632515, -121.243878], [37.557750, -121.182663], [37.475409, -121.236378], [37.400519, -121.175257], [37.318106, -121.228899], [37.243092, -121.167872], [37.160607, -121.221443], [37.085470, -121.160510], [37.002914, -121.214009], [36.995490, -121.328282], [36.912860, -121.381551], [36.905305, -121.495600], [36.822602, -121.548639], [36.814919, -121.662463], [36.732145, -121.715272], [36.724333, -121.828869], [36.799241, -121.889820], [36.791248, -122.003352], [36.865977, -122.064397], [36.857802, -122.177861], [36.932351, -122.239000], [36.923995, -122.352395], [36.998363, -122.413626], [36.989826, -122.526949], [37.064013, -122.588271], [37.055294, -122.701520], [36.972446, -122.753285], [36.898316, -122.691966], [36.906977, -122.578878], [36.832666, -122.517650], [36.841147, -122.404488], [36.766655, -122.343351], [36.774955, -122.230118], [36.700284, -122.169073], [36.708403, -122.055771], [36.633553, -121.994819], [36.641490, -121.881449], [36.566462, -121.820592], [36.574218, -121.707157], [36.657058, -121.654417], [36.664688, -121.540757], [36.747458, -121.487788], [36.754960, -121.373903], [36.837659, -121.320705], [36.845030, -121.206596], [36.927656, -121.153169], [36.934897, -121.038838], [37.017447, -120.985181], [37.092763, -121.046013], [37.175243, -120.992284], [37.250436, -121.053210], [37.332844, -120.999409], [37.407914, -121.060428]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonStdin1 "cellsToMultiPolygon -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test1.txt" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonStdin2 "cellsToMultiPolygon -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test2.txt" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]], [[[38.231228, -123.642760], [38.229797, -123.658996], [38.218020, -123.666324], [38.207675, -123.657418], [38.209105, -123.641184], [38.220882, -123.633853]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonStdin3 "cellsToMultiPolygon -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test3.txt" "[[[[37.106073, -122.020493], [37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726]], [[37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101], [37.337556, -122.090429], [37.420129, -122.037735]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonStdin4 "cellsToMultiPolygon -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test4.txt" "[[[[37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726], [37.106073, -122.020493]], [[37.337556, -122.090429], [37.420129, -122.037735], [37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101]]], [[[43.431278, -115.975237], [43.508096, -115.912429], [43.581386, -115.974912], [43.577810, -116.100258], [43.500970, -116.162919], [43.427727, -116.100382]]]]") -add_h3_cli_test(testCliCellsToMultiPolygonStdin5 "cellsToMultiPolygon -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test5.txt" "[[[[37.893933, -120.851267], [37.968684, -120.912560], [37.961273, -121.028117], [38.035842, -121.089514], [38.028243, -121.205013], [38.102628, -121.266514], [38.094842, -121.381953], [38.169044, -121.443555], [38.161070, -121.558932], [38.235088, -121.620634], [38.226927, -121.735948], [38.300760, -121.797749], [38.292411, -121.912997], [38.366059, -121.974896], [38.357522, -122.090075], [38.275391, -122.143187], [38.266721, -122.258129], [38.184513, -122.311004], [38.175712, -122.425707], [38.093428, -122.478345], [38.084496, -122.592809], [38.002138, -122.645211], [37.993077, -122.759435], [37.910647, -122.811600], [37.901458, -122.925582], [37.818957, -122.977512], [37.809642, -123.091252], [37.727072, -123.142946], [37.653813, -123.081070], [37.571172, -123.132698], [37.497785, -123.070917], [37.415075, -123.122480], [37.341561, -123.060795], [37.258782, -123.112292], [37.185142, -123.050702], [37.102296, -123.102134], [37.028530, -123.040638], [36.945618, -123.092005], [36.871727, -123.030604], [36.788751, -123.081906], [36.714736, -123.020599], [36.723641, -122.907984], [36.649445, -122.846765], [36.658170, -122.734072], [36.583794, -122.672942], [36.592340, -122.560174], [36.517784, -122.499133], [36.526150, -122.386293], [36.451416, -122.325343], [36.459602, -122.212431], [36.384689, -122.151573], [36.392695, -122.038593], [36.317605, -121.977827], [36.325432, -121.864780], [36.408404, -121.812338], [36.416106, -121.699065], [36.499012, -121.646395], [36.506587, -121.532897], [36.589424, -121.479999], [36.596872, -121.366277], [36.679638, -121.313150], [36.686957, -121.199205], [36.769651, -121.145849], [36.776840, -121.031683], [36.859460, -120.978099], [36.866518, -120.863712], [36.949062, -120.809899], [37.024556, -120.870629], [37.107030, -120.816743], [37.182402, -120.877566], [37.264805, -120.823607], [37.340054, -120.884523], [37.422384, -120.830491], [37.497511, -120.891502], [37.579767, -120.837396], [37.654769, -120.898500], [37.736951, -120.844321], [37.811828, -120.905520]]], [[[37.490250, -121.006554], [37.565196, -121.067667], [37.647458, -121.013720], [37.722279, -121.074928], [37.804467, -121.020908], [37.879162, -121.082210], [37.871614, -121.197541], [37.789422, -121.251401], [37.714782, -121.190091], [37.632515, -121.243878], [37.557750, -121.182663], [37.475409, -121.236378], [37.400519, -121.175257], [37.318106, -121.228899], [37.243092, -121.167872], [37.160607, -121.221443], [37.085470, -121.160510], [37.002914, -121.214009], [36.995490, -121.328282], [36.912860, -121.381551], [36.905305, -121.495600], [36.822602, -121.548639], [36.814919, -121.662463], [36.732145, -121.715272], [36.724333, -121.828869], [36.799241, -121.889820], [36.791248, -122.003352], [36.865977, -122.064397], [36.857802, -122.177861], [36.932351, -122.239000], [36.923995, -122.352395], [36.998363, -122.413626], [36.989826, -122.526949], [37.064013, -122.588271], [37.055294, -122.701520], [36.972446, -122.753285], [36.898316, -122.691966], [36.906977, -122.578878], [36.832666, -122.517650], [36.841147, -122.404488], [36.766655, -122.343351], [36.774955, -122.230118], [36.700284, -122.169073], [36.708403, -122.055771], [36.633553, -121.994819], [36.641490, -121.881449], [36.566462, -121.820592], [36.574218, -121.707157], [36.657058, -121.654417], [36.664688, -121.540757], [36.747458, -121.487788], [36.754960, -121.373903], [36.837659, -121.320705], [36.845030, -121.206596], [36.927656, -121.153169], [36.934897, -121.038838], [37.017447, -120.985181], [37.092763, -121.046013], [37.175243, -120.992284], [37.250436, -121.053210], [37.332844, -120.999409], [37.407914, -121.060428]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonFile1 "cellsToMultiPolygon -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test1.txt" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonFile2 "cellsToMultiPolygon -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test2.txt" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]], [[[38.231228, -123.642760], [38.229797, -123.658996], [38.218020, -123.666324], [38.207675, -123.657418], [38.209105, -123.641184], [38.220882, -123.633853]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonFile3 "cellsToMultiPolygon -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test3.txt" "[[[[37.106073, -122.020493], [37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726]], [[37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101], [37.337556, -122.090429], [37.420129, -122.037735]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonFile4 "cellsToMultiPolygon -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test4.txt" "[[[[37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726], [37.106073, -122.020493]], [[37.337556, -122.090429], [37.420129, -122.037735], [37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101]]], [[[43.431278, -115.975237], [43.508096, -115.912429], [43.581386, -115.974912], [43.577810, -116.100258], [43.500970, -116.162919], [43.427727, -116.100382]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonFile5 "cellsToMultiPolygon -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test5.txt" "[[[[37.893933, -120.851267], [37.968684, -120.912560], [37.961273, -121.028117], [38.035842, -121.089514], [38.028243, -121.205013], [38.102628, -121.266514], [38.094842, -121.381953], [38.169044, -121.443555], [38.161070, -121.558932], [38.235088, -121.620634], [38.226927, -121.735948], [38.300760, -121.797749], [38.292411, -121.912997], [38.366059, -121.974896], [38.357522, -122.090075], [38.275391, -122.143187], [38.266721, -122.258129], [38.184513, -122.311004], [38.175712, -122.425707], [38.093428, -122.478345], [38.084496, -122.592809], [38.002138, -122.645211], [37.993077, -122.759435], [37.910647, -122.811600], [37.901458, -122.925582], [37.818957, -122.977512], [37.809642, -123.091252], [37.727072, -123.142946], [37.653813, -123.081070], [37.571172, -123.132698], [37.497785, -123.070917], [37.415075, -123.122480], [37.341561, -123.060795], [37.258782, -123.112292], [37.185142, -123.050702], [37.102296, -123.102134], [37.028530, -123.040638], [36.945618, -123.092005], [36.871727, -123.030604], [36.788751, -123.081906], [36.714736, -123.020599], [36.723641, -122.907984], [36.649445, -122.846765], [36.658170, -122.734072], [36.583794, -122.672942], [36.592340, -122.560174], [36.517784, -122.499133], [36.526150, -122.386293], [36.451416, -122.325343], [36.459602, -122.212431], [36.384689, -122.151573], [36.392695, -122.038593], [36.317605, -121.977827], [36.325432, -121.864780], [36.408404, -121.812338], [36.416106, -121.699065], [36.499012, -121.646395], [36.506587, -121.532897], [36.589424, -121.479999], [36.596872, -121.366277], [36.679638, -121.313150], [36.686957, -121.199205], [36.769651, -121.145849], [36.776840, -121.031683], [36.859460, -120.978099], [36.866518, -120.863712], [36.949062, -120.809899], [37.024556, -120.870629], [37.107030, -120.816743], [37.182402, -120.877566], [37.264805, -120.823607], [37.340054, -120.884523], [37.422384, -120.830491], [37.497511, -120.891502], [37.579767, -120.837396], [37.654769, -120.898500], [37.736951, -120.844321], [37.811828, -120.905520]]], [[[37.490250, -121.006554], [37.565196, -121.067667], [37.647458, -121.013720], [37.722279, -121.074928], [37.804467, -121.020908], [37.879162, -121.082210], [37.871614, -121.197541], [37.789422, -121.251401], [37.714782, -121.190091], [37.632515, -121.243878], [37.557750, -121.182663], [37.475409, -121.236378], [37.400519, -121.175257], [37.318106, -121.228899], [37.243092, -121.167872], [37.160607, -121.221443], [37.085470, -121.160510], [37.002914, -121.214009], [36.995490, -121.328282], [36.912860, -121.381551], [36.905305, -121.495600], [36.822602, -121.548639], [36.814919, -121.662463], [36.732145, -121.715272], [36.724333, -121.828869], [36.799241, -121.889820], [36.791248, -122.003352], [36.865977, -122.064397], [36.857802, -122.177861], [36.932351, -122.239000], [36.923995, -122.352395], [36.998363, -122.413626], [36.989826, -122.526949], [37.064013, -122.588271], [37.055294, -122.701520], [36.972446, -122.753285], [36.898316, -122.691966], [36.906977, -122.578878], [36.832666, -122.517650], [36.841147, -122.404488], [36.766655, -122.343351], [36.774955, -122.230118], [36.700284, -122.169073], [36.708403, -122.055771], [36.633553, -121.994819], [36.641490, -121.881449], [36.566462, -121.820592], [36.574218, -121.707157], [36.657058, -121.654417], [36.664688, -121.540757], [36.747458, -121.487788], [36.754960, -121.373903], [36.837659, -121.320705], [36.845030, -121.206596], [36.927656, -121.153169], [36.934897, -121.038838], [37.017447, -120.985181], [37.092763, -121.046013], [37.175243, -120.992284], [37.250436, -121.053210], [37.332844, -120.999409], [37.407914, -121.060428]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonStdin1 "cellsToMultiPolygon -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test1.txt" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonStdin2 "cellsToMultiPolygon -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test2.txt" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]], [[[38.231228, -123.642760], [38.229797, -123.658996], [38.218020, -123.666324], [38.207675, -123.657418], [38.209105, -123.641184], [38.220882, -123.633853]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonStdin3 "cellsToMultiPolygon -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test3.txt" "[[[[37.106073, -122.020493], [37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726]], [[37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101], [37.337556, -122.090429], [37.420129, -122.037735]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonStdin4 "cellsToMultiPolygon -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test4.txt" "[[[[37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726], [37.106073, -122.020493]], [[37.337556, -122.090429], [37.420129, -122.037735], [37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101]]], [[[43.431278, -115.975237], [43.508096, -115.912429], [43.581386, -115.974912], [43.577810, -116.100258], [43.500970, -116.162919], [43.427727, -116.100382]]]]") +add_h3_cli_test(testCliCellsToMultiPolygonStdin5 "cellsToMultiPolygon -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test5.txt" "[[[[37.893933, -120.851267], [37.968684, -120.912560], [37.961273, -121.028117], [38.035842, -121.089514], [38.028243, -121.205013], [38.102628, -121.266514], [38.094842, -121.381953], [38.169044, -121.443555], [38.161070, -121.558932], [38.235088, -121.620634], [38.226927, -121.735948], [38.300760, -121.797749], [38.292411, -121.912997], [38.366059, -121.974896], [38.357522, -122.090075], [38.275391, -122.143187], [38.266721, -122.258129], [38.184513, -122.311004], [38.175712, -122.425707], [38.093428, -122.478345], [38.084496, -122.592809], [38.002138, -122.645211], [37.993077, -122.759435], [37.910647, -122.811600], [37.901458, -122.925582], [37.818957, -122.977512], [37.809642, -123.091252], [37.727072, -123.142946], [37.653813, -123.081070], [37.571172, -123.132698], [37.497785, -123.070917], [37.415075, -123.122480], [37.341561, -123.060795], [37.258782, -123.112292], [37.185142, -123.050702], [37.102296, -123.102134], [37.028530, -123.040638], [36.945618, -123.092005], [36.871727, -123.030604], [36.788751, -123.081906], [36.714736, -123.020599], [36.723641, -122.907984], [36.649445, -122.846765], [36.658170, -122.734072], [36.583794, -122.672942], [36.592340, -122.560174], [36.517784, -122.499133], [36.526150, -122.386293], [36.451416, -122.325343], [36.459602, -122.212431], [36.384689, -122.151573], [36.392695, -122.038593], [36.317605, -121.977827], [36.325432, -121.864780], [36.408404, -121.812338], [36.416106, -121.699065], [36.499012, -121.646395], [36.506587, -121.532897], [36.589424, -121.479999], [36.596872, -121.366277], [36.679638, -121.313150], [36.686957, -121.199205], [36.769651, -121.145849], [36.776840, -121.031683], [36.859460, -120.978099], [36.866518, -120.863712], [36.949062, -120.809899], [37.024556, -120.870629], [37.107030, -120.816743], [37.182402, -120.877566], [37.264805, -120.823607], [37.340054, -120.884523], [37.422384, -120.830491], [37.497511, -120.891502], [37.579767, -120.837396], [37.654769, -120.898500], [37.736951, -120.844321], [37.811828, -120.905520]]], [[[37.490250, -121.006554], [37.565196, -121.067667], [37.647458, -121.013720], [37.722279, -121.074928], [37.804467, -121.020908], [37.879162, -121.082210], [37.871614, -121.197541], [37.789422, -121.251401], [37.714782, -121.190091], [37.632515, -121.243878], [37.557750, -121.182663], [37.475409, -121.236378], [37.400519, -121.175257], [37.318106, -121.228899], [37.243092, -121.167872], [37.160607, -121.221443], [37.085470, -121.160510], [37.002914, -121.214009], [36.995490, -121.328282], [36.912860, -121.381551], [36.905305, -121.495600], [36.822602, -121.548639], [36.814919, -121.662463], [36.732145, -121.715272], [36.724333, -121.828869], [36.799241, -121.889820], [36.791248, -122.003352], [36.865977, -122.064397], [36.857802, -122.177861], [36.932351, -122.239000], [36.923995, -122.352395], [36.998363, -122.413626], [36.989826, -122.526949], [37.064013, -122.588271], [37.055294, -122.701520], [36.972446, -122.753285], [36.898316, -122.691966], [36.906977, -122.578878], [36.832666, -122.517650], [36.841147, -122.404488], [36.766655, -122.343351], [36.774955, -122.230118], [36.700284, -122.169073], [36.708403, -122.055771], [36.633553, -121.994819], [36.641490, -121.881449], [36.566462, -121.820592], [36.574218, -121.707157], [36.657058, -121.654417], [36.664688, -121.540757], [36.747458, -121.487788], [36.754960, -121.373903], [36.837659, -121.320705], [36.845030, -121.206596], [36.927656, -121.153169], [36.934897, -121.038838], [37.017447, -120.985181], [37.092763, -121.046013], [37.175243, -120.992284], [37.250436, -121.053210], [37.332844, -120.999409], [37.407914, -121.060428]]]]") add_h3_cli_test(testCliCellsToMultiPolygonArg1 "cellsToMultiPolygon -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test1.txt\\\\`\"" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]]]") add_h3_cli_test(testCliCellsToMultiPolygonArg2 "cellsToMultiPolygon -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test2.txt\\\\`\"" "[[[[37.784046, -122.427089], [37.772267, -122.434586], [37.761736, -122.425769], [37.762982, -122.409455], [37.752446, -122.400640], [37.753689, -122.384324], [37.765468, -122.376819], [37.776004, -122.385635], [37.774761, -122.401954], [37.785293, -122.410771]]], [[[38.231228, -123.642760], [38.229797, -123.658996], [38.218020, -123.666324], [38.207675, -123.657418], [38.209105, -123.641184], [38.220882, -123.633853]]]]") add_h3_cli_test(testCliCellsToMultiPolygonArg3 "cellsToMultiPolygon -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/multipolygon_test3.txt\\\\`\"" "[[[[37.106073, -122.020493], [37.114176, -121.906636], [37.196816, -121.853848], [37.204791, -121.739761], [37.287359, -121.686742], [37.361955, -121.747972], [37.444452, -121.694882], [37.518923, -121.756207], [37.510841, -121.870623], [37.585130, -121.932045], [37.576863, -122.046394], [37.494361, -122.099157], [37.485965, -122.213273], [37.403391, -122.265803], [37.329215, -122.204381], [37.246571, -122.256843], [37.172270, -122.195515], [37.180556, -122.081726]], [[37.428341, -121.923550], [37.353926, -121.862223], [37.271356, -121.915080], [37.263198, -122.029101], [37.337556, -122.090429], [37.420129, -122.037735]]]]") diff --git a/tests/cli/childPosToCell.txt b/tests/cli/childPosToCell.txt index 60f1e7398..0cf221b1f 100644 --- a/tests/cli/childPosToCell.txt +++ b/tests/cli/childPosToCell.txt @@ -1 +1 @@ -add_h3_cli_test(testCliChildPosToCell "childPosToCell -c 85283473fffffff -r 7 -p 42" "872834730ffffff") +add_h3_cli_test(testCliChildPosToCell "childPosToCell -c 85283473fffffff -r 7 -p 42 -f newline" "872834730ffffff") diff --git a/tests/cli/compactCells.txt b/tests/cli/compactCells.txt index 1873e9376..493b05375 100644 --- a/tests/cli/compactCells.txt +++ b/tests/cli/compactCells.txt @@ -1,9 +1,9 @@ -add_h3_cli_test(testCliCompactCellsFile1 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") -add_h3_cli_test(testCliCompactCellsFile2 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") -add_h3_cli_test(testCliCompactCellsFile3 "compactCells -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") -add_h3_cli_test(testCliCompactCellsStdin1 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") -add_h3_cli_test(testCliCompactCellsStdin2 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") -add_h3_cli_test(testCliCompactCellsStdin3 "compactCells -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") -add_h3_cli_test(testCliCompactCellsArg1 "compactCells -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt\\\\`\" | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") -add_h3_cli_test(testCliCompactCellsArg2 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt\\\\` | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") -add_h3_cli_test(testCliCompactCellsArg3 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt\\\\` | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsFile1 "compactCells -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsFile2 "compactCells -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsFile3 "compactCells -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsStdin1 "compactCells -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsStdin2 "compactCells -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsStdin3 "compactCells -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsArg1 "compactCells -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test1.txt\\\\`\" -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsArg2 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test2.txt\\\\` -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") +add_h3_cli_test(testCliCompactCellsArg3 "compactCells -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/compact_test3.txt\\\\` -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff,") diff --git a/tests/cli/directedEdgeToBoundary.txt b/tests/cli/directedEdgeToBoundary.txt index 537f75927..627b93654 100644 --- a/tests/cli/directedEdgeToBoundary.txt +++ b/tests/cli/directedEdgeToBoundary.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliDirectedEdgeToBoundary "directedEdgeToBoundary -c 115283473fffffff" "POLYGON((-122.0377349643 37.4201286777, -122.0904289290 37.3375560844, -122.0377349643 37.4201286777))") +add_h3_cli_test(testCliDirectedEdgeToBoundary "directedEdgeToBoundary -c 115283473fffffff -f wkt" "LINESTRING (-122.0377349643 37.4201286777, -122.0904289290 37.3375560844)") add_h3_cli_test(testCliNotDirectedEdgeToBoundary "directedEdgeToBoundary -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid") diff --git a/tests/cli/getDirectedEdgeDestination.txt b/tests/cli/getDirectedEdgeDestination.txt index 7a67f2a0b..301fdbc37 100644 --- a/tests/cli/getDirectedEdgeDestination.txt +++ b/tests/cli/getDirectedEdgeDestination.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliGetDirectedEdgeDestination "getDirectedEdgeDestination -c 115283473fffffff" "85283477fffffff") +add_h3_cli_test(testCliGetDirectedEdgeDestination "getDirectedEdgeDestination -c 115283473fffffff -f newline" "85283477fffffff") add_h3_cli_test(testCliDoNotGetDirectedEdgeDestination "getDirectedEdgeDestination -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid") diff --git a/tests/cli/getDirectedEdgeOrigin.txt b/tests/cli/getDirectedEdgeOrigin.txt index 770d26264..42c0c6d2b 100644 --- a/tests/cli/getDirectedEdgeOrigin.txt +++ b/tests/cli/getDirectedEdgeOrigin.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliGetDirectedEdgeOrigin "getDirectedEdgeOrigin -c 115283473fffffff" "85283473fffffff") +add_h3_cli_test(testCliGetDirectedEdgeOrigin "getDirectedEdgeOrigin -c 115283473fffffff -f newline" "85283473fffffff") add_h3_cli_test(testCliDoNotGetDirectedEdgeOrigin "getDirectedEdgeOrigin -c 85283473fffffff 2>&1" "Error 6: Directed edge argument was not valid") diff --git a/tests/cli/getIcosahedronFaces.txt b/tests/cli/getIcosahedronFaces.txt index 2bba69731..9087e3127 100644 --- a/tests/cli/getIcosahedronFaces.txt +++ b/tests/cli/getIcosahedronFaces.txt @@ -1 +1 @@ -add_h3_cli_test(testCliGetIcosahedronFaces "getIcosahedronFaces -c 81743ffffffffff" "3, 8, 13, 9, 4") +add_h3_cli_test(testCliGetIcosahedronFaces "getIcosahedronFaces -c 81743ffffffffff" "[3, 8, 13, 9, 4]") diff --git a/tests/cli/getPentagons.txt b/tests/cli/getPentagons.txt index fae729218..d769992a7 100644 --- a/tests/cli/getPentagons.txt +++ b/tests/cli/getPentagons.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliGetPentagons "getPentagons -r 0" "[\"8009fffffffffff\", \"801dfffffffffff\", \"8031fffffffffff\", \"804dfffffffffff\", \"8063fffffffffff\", \"8075fffffffffff\", \"807ffffffffffff\", \"8091fffffffffff\", \"80a7fffffffffff\", \"80c3fffffffffff\", \"80d7fffffffffff\", \"80ebfffffffffff\"]") +add_h3_cli_test(testCliGetPentagons "getPentagons -r 0" "[ \"8009fffffffffff\", \"801dfffffffffff\", \"8031fffffffffff\", \"804dfffffffffff\", \"8063fffffffffff\", \"8075fffffffffff\", \"807ffffffffffff\", \"8091fffffffffff\", \"80a7fffffffffff\", \"80c3fffffffffff\", \"80d7fffffffffff\", \"80ebfffffffffff\" ]") add_h3_cli_test(testCliDontGetPentagons "getPentagons -r 20 2>&1" "Error 4: Resolution argument was outside of acceptable range") diff --git a/tests/cli/getRes0Cells.txt b/tests/cli/getRes0Cells.txt index 4887e274f..028fe93b3 100644 --- a/tests/cli/getRes0Cells.txt +++ b/tests/cli/getRes0Cells.txt @@ -1 +1 @@ -add_h3_cli_test(testCliGetRes0Cells "getRes0Cells" "[\"8001fffffffffff\", \"8003fffffffffff\", \"8005fffffffffff\", \"8007fffffffffff\", \"8009fffffffffff\", \"800bfffffffffff\", \"800dfffffffffff\", \"800ffffffffffff\", \"8011fffffffffff\", \"8013fffffffffff\", \"8015fffffffffff\", \"8017fffffffffff\", \"8019fffffffffff\", \"801bfffffffffff\", \"801dfffffffffff\", \"801ffffffffffff\", \"8021fffffffffff\", \"8023fffffffffff\", \"8025fffffffffff\", \"8027fffffffffff\", \"8029fffffffffff\", \"802bfffffffffff\", \"802dfffffffffff\", \"802ffffffffffff\", \"8031fffffffffff\", \"8033fffffffffff\", \"8035fffffffffff\", \"8037fffffffffff\", \"8039fffffffffff\", \"803bfffffffffff\", \"803dfffffffffff\", \"803ffffffffffff\", \"8041fffffffffff\", \"8043fffffffffff\", \"8045fffffffffff\", \"8047fffffffffff\", \"8049fffffffffff\", \"804bfffffffffff\", \"804dfffffffffff\", \"804ffffffffffff\", \"8051fffffffffff\", \"8053fffffffffff\", \"8055fffffffffff\", \"8057fffffffffff\", \"8059fffffffffff\", \"805bfffffffffff\", \"805dfffffffffff\", \"805ffffffffffff\", \"8061fffffffffff\", \"8063fffffffffff\", \"8065fffffffffff\", \"8067fffffffffff\", \"8069fffffffffff\", \"806bfffffffffff\", \"806dfffffffffff\", \"806ffffffffffff\", \"8071fffffffffff\", \"8073fffffffffff\", \"8075fffffffffff\", \"8077fffffffffff\", \"8079fffffffffff\", \"807bfffffffffff\", \"807dfffffffffff\", \"807ffffffffffff\", \"8081fffffffffff\", \"8083fffffffffff\", \"8085fffffffffff\", \"8087fffffffffff\", \"8089fffffffffff\", \"808bfffffffffff\", \"808dfffffffffff\", \"808ffffffffffff\", \"8091fffffffffff\", \"8093fffffffffff\", \"8095fffffffffff\", \"8097fffffffffff\", \"8099fffffffffff\", \"809bfffffffffff\", \"809dfffffffffff\", \"809ffffffffffff\", \"80a1fffffffffff\", \"80a3fffffffffff\", \"80a5fffffffffff\", \"80a7fffffffffff\", \"80a9fffffffffff\", \"80abfffffffffff\", \"80adfffffffffff\", \"80affffffffffff\", \"80b1fffffffffff\", \"80b3fffffffffff\", \"80b5fffffffffff\", \"80b7fffffffffff\", \"80b9fffffffffff\", \"80bbfffffffffff\", \"80bdfffffffffff\", \"80bffffffffffff\", \"80c1fffffffffff\", \"80c3fffffffffff\", \"80c5fffffffffff\", \"80c7fffffffffff\", \"80c9fffffffffff\", \"80cbfffffffffff\", \"80cdfffffffffff\", \"80cffffffffffff\", \"80d1fffffffffff\", \"80d3fffffffffff\", \"80d5fffffffffff\", \"80d7fffffffffff\", \"80d9fffffffffff\", \"80dbfffffffffff\", \"80ddfffffffffff\", \"80dffffffffffff\", \"80e1fffffffffff\", \"80e3fffffffffff\", \"80e5fffffffffff\", \"80e7fffffffffff\", \"80e9fffffffffff\", \"80ebfffffffffff\", \"80edfffffffffff\", \"80effffffffffff\", \"80f1fffffffffff\", \"80f3fffffffffff\"]") +add_h3_cli_test(testCliGetRes0Cells "getRes0Cells" "[ \"8001fffffffffff\", \"8003fffffffffff\", \"8005fffffffffff\", \"8007fffffffffff\", \"8009fffffffffff\", \"800bfffffffffff\", \"800dfffffffffff\", \"800ffffffffffff\", \"8011fffffffffff\", \"8013fffffffffff\", \"8015fffffffffff\", \"8017fffffffffff\", \"8019fffffffffff\", \"801bfffffffffff\", \"801dfffffffffff\", \"801ffffffffffff\", \"8021fffffffffff\", \"8023fffffffffff\", \"8025fffffffffff\", \"8027fffffffffff\", \"8029fffffffffff\", \"802bfffffffffff\", \"802dfffffffffff\", \"802ffffffffffff\", \"8031fffffffffff\", \"8033fffffffffff\", \"8035fffffffffff\", \"8037fffffffffff\", \"8039fffffffffff\", \"803bfffffffffff\", \"803dfffffffffff\", \"803ffffffffffff\", \"8041fffffffffff\", \"8043fffffffffff\", \"8045fffffffffff\", \"8047fffffffffff\", \"8049fffffffffff\", \"804bfffffffffff\", \"804dfffffffffff\", \"804ffffffffffff\", \"8051fffffffffff\", \"8053fffffffffff\", \"8055fffffffffff\", \"8057fffffffffff\", \"8059fffffffffff\", \"805bfffffffffff\", \"805dfffffffffff\", \"805ffffffffffff\", \"8061fffffffffff\", \"8063fffffffffff\", \"8065fffffffffff\", \"8067fffffffffff\", \"8069fffffffffff\", \"806bfffffffffff\", \"806dfffffffffff\", \"806ffffffffffff\", \"8071fffffffffff\", \"8073fffffffffff\", \"8075fffffffffff\", \"8077fffffffffff\", \"8079fffffffffff\", \"807bfffffffffff\", \"807dfffffffffff\", \"807ffffffffffff\", \"8081fffffffffff\", \"8083fffffffffff\", \"8085fffffffffff\", \"8087fffffffffff\", \"8089fffffffffff\", \"808bfffffffffff\", \"808dfffffffffff\", \"808ffffffffffff\", \"8091fffffffffff\", \"8093fffffffffff\", \"8095fffffffffff\", \"8097fffffffffff\", \"8099fffffffffff\", \"809bfffffffffff\", \"809dfffffffffff\", \"809ffffffffffff\", \"80a1fffffffffff\", \"80a3fffffffffff\", \"80a5fffffffffff\", \"80a7fffffffffff\", \"80a9fffffffffff\", \"80abfffffffffff\", \"80adfffffffffff\", \"80affffffffffff\", \"80b1fffffffffff\", \"80b3fffffffffff\", \"80b5fffffffffff\", \"80b7fffffffffff\", \"80b9fffffffffff\", \"80bbfffffffffff\", \"80bdfffffffffff\", \"80bffffffffffff\", \"80c1fffffffffff\", \"80c3fffffffffff\", \"80c5fffffffffff\", \"80c7fffffffffff\", \"80c9fffffffffff\", \"80cbfffffffffff\", \"80cdfffffffffff\", \"80cffffffffffff\", \"80d1fffffffffff\", \"80d3fffffffffff\", \"80d5fffffffffff\", \"80d7fffffffffff\", \"80d9fffffffffff\", \"80dbfffffffffff\", \"80ddfffffffffff\", \"80dffffffffffff\", \"80e1fffffffffff\", \"80e3fffffffffff\", \"80e5fffffffffff\", \"80e7fffffffffff\", \"80e9fffffffffff\", \"80ebfffffffffff\", \"80edfffffffffff\", \"80effffffffffff\", \"80f1fffffffffff\", \"80f3fffffffffff\" ]") diff --git a/tests/cli/gridDiskDistances.txt b/tests/cli/gridDiskDistances.txt index ed59e0d23..373c75dea 100644 --- a/tests/cli/gridDiskDistances.txt +++ b/tests/cli/gridDiskDistances.txt @@ -1 +1 @@ -add_h3_cli_test(testCliGridDiskDistances "gridDiskDistances -c 85283473fffffff -k 1" "[[\"85283473fffffff\"],[\"85283447fffffff\",\"8528347bfffffff\",\"85283463fffffff\",\"85283477fffffff\",\"8528340ffffffff\",\"8528340bfffffff\"]]") +add_h3_cli_test(testCliGridDiskDistances "gridDiskDistances -c 85283473fffffff -k 1" "[[\"85283473fffffff\"], [\"85283447fffffff\", \"8528347bfffffff\", \"85283463fffffff\", \"85283477fffffff\", \"8528340ffffffff\", \"8528340bfffffff\"]]") diff --git a/tests/cli/latLngToCell.txt b/tests/cli/latLngToCell.txt index 0d682a3bb..4156f6a97 100644 --- a/tests/cli/latLngToCell.txt +++ b/tests/cli/latLngToCell.txt @@ -1 +1 @@ -add_h3_cli_test(testCliLatLngToCell "latLngToCell --lat 20 --lng 123 -r 2" "824b9ffffffffff") +add_h3_cli_test(testCliLatLngToCell "latLngToCell --lat 20 --lng 123 -r 2 -f newline" "824b9ffffffffff") diff --git a/tests/cli/localIjToCell.txt b/tests/cli/localIjToCell.txt index 3b69d4a2e..36272c154 100644 --- a/tests/cli/localIjToCell.txt +++ b/tests/cli/localIjToCell.txt @@ -1 +1 @@ -add_h3_cli_test(testCliLocalIjToCell "localIjToCell -o 85283473fffffff -i 25 -j 13" "8528342bfffffff") +add_h3_cli_test(testCliLocalIjToCell "localIjToCell -o 85283473fffffff -i 25 -j 13 -f newline" "8528342bfffffff") diff --git a/tests/cli/maxPolygonToCellsSize.txt b/tests/cli/maxPolygonToCellsSize.txt index f22d76b36..a164185d3 100644 --- a/tests/cli/maxPolygonToCellsSize.txt +++ b/tests/cli/maxPolygonToCellsSize.txt @@ -1,8 +1,8 @@ -add_h3_cli_test(testCliMaxPolygonToCellsSizeFile1 "maxPolygonToCellsSize -r 7 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt" "100") -add_h3_cli_test(testCliMaxPolygonToCellsSizeFile2 "maxPolygonToCellsSize -r 7 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt" "23") -add_h3_cli_test(testCliMaxPolygonToCellsSizeFile3 "maxPolygonToCellsSize -r 4 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt" "3484") -add_h3_cli_test(testCliMaxPolygonToCellsSizeStdin1 "maxPolygonToCellsSize -r 7 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt" "100") -add_h3_cli_test(testCliMaxPolygonToCellsSizeStdin2 "maxPolygonToCellsSize -r 7 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt" "23") -add_h3_cli_test(testCliMaxPolygonToCellsSizeStdin3 "maxPolygonToCellsSize -r 4 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt" "3484") +add_h3_cli_test(testCliMaxPolygonToCellsSizeFile1 "maxPolygonToCellsSize -r 7 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt" "100") +add_h3_cli_test(testCliMaxPolygonToCellsSizeFile2 "maxPolygonToCellsSize -r 7 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt" "23") +add_h3_cli_test(testCliMaxPolygonToCellsSizeFile3 "maxPolygonToCellsSize -r 4 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt" "3484") +add_h3_cli_test(testCliMaxPolygonToCellsSizeStdin1 "maxPolygonToCellsSize -r 7 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt" "100") +add_h3_cli_test(testCliMaxPolygonToCellsSizeStdin2 "maxPolygonToCellsSize -r 7 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt" "23") +add_h3_cli_test(testCliMaxPolygonToCellsSizeStdin3 "maxPolygonToCellsSize -r 4 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt" "3484") add_h3_cli_test(testCliMaxPolygonToCellsSizeArg1 "maxPolygonToCellsSize -r 7 -p \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt\\\\`\"" "100") add_h3_cli_test(testCliMaxPolygonToCellsSizeArg2 "maxPolygonToCellsSize -r 7 -p \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt\\\\`\"" "23") \ No newline at end of file diff --git a/tests/cli/polygonToCells.txt b/tests/cli/polygonToCells.txt index 455e8953f..9dbef7b3c 100644 --- a/tests/cli/polygonToCells.txt +++ b/tests/cli/polygonToCells.txt @@ -1,8 +1,8 @@ -add_h3_cli_test(testCliPolygonToCellsFile1 "polygonToCells -r 7 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "87283082bffffff,872830870ffffff,872830820ffffff,87283082effffff,872830828ffffff,87283082affffff,872830876ffffff,") -add_h3_cli_test(testCliPolygonToCellsFile2 "polygonToCells -r 7 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "872830828ffffff,87283082effffff,") -add_h3_cli_test(testCliPolygonToCellsFile3 "polygonToCells -r 4 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "84f05a3ffffffff,84e720bffffffff,84e7257ffffffff,84e725bffffffff,") -add_h3_cli_test(testCliPolygonToCellsStdin1 "polygonToCells -r 7 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "87283082bffffff,872830870ffffff,872830820ffffff,87283082effffff,872830828ffffff,87283082affffff,872830876ffffff,") -add_h3_cli_test(testCliPolygonToCellsStdin2 "polygonToCells -r 7 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "872830828ffffff,87283082effffff,") -add_h3_cli_test(testCliPolygonToCellsStdin3 "polygonToCells -r 4 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "84f05a3ffffffff,84e720bffffffff,84e7257ffffffff,84e725bffffffff,") -add_h3_cli_test(testCliPolygonToCellsArg1 "polygonToCells -r 7 -p \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt\\\\`\" | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "87283082bffffff,872830870ffffff,872830820ffffff,87283082effffff,872830828ffffff,87283082affffff,872830876ffffff,") -add_h3_cli_test(testCliPolygonToCellsArg2 "polygonToCells -r 7 -p \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt\\\\`\" | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "872830828ffffff,87283082effffff,") \ No newline at end of file +add_h3_cli_test(testCliPolygonToCellsFile1 "polygonToCells -r 7 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "87283082bffffff,872830870ffffff,872830820ffffff,87283082effffff,872830828ffffff,87283082affffff,872830876ffffff,") +add_h3_cli_test(testCliPolygonToCellsFile2 "polygonToCells -r 7 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "872830828ffffff,87283082effffff,") +add_h3_cli_test(testCliPolygonToCellsFile3 "polygonToCells -r 4 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "84f05a3ffffffff,84e720bffffffff,84e7257ffffffff,84e725bffffffff,") +add_h3_cli_test(testCliPolygonToCellsStdin1 "polygonToCells -r 7 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "87283082bffffff,872830870ffffff,872830820ffffff,87283082effffff,872830828ffffff,87283082affffff,872830876ffffff,") +add_h3_cli_test(testCliPolygonToCellsStdin2 "polygonToCells -r 7 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "872830828ffffff,87283082effffff,") +add_h3_cli_test(testCliPolygonToCellsStdin3 "polygonToCells -r 4 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test3.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "84f05a3ffffffff,84e720bffffffff,84e7257ffffffff,84e725bffffffff,") +add_h3_cli_test(testCliPolygonToCellsArg1 "polygonToCells -r 7 -p \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test1.txt\\\\`\" -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "87283082bffffff,872830870ffffff,872830820ffffff,87283082effffff,872830828ffffff,87283082affffff,872830876ffffff,") +add_h3_cli_test(testCliPolygonToCellsArg2 "polygonToCells -r 7 -p \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/polygon_test2.txt\\\\`\" -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "872830828ffffff,87283082effffff,") \ No newline at end of file diff --git a/tests/cli/uncompactCells.txt b/tests/cli/uncompactCells.txt index a75d1513f..ca114e2b6 100644 --- a/tests/cli/uncompactCells.txt +++ b/tests/cli/uncompactCells.txt @@ -1,9 +1,9 @@ -add_h3_cli_test(testCliUncompactCellsFile1 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") -add_h3_cli_test(testCliUncompactCellsFile2 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") -add_h3_cli_test(testCliUncompactCellsFile3 "uncompactCells -r 5 -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") -add_h3_cli_test(testCliUncompactCellsStdin1 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") -add_h3_cli_test(testCliUncompactCellsStdin2 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") -add_h3_cli_test(testCliUncompactCellsStdin3 "uncompactCells -r 5 -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") -add_h3_cli_test(testCliUncompactCellsArg1 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt\\\\`\" | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") -add_h3_cli_test(testCliUncompactCellsArg2 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt\\\\`\" | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") -add_h3_cli_test(testCliUncompactCellsArg3 "uncompactCells -r 5 -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt\\\\` | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsFile1 "uncompactCells -r 5 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsFile2 "uncompactCells -r 5 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsFile3 "uncompactCells -r 5 -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsStdin1 "uncompactCells -r 5 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsStdin2 "uncompactCells -r 5 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsStdin3 "uncompactCells -r 5 -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsArg1 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test1.txt\\\\`\" -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsArg2 "uncompactCells -r 5 -c \"\\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test2.txt\\\\`\" -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") +add_h3_cli_test(testCliUncompactCellsArg3 "uncompactCells -r 5 -c \\\\`cat ${PROJECT_SOURCE_DIR}/tests/inputfiles/uncompact_test3.txt\\\\` -f newline | tr -s '\\\\r\\\\n' ',' | tr -s '\\\\n' ','" "85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,85283463fffffff,85283467fffffff,8528346bfffffff,8528346ffffffff,85283473fffffff,85283477fffffff,8528347bfffffff,") diff --git a/tests/cli/vertexToLatLng.txt b/tests/cli/vertexToLatLng.txt index 7204b3d1c..3103833cb 100644 --- a/tests/cli/vertexToLatLng.txt +++ b/tests/cli/vertexToLatLng.txt @@ -1,2 +1,2 @@ -add_h3_cli_test(testCliVertexToLatLng "vertexToLatLng -c 22528340bfffffff" "POINT(-121.9150803271 37.2713558667)") +add_h3_cli_test(testCliVertexToLatLng "vertexToLatLng -c 22528340bfffffff -f wkt" "POINT(-121.9150803271 37.2713558667)") add_h3_cli_test(testCliNotVertexToLatLng "vertexToLatLng -c 85283473fffffff 2>&1" "Error 8: Vertex argument was not valid") From 3a515457e332a75e0b4f16095eeba487c40579da Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 17 Oct 2024 08:42:44 -0700 Subject: [PATCH 2/5] Update website docs --- website/docs/api/directededge.mdx | 16 ++++++--- website/docs/api/hierarchy.mdx | 58 +++++++++---------------------- website/docs/api/indexing.mdx | 19 +++++----- website/docs/api/inspection.mdx | 6 +++- website/docs/api/misc.mdx | 6 ++-- website/docs/api/regions.mdx | 16 ++++----- website/docs/api/traversal.mdx | 27 ++++++++------ website/docs/api/vertex.mdx | 10 ++++-- 8 files changed, 78 insertions(+), 80 deletions(-) diff --git a/website/docs/api/directededge.mdx b/website/docs/api/directededge.mdx index 5fe77948a..0be79a897 100644 --- a/website/docs/api/directededge.mdx +++ b/website/docs/api/directededge.mdx @@ -72,6 +72,7 @@ H3 4.1.0 -o, --origin Required. Origin H3 Cell -d, --destination Required. Destination H3 Cell -h, --help Show this help message. + -f, --format 'json' for true or false, 'numeric' for 1 or 0 (Default: json) ``` ```bash @@ -147,11 +148,12 @@ H3 4.1.0 -o, --origin Required. Origin H3 Cell -d, --destination Required. Destination H3 Cell -h, --help Show this help message. + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 cellsToDirectedEdge -o 85283473fffffff -d 85283477fffffff -115283473fffffff +"115283473fffffff" ``` @@ -221,6 +223,7 @@ H3 4.1.0 isValidDirectedEdge Checks if the provided H3 directed edge is actually valid -h, --help Show this help message. -c, --cell Required. H3 Cell + -f, --format 'json' for true or false, 'numeric' for 1 or 0 (Default: json) ``` ```bash @@ -294,11 +297,12 @@ H3 4.1.0 getDirectedEdgeOrigin Returns the origin cell from the directed edge -c, --cell Required. H3 Cell -h, --help Show this help message. + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 getDirectedEdgeOrigin -c 115283473fffffff -85283473fffffff +"85283473fffffff" ``` @@ -365,11 +369,12 @@ H3 4.1.0 getDirectedEdgeDestination Returns the destination cell from the directed edge -c, --cell Required. H3 Cell -h, --help Show this help message. + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 getDirectedEdgeDestination -c 115283473fffffff -85283477fffffff +"85283477fffffff" ``` @@ -436,6 +441,7 @@ H3 4.1.0 directedEdgeToCells Returns the origin, destination pair of cells from the directed edge -c, --cell Required. H3 Cell -h, --help Show this help message. + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash @@ -508,6 +514,7 @@ H3 4.1.0 originToDirectedEdges Returns all of the directed edges from the specified origin cell -c, --cell Required. H3 Cell -h, --help Show this help message. + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash @@ -581,11 +588,12 @@ H3 4.1.0 directedEdgeToBoundary Provides the coordinates defining the directed edge -c, --cell Required. H3 Cell -h, --help Show this help message. + -f, --format 'json' for [[lat, lng], ...], 'wkt' for a WKT POLYGON, 'newline' for lat\nlng\n... (Default: json) ``` ```bash $ h3 directedEdgeToBoundary -c 115283473fffffff -POLYGON((-122.0377349643 37.4201286777, -122.0904289290 37.3375560844, -122.0377349643 37.4201286777)) +[[37.4201286777, -122.0377349643], [37.3375560844, -122.0904289290]] ``` diff --git a/website/docs/api/hierarchy.mdx b/website/docs/api/hierarchy.mdx index 6ca5012a6..95c007da2 100644 --- a/website/docs/api/hierarchy.mdx +++ b/website/docs/api/hierarchy.mdx @@ -70,11 +70,12 @@ H3 4.1.0 -h, --help Show this help message. -c, --cell Required. H3 Cell -r, --resolution Required. Resolution, 0-14 inclusive, excluding 15 as it can never be a parent + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 cellToParent -c 85283473fffffff -r 4 -8428347ffffffff +"8428347ffffffff" ``` @@ -137,13 +138,14 @@ h3.cell_to_children(cell, child_res) ```sh $ h3 cellToChildren --help -h3: Returns a JSON array of H3 indexes that are the children (or lower) of the provided cell +h3: Returns an array of H3 indexes that are the children (or lower) of the provided cell H3 4.1.0 - cellToChildren Returns a JSON array of H3 indexes that are the children (or lower) of the provided cell + cellToChildren Returns an array of H3 indexes that are the children (or lower) of the provided cell -h, --help Show this help message. -c, --cell Required. H3 Cell -r, --resolution Required. Resolution, 1-15 inclusive, excluding 0 as it can never be a child + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash @@ -290,11 +292,12 @@ H3 4.1.0 -h, --help Show this help message. -c, --cell Required. H3 Cell -r, --resolution Required. Resolution, 1-15 inclusive, excluding 0 as it can never be a child + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 cellToCenterChild -c 85283473fffffff -r 7 -872834700ffffff +"872834700ffffff" ``` @@ -440,11 +443,12 @@ H3 4.1.0 -c, --cell Required. H3 Cell -r, --resolution Required. Resolution, 1-15 inclusive, excluding 0 as it can never be a child -p, --position Required. The child position within the set of children of the parent cell + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 childPosToCell -p 42 -c 85283473fffffff -r 7 -872834730ffffff +"872834730ffffff" ``` @@ -508,30 +512,19 @@ h3.compact_cells(cells) ```sh $ h3 compactCells --help -h3: Compacts the provided set of cells as best as possible. The set of input cells must all share the same resolution. The compacted cells will be printed one per line to stdout. +h3: Compacts the provided set of cells as best as possible. The set of input cells must all share the same resolution. H3 4.1.0 - compactCells Compacts the provided set of cells as best as possible. The set of input cells must all share the same resolution. The compacted cells will be printed one per line to stdout. + compactCells Compacts the provided set of cells as best as possible. The set of input cells must all share the same resolution. -h, --help Show this help message. - -f, --file The file to load the cells from. Use -- to read from stdin. + -i, --file The file to load the cells from. Use -- to read from stdin. -c, --cells The cells to compact. Up to 100 cells if provided as hexadecimals with zero padding. + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash $ h3 compactCells -c 85283473fffffff,85283447fffffff,8528347bfffffff,85283463fffffff,85283477fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528346bfffffff,8528346ffffffff,85283467fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff -85283447fffffff -8528340ffffffff -8528340bfffffff -85283457fffffff -85283443fffffff -8528344ffffffff -852836b7fffffff -8528342bfffffff -8528343bfffffff -85283407fffffff -85283403fffffff -8528341bfffffff -8428347ffffffff +[ "85283447fffffff", "8528340ffffffff", "8528340bfffffff", "85283457fffffff", "85283443fffffff", "8528344ffffffff", "852836b7fffffff", "8528342bfffffff", "8528343bfffffff", "85283407fffffff", "85283403fffffff", "8528341bfffffff", "8428347ffffffff" ] ``` @@ -601,32 +594,15 @@ H3 4.1.0 uncompactCells Unompacts the provided set of compacted cells.The uncompacted cells will be printed one per line to stdout. -h, --help Show this help message. - -f, --file The file to load the cells from. Use -- to read from stdin. + -i, --file The file to load the cells from. Use -- to read from stdin. -c, --cells The cells to uncompact. Up to 100 cells if provided as hexadecimals with zero padding. -r, --resolution Required. Resolution, 0-15 inclusive, that the compacted set should be uncompacted to. Must be greater than or equal to the highest resolution within the compacted set. + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash $ h3 uncompactCells -r 5 -c 85283447fffffff,8528340ffffffff,8528340bfffffff,85283457fffffff,85283443fffffff,8528344ffffffff,852836b7fffffff,8528342bfffffff,8528343bfffffff,85283407fffffff,85283403fffffff,8528341bfffffff,8428347ffffffff -85283447fffffff -8528340ffffffff -8528340bfffffff -85283457fffffff -85283443fffffff -8528344ffffffff -852836b7fffffff -8528342bfffffff -8528343bfffffff -85283407fffffff -85283403fffffff -8528341bfffffff -85283463fffffff -85283467fffffff -8528346bfffffff -8528346ffffffff -85283473fffffff -85283477fffffff -8528347bfffffff +[ "85283447fffffff", "8528340ffffffff", "8528340bfffffff", "85283457fffffff", "85283443fffffff", "8528344ffffffff", "852836b7fffffff", "8528342bfffffff", "8528343bfffffff", "85283407fffffff", "85283403fffffff", "8528341bfffffff", "85283463fffffff", "85283467fffffff", "8528346bfffffff", "8528346ffffffff", "85283473fffffff", "85283477fffffff", "8528347bfffffff" ] ``` diff --git a/website/docs/api/indexing.mdx b/website/docs/api/indexing.mdx index fc27b8d68..5809b6794 100644 --- a/website/docs/api/indexing.mdx +++ b/website/docs/api/indexing.mdx @@ -71,13 +71,14 @@ H3 4.1.0 latLngToCell Convert degrees latitude/longitude coordinate to an H3 cell -h, --help Show this help message. -r, --resolution Required. Resolution, 0-15 inclusive. - --lat, --latitude Required. Latitude in degrees. + --lat, --latitude Required. Latitude in degrees. --lng, --longitude Required. Longitude in degrees. + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 latLngToCell --lat 45 --lng 40 -r 2 -822d57fffffffff +"822d57fffffffff" ``` @@ -141,17 +142,18 @@ h3.cell_to_latlng(cell) ```sh $ h3 cellToLatLng --help -h3: Convert an H3Cell to a WKT POINT coordinate +h3: Convert an H3Cell to a coordinate H3 4.1.0 - cellToLatLng Convert an H3Cell to a WKT POINT coordinate + cellToLatLng Convert an H3Cell to a coordinate -h, --help Show this help message. -c, --cell Required. H3 Cell + -f, --format 'json' for [lat, lng], 'wkt' for a WKT POINT, 'newline' for lat\nlng\n (Default: json) ``` ```bash $ h3 cellToLatLng -c 85283473fffffff -POINT(-121.9763759726 37.3457933754) +[37.3457933754, -121.9763759726] ``` @@ -221,17 +223,18 @@ h3.cell_to_boundary(cell, geo_json=False) ```sh $ h3 cellToBoundary --help -h3: Convert an H3 cell to a WKT POLYGON defining its boundary +h3: Convert an H3 cell to a polygon defining its boundary H3 4.1.0 - cellToBoundary Convert an H3 cell to a WKT POLYGON defining its boundary + cellToBoundary Convert an H3 cell to a polygon defining its boundary -h, --help Show this help message. -c, --cell Required. H3 Cell + -f, --format 'json' for [[lat, lng], ...], 'wkt' for a WKT POLYGON, 'newline' for lat\nlng\n... (Default: json) ``` ```bash $ h3 cellToBoundary -c 85283473fffffff -POLYGON((-121.9150803271 37.2713558667, -121.8622232890 37.3539264509, -121.9235499963 37.4283411861, -122.0377349643 37.4201286777, -122.0904289290 37.3375560844, -122.0291013092 37.2631979746, -121.9150803271 37.2713558667)) +[[37.2713558667, -121.9150803271], [37.3539264509, -121.8622232890], [37.4283411861, -121.9235499963], [37.4201286777, -122.0377349643], [37.3375560844, -122.0904289290], [37.2631979746, -122.0291013092]] ``` diff --git a/website/docs/api/inspection.mdx b/website/docs/api/inspection.mdx index 24a156399..53aadf62f 100644 --- a/website/docs/api/inspection.mdx +++ b/website/docs/api/inspection.mdx @@ -306,6 +306,7 @@ H3 4.1.0 isValidCell Checks if the provided H3 index is actually valid -h, --help Show this help message. -c, --cell Required. H3 Cell + -f, --format 'json' for true or false, 'numeric' for 1 or 0 (Default: json) ``` ```bash @@ -377,6 +378,7 @@ H3 4.1.0 isResClassIII Checks if the provided H3 index has a Class III orientation -h, --help Show this help message. -c, --cell Required. H3 Cell + -f, --format 'json' for true or false, 'numeric' for 1 or 0 (Default: json) ``` ```bash @@ -448,6 +450,7 @@ H3 4.1.0 isPentagon Checks if the provided H3 index is a pentagon instead of a hexagon -h, --help Show this help message. -c, --cell Required. H3 Cell + -f, --format 'json' for true or false, 'numeric' for 1 or 0 (Default: json) ``` ```bash @@ -519,11 +522,12 @@ H3 4.1.0 getIcosahedronFaces Returns the icosahedron face numbers (0 - 19) that the H3 index intersects -h, --help Show this help message. -c, --cell Required. H3 Cell + -f, --format 'json' for [faceNum, ...], 'newline' for faceNum\n... (Default: json) ``` ```bash $ h3 getIcosahedronFaces -c 85283473fffffff -7 +[7] ``` diff --git a/website/docs/api/misc.mdx b/website/docs/api/misc.mdx index 0255dba7c..ffa70c549 100644 --- a/website/docs/api/misc.mdx +++ b/website/docs/api/misc.mdx @@ -994,11 +994,12 @@ H3 4.1.0 getRes0Cells Returns all of the resolution 0 cells -h, --help Show this help message. + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash $ h3 getRes0Cells -["8001fffffffffff", "8003fffffffffff", "8005fffffffffff", "8007fffffffffff", "8009fffffffffff", "800bfffffffffff", "800dfffffffffff", "800ffffffffffff", "8011fffffffffff", "8013fffffffffff", "8015fffffffffff", "8017fffffffffff", "8019fffffffffff", "801bfffffffffff", "801dfffffffffff", "801ffffffffffff", "8021fffffffffff", "8023fffffffffff", "8025fffffffffff", "8027fffffffffff", "8029fffffffffff", "802bfffffffffff", "802dfffffffffff", "802ffffffffffff", "8031fffffffffff", "8033fffffffffff", "8035fffffffffff", "8037fffffffffff", "8039fffffffffff", "803bfffffffffff", "803dfffffffffff", "803ffffffffffff", "8041fffffffffff", "8043fffffffffff", "8045fffffffffff", "8047fffffffffff", "8049fffffffffff", "804bfffffffffff", "804dfffffffffff", "804ffffffffffff", "8051fffffffffff", "8053fffffffffff", "8055fffffffffff", "8057fffffffffff", "8059fffffffffff", "805bfffffffffff", "805dfffffffffff", "805ffffffffffff", "8061fffffffffff", "8063fffffffffff", "8065fffffffffff", "8067fffffffffff", "8069fffffffffff", "806bfffffffffff", "806dfffffffffff", "806ffffffffffff", "8071fffffffffff", "8073fffffffffff", "8075fffffffffff", "8077fffffffffff", "8079fffffffffff", "807bfffffffffff", "807dfffffffffff", "807ffffffffffff", "8081fffffffffff", "8083fffffffffff", "8085fffffffffff", "8087fffffffffff", "8089fffffffffff", "808bfffffffffff", "808dfffffffffff", "808ffffffffffff", "8091fffffffffff", "8093fffffffffff", "8095fffffffffff", "8097fffffffffff", "8099fffffffffff", "809bfffffffffff", "809dfffffffffff", "809ffffffffffff", "80a1fffffffffff", "80a3fffffffffff", "80a5fffffffffff", "80a7fffffffffff", "80a9fffffffffff", "80abfffffffffff", "80adfffffffffff", "80affffffffffff", "80b1fffffffffff", "80b3fffffffffff", "80b5fffffffffff", "80b7fffffffffff", "80b9fffffffffff", "80bbfffffffffff", "80bdfffffffffff", "80bffffffffffff", "80c1fffffffffff", "80c3fffffffffff", "80c5fffffffffff", "80c7fffffffffff", "80c9fffffffffff", "80cbfffffffffff", "80cdfffffffffff", "80cffffffffffff", "80d1fffffffffff", "80d3fffffffffff", "80d5fffffffffff", "80d7fffffffffff", "80d9fffffffffff", "80dbfffffffffff", "80ddfffffffffff", "80dffffffffffff", "80e1fffffffffff", "80e3fffffffffff", "80e5fffffffffff", "80e7fffffffffff", "80e9fffffffffff", "80ebfffffffffff", "80edfffffffffff", "80effffffffffff", "80f1fffffffffff", "80f3fffffffffff"] +[ "8001fffffffffff", "8003fffffffffff", "8005fffffffffff", "8007fffffffffff", "8009fffffffffff", "800bfffffffffff", "800dfffffffffff", "800ffffffffffff", "8011fffffffffff", "8013fffffffffff", "8015fffffffffff", "8017fffffffffff", "8019fffffffffff", "801bfffffffffff", "801dfffffffffff", "801ffffffffffff", "8021fffffffffff", "8023fffffffffff", "8025fffffffffff", "8027fffffffffff", "8029fffffffffff", "802bfffffffffff", "802dfffffffffff", "802ffffffffffff", "8031fffffffffff", "8033fffffffffff", "8035fffffffffff", "8037fffffffffff", "8039fffffffffff", "803bfffffffffff", "803dfffffffffff", "803ffffffffffff", "8041fffffffffff", "8043fffffffffff", "8045fffffffffff", "8047fffffffffff", "8049fffffffffff", "804bfffffffffff", "804dfffffffffff", "804ffffffffffff", "8051fffffffffff", "8053fffffffffff", "8055fffffffffff", "8057fffffffffff", "8059fffffffffff", "805bfffffffffff", "805dfffffffffff", "805ffffffffffff", "8061fffffffffff", "8063fffffffffff", "8065fffffffffff", "8067fffffffffff", "8069fffffffffff", "806bfffffffffff", "806dfffffffffff", "806ffffffffffff", "8071fffffffffff", "8073fffffffffff", "8075fffffffffff", "8077fffffffffff", "8079fffffffffff", "807bfffffffffff", "807dfffffffffff", "807ffffffffffff", "8081fffffffffff", "8083fffffffffff", "8085fffffffffff", "8087fffffffffff", "8089fffffffffff", "808bfffffffffff", "808dfffffffffff", "808ffffffffffff", "8091fffffffffff", "8093fffffffffff", "8095fffffffffff", "8097fffffffffff", "8099fffffffffff", "809bfffffffffff", "809dfffffffffff", "809ffffffffffff", "80a1fffffffffff", "80a3fffffffffff", "80a5fffffffffff", "80a7fffffffffff", "80a9fffffffffff", "80abfffffffffff", "80adfffffffffff", "80affffffffffff", "80b1fffffffffff", "80b3fffffffffff", "80b5fffffffffff", "80b7fffffffffff", "80b9fffffffffff", "80bbfffffffffff", "80bdfffffffffff", "80bffffffffffff", "80c1fffffffffff", "80c3fffffffffff", "80c5fffffffffff", "80c7fffffffffff", "80c9fffffffffff", "80cbfffffffffff", "80cdfffffffffff", "80cffffffffffff", "80d1fffffffffff", "80d3fffffffffff", "80d5fffffffffff", "80d7fffffffffff", "80d9fffffffffff", "80dbfffffffffff", "80ddfffffffffff", "80dffffffffffff", "80e1fffffffffff", "80e3fffffffffff", "80e5fffffffffff", "80e7fffffffffff", "80e9fffffffffff", "80ebfffffffffff", "80edfffffffffff", "80effffffffffff", "80f1fffffffffff", "80f3fffffffffff" ] ``` @@ -1127,11 +1128,12 @@ H3 4.1.0 getPentagons Returns all of the pentagons at the specified resolution -r, --resolution Required. Resolution, 0-15 inclusive. -h, --help Show this help message. + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash $ h3 getPentagons -r 5 -["85080003fffffff", "851c0003fffffff", "85300003fffffff", "854c0003fffffff", "85620003fffffff", "85740003fffffff", "857e0003fffffff", "85900003fffffff", "85a60003fffffff", "85c20003fffffff", "85d60003fffffff", "85ea0003fffffff"] +[ "85080003fffffff", "851c0003fffffff", "85300003fffffff", "854c0003fffffff", "85620003fffffff", "85740003fffffff", "857e0003fffffff", "85900003fffffff", "85a60003fffffff", "85c20003fffffff", "85d60003fffffff", "85ea0003fffffff" ] ``` diff --git a/website/docs/api/regions.mdx b/website/docs/api/regions.mdx index 4d9336e08..62dfad9b6 100644 --- a/website/docs/api/regions.mdx +++ b/website/docs/api/regions.mdx @@ -73,20 +73,15 @@ H3 4.1.0 polygonToCells Converts a polygon (array of lat, lng points, or array of arrays of lat, lng points) into a set of covering cells at the specified resolution -h, --help Show this help message. - -f, --file The file to load the polygon from. Use -- to read from stdin. - -p, --polygon The polygon to convert. Up to 1500 characters. + -i, --file The file to load the polygon from. Use -- to read from stdin. + -p, --polygon The polygon to convert. Up to 1500 characters. -r, --resolution Required. Resolution, 0-15 inclusive, that the polygon should be converted to. + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash $ h3 polygonToCells -r 7 -p "[[37.813318999983238, -122.4089866999972145], [37.7198061999978478, -122.3544736999993603], [37.8151571999998453, -122.4798767000009008]]" -87283082bffffff -872830870ffffff -872830820ffffff -87283082effffff -872830828ffffff -87283082affffff -872830876ffffff +[ "87283082bffffff", "872830870ffffff", "872830820ffffff", "87283082effffff", "872830828ffffff", "87283082affffff", "872830876ffffff" ] ``` @@ -235,8 +230,9 @@ H3 4.1.0 cellsToMultiPolygon Returns a polygon (array of arrays of lat, lng points) for a set of cells -h, --help Show this help message. - -f, --file The file to load the cells from. Use -- to read from stdin. + -i, --file The file to load the cells from. Use -- to read from stdin. -c, --cells The cells to convert. Up to 100 cells if provided as hexadecimals with zero padding. + -f, --format 'json' for [[[[lat, lng],...],...],...] 'wkt' for a WKT MULTIPOLYGON ``` ```bash diff --git a/website/docs/api/traversal.mdx b/website/docs/api/traversal.mdx index 2dd0789e1..3b506667a 100644 --- a/website/docs/api/traversal.mdx +++ b/website/docs/api/traversal.mdx @@ -64,13 +64,14 @@ h3.grid_disk(origin, k) ```sh $ h3 gridDisk --help -h3: Returns a JSON array of a H3 cells within 'k' steps of the origin cell +h3: Returns an array of a H3 cells within 'k' steps of the origin cell H3 4.1.0 - gridDisk Returns a JSON array of a H3 cells within 'k' steps of the origin cell + gridDisk Returns an array of a H3 cells within 'k' steps of the origin cell -h, --help Show this help message. -c, --cell Required. H3 Cell -k Required. Maximum grid distance for the output set + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash @@ -204,19 +205,19 @@ h3.grid_disk_distances(origin, k) ```sh $ h3 gridDiskDistances --help -h3: Returns a JSON array of arrays of H3 cells, each array containing cells 'k' steps away from the origin cell, based on the outer array index +h3: Returns an array of arrays of H3 cells, each array containing cells 'k' steps away from the origin cell, based on the outer array index H3 4.1.0 - gridDiskDistances Returns a JSON array of arrays of H3 cells, each array containing cells 'k' steps away from the origin cell, based on the outer array index + gridDiskDistances Returns an array of arrays of H3 cells, each array containing cells 'k' steps away from the origin cell, based on the outer array index -h, --help Show this help message. -c, --cell Required. H3 Cell -k Required. Maximum grid distance for the output set - -p, --pretty-print Determine if the JSON output should be pretty printed or not + -f, --format 'json' for [["CELL", ...], ...], 'newline' for CELL\n with an extra newline between rings (Default: json) ``` ```bash $ h3 gridDiskDistances -k 5 -c 85283473fffffff -[["85283473fffffff"],["85283447fffffff","8528347bfffffff","85283463fffffff","85283477fffffff","8528340ffffffff","8528340bfffffff"],["85283457fffffff","85283443fffffff","8528344ffffffff","852836b7fffffff","8528346bfffffff","8528346ffffffff","85283467fffffff","8528342bfffffff","8528343bfffffff","85283407fffffff","85283403fffffff","8528341bfffffff"],["852834cffffffff","85283453fffffff","8528345bfffffff","8528344bfffffff","852836b3fffffff","852836a3fffffff","852836a7fffffff","852830d3fffffff","852830d7fffffff","8528309bfffffff","85283093fffffff","8528342ffffffff","85283423fffffff","85283433fffffff","852834abfffffff","85283417fffffff","85283413fffffff","852834c7fffffff"],["852834c3fffffff","852834cbfffffff","8529a927fffffff","8529a92ffffffff","85283697fffffff","85283687fffffff","852836bbfffffff","852836abfffffff","852836affffffff","852830dbfffffff","852830c3fffffff","852830c7fffffff","8528308bfffffff","85283083fffffff","85283097fffffff","8528355bfffffff","85283427fffffff","85283437fffffff","852834affffffff","852834a3fffffff","852834bbfffffff","8528348ffffffff","8528348bfffffff","852834d7fffffff"],["852834d3fffffff","852834dbfffffff","8529a937fffffff","8529a923fffffff","8529a92bfffffff","85283693fffffff","85283683fffffff","8528368ffffffff","85283617fffffff","85283607fffffff","85283633fffffff","85283637fffffff","852830cbfffffff","852830cffffffff","8528301bfffffff","85283013fffffff","8528308ffffffff","85283087fffffff","8528354bfffffff","85283543fffffff","85283553fffffff","852835cbfffffff","852835dbfffffff","852834a7fffffff","852834b7fffffff","852834b3fffffff","85283487fffffff","85283483fffffff","8528349bfffffff","85291a6ffffffff"]] +[["85283473fffffff"], ["85283447fffffff", "8528347bfffffff", "85283463fffffff", "85283477fffffff", "8528340ffffffff", "8528340bfffffff"], ["85283457fffffff", "85283443fffffff", "8528344ffffffff", "852836b7fffffff", "8528346bfffffff", "8528346ffffffff", "85283467fffffff", "8528342bfffffff", "8528343bfffffff", "85283407fffffff", "85283403fffffff", "8528341bfffffff"], ["852834cffffffff", "85283453fffffff", "8528345bfffffff", "8528344bfffffff", "852836b3fffffff", "852836a3fffffff", "852836a7fffffff", "852830d3fffffff", "852830d7fffffff", "8528309bfffffff", "85283093fffffff", "8528342ffffffff", "85283423fffffff", "85283433fffffff", "852834abfffffff", "85283417fffffff", "85283413fffffff", "852834c7fffffff"], ["852834c3fffffff", "852834cbfffffff", "8529a927fffffff", "8529a92ffffffff", "85283697fffffff", "85283687fffffff", "852836bbfffffff", "852836abfffffff", "852836affffffff", "852830dbfffffff", "852830c3fffffff", "852830c7fffffff", "8528308bfffffff", "85283083fffffff", "85283097fffffff", "8528355bfffffff", "85283427fffffff", "85283437fffffff", "852834affffffff", "852834a3fffffff", "852834bbfffffff", "8528348ffffffff", "8528348bfffffff", "852834d7fffffff"], ["852834d3fffffff", "852834dbfffffff", "8529a937fffffff", "8529a923fffffff", "8529a92bfffffff", "85283693fffffff", "85283683fffffff", "8528368ffffffff", "85283617fffffff", "85283607fffffff", "85283633fffffff", "85283637fffffff", "852830cbfffffff", "852830cffffffff", "8528301bfffffff", "85283013fffffff", "8528308ffffffff", "85283087fffffff", "8528354bfffffff", "85283543fffffff", "85283553fffffff", "852835cbfffffff", "852835dbfffffff", "852834a7fffffff", "852834b7fffffff", "852834b3fffffff", "85283487fffffff", "85283483fffffff", "8528349bfffffff", "85291a6ffffffff"]] ``` @@ -557,13 +558,14 @@ The shell uses `gridRingUnsafe` internally to generate the results, but on failu ```sh $ h3 gridRing --help -h3: Returns a JSON array of H3 cells, each cell 'k' steps away from the origin cell +h3: Returns an array of H3 cells, each cell 'k' steps away from the origin cell H3 4.1.0 - gridRing Returns a JSON array of H3 cells, each cell 'k' steps away from the origin cell + gridRing Returns an array of H3 cells, each cell 'k' steps away from the origin cell -h, --help Show this help message. -c, --cell Required. H3 Cell -k Required. Maximum grid distance for the output set + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash @@ -632,13 +634,14 @@ h3.grid_path_cells(start, end) ```sh $ h3 gridPathCells --help -h3: Returns a JSON array of H3 cells from the origin cell to the destination cell (inclusive) +h3: Returns an array of H3 cells from the origin cell to the destination cell (inclusive) H3 4.1.0 - gridPathCells Returns a JSON array of H3 cells from the origin cell to the destination cell (inclusive) + gridPathCells Returns an array of H3 cells from the origin cell to the destination cell (inclusive) -h, --help Show this help message. -o, --origin Required. The origin H3 cell -d, --destination Required. The destination H3 cell + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash @@ -868,6 +871,7 @@ H3 4.1.0 -h, --help Show this help message. -c, --cell Required. H3 Cell -o, --origin Required. The origin H3 cell + -f, --format 'json' for [I, J], 'newline' for I\nJ\n (Default: json) ``` ```bash @@ -947,11 +951,12 @@ H3 4.1.0 -o, --origin Required. The origin H3 cell -i Required. The I dimension of the IJ coordinate -j Required. The J dimension of the IJ coordinate + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 localIjToCell -o 85283473fffffff -i 0 -j 0 -85280003fffffff +"85280003fffffff" ``` diff --git a/website/docs/api/vertex.mdx b/website/docs/api/vertex.mdx index bf011c538..1f1a0e6d5 100644 --- a/website/docs/api/vertex.mdx +++ b/website/docs/api/vertex.mdx @@ -71,11 +71,12 @@ H3 4.1.0 -c, --cell Required. H3 Cell -v, --vertex Required. Vertex index number. 0-5 for hexagons, 0-4 for pentagons -h, --help Show this help message. + -f, --format 'json' for "CELL"\n, 'newline' for CELL\n (Default: json) ``` ```bash $ h3 cellToVertex -v 2 -c 85283473fffffff -205283463fffffff +"205283463fffffff" ``` @@ -143,11 +144,12 @@ H3 4.1.0 cellToVertexes Returns all of the vertexes from the specified cell -c, --cell Required. H3 Cell -h, --help Show this help message. + -f, --format 'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json) ``` ```bash $ h3 cellToVertexes -c 85283473fffffff -["22528340bfffffff", "235283447fffffff", "205283463fffffff", "255283463fffffff", "22528340ffffffff", "23528340bfffffff"] +[ "22528340bfffffff", "235283447fffffff", "205283463fffffff", "255283463fffffff", "22528340ffffffff", "23528340bfffffff" ] ``` @@ -217,11 +219,12 @@ H3 4.1.0 vertexToLatLng Returns the lat, lng pair for the given vertex -c, --cell Required. H3 Cell -h, --help Show this help message. + -f, --format 'json' for [lat, lng], 'wkt' for a WKT POINT, 'newline' for lat\nlng\n (Default: json) ``` ```bash $ h3 vertexToLatLng -c 255283463fffffff -POINT(-122.0377349643 37.4201286777) +[37.4201286777, -122.0377349643] ``` @@ -288,6 +291,7 @@ H3 4.1.0 isValidVertex Checks if the provided H3 vertex is actually valid -h, --help Show this help message. -c, --cell Required. H3 Cell + -f, --format 'json' for true or false, 'numeric' for 1 or 0 (Default: json) ``` ```bash From 82c93b2defc84860d8a273824caa10850da93a65 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 17 Oct 2024 08:43:58 -0700 Subject: [PATCH 3/5] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f82b06bba..c0c621560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The public API of this library consists of the functions declared in file ## [Unreleased] ### Added -- `h3` binary for shell scripts ready for use (#818, #826, #846, #923, #924, #931) +- `h3` binary for shell scripts ready for use (#818, #826, #846, #923, #924, #931, #933) ### Fixed - Fixed compacting all or many resolution 1 cells (#919) From 1c63fca3f0d0d94e9ea72dbd28a1c2f4237ed98a Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 17 Oct 2024 09:02:37 -0700 Subject: [PATCH 4/5] Fix some stragglers still using -f for files instead of formatting --- src/apps/filters/h3.c | 6 +++--- tests/cli/greatCircleDistanceKm.txt | 4 ++-- tests/cli/greatCircleDistanceM.txt | 4 ++-- tests/cli/greatCircleDistanceRads.txt | 4 ++-- website/docs/api/misc.mdx | 8 ++++---- website/docs/api/regions.mdx | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index fc767447a..f45d03404 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -2696,7 +2696,7 @@ SUBCOMMAND(greatCircleDistanceRads, "Calculates the 'great circle' or 'haversine' distance between two " "lat, lng points, in radians") { char filename[1024] = {0}; // More than Windows, lol - Arg filenameArg = {.names = {"-f", "--file"}, + Arg filenameArg = {.names = {"-i", "--file"}, .scanFormat = "%1023c", .valueName = "FILENAME", .value = &filename, @@ -2767,7 +2767,7 @@ SUBCOMMAND(greatCircleDistanceKm, "Calculates the 'great circle' or 'haversine' distance between two " "lat, lng points, in kilometers") { char filename[1024] = {0}; // More than Windows, lol - Arg filenameArg = {.names = {"-f", "--file"}, + Arg filenameArg = {.names = {"-i", "--file"}, .scanFormat = "%1023c", .valueName = "FILENAME", .value = &filename, @@ -2838,7 +2838,7 @@ SUBCOMMAND(greatCircleDistanceM, "Calculates the 'great circle' or 'haversine' distance between two " "lat, lng points, in meters") { char filename[1024] = {0}; // More than Windows, lol - Arg filenameArg = {.names = {"-f", "--file"}, + Arg filenameArg = {.names = {"-i", "--file"}, .scanFormat = "%1023c", .valueName = "FILENAME", .value = &filename, diff --git a/tests/cli/greatCircleDistanceKm.txt b/tests/cli/greatCircleDistanceKm.txt index b75391b1f..bbcc4963f 100644 --- a/tests/cli/greatCircleDistanceKm.txt +++ b/tests/cli/greatCircleDistanceKm.txt @@ -1,4 +1,4 @@ add_h3_cli_test(testCliGreatCircleDistanceKmArg "greatCircleDistanceKm -c '[[0, 1], [1, 2]]'" "157.2495585118") -add_h3_cli_test(testCliGreatCircleDistanceKmFile "greatCircleDistanceKm -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157.2495585118") -add_h3_cli_test(testCliGreatCircleDistanceKmStdin "greatCircleDistanceKm -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157.2495585118") +add_h3_cli_test(testCliGreatCircleDistanceKmFile "greatCircleDistanceKm -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157.2495585118") +add_h3_cli_test(testCliGreatCircleDistanceKmStdin "greatCircleDistanceKm -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157.2495585118") add_h3_cli_test(testCliGreatCircleDistanceKmBadArg "greatCircleDistanceKm -c '[[0, 1]]' 2>&1" "Only two pairs of coordinates should be provided.") diff --git a/tests/cli/greatCircleDistanceM.txt b/tests/cli/greatCircleDistanceM.txt index 2e0bbfea5..63789a306 100644 --- a/tests/cli/greatCircleDistanceM.txt +++ b/tests/cli/greatCircleDistanceM.txt @@ -1,4 +1,4 @@ add_h3_cli_test(testCliGreatCircleDistanceMArg "greatCircleDistanceM -c '[[0, 1], [1, 2]]'" "157249.5585117787") -add_h3_cli_test(testCliGreatCircleDistanceMFile "greatCircleDistanceM -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157249.5585117787") -add_h3_cli_test(testCliGreatCircleDistanceMStdin "greatCircleDistanceM -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157249.5585117787") +add_h3_cli_test(testCliGreatCircleDistanceMFile "greatCircleDistanceM -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157249.5585117787") +add_h3_cli_test(testCliGreatCircleDistanceMStdin "greatCircleDistanceM -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "157249.5585117787") add_h3_cli_test(testCliGreatCircleDistanceMBadArg "greatCircleDistanceM -c '[[0, 1]]' 2>&1" "Only two pairs of coordinates should be provided.") diff --git a/tests/cli/greatCircleDistanceRads.txt b/tests/cli/greatCircleDistanceRads.txt index af4d2b499..c3e16b758 100644 --- a/tests/cli/greatCircleDistanceRads.txt +++ b/tests/cli/greatCircleDistanceRads.txt @@ -1,4 +1,4 @@ add_h3_cli_test(testCliGreatCircleDistanceRadsArg "greatCircleDistanceRads -c '[[0, 1], [1, 2]]'" "0.0246820564") -add_h3_cli_test(testCliGreatCircleDistanceRadsFile "greatCircleDistanceRads -f ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "0.0246820564") -add_h3_cli_test(testCliGreatCircleDistanceRadsStdin "greatCircleDistanceRads -f -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "0.0246820564") +add_h3_cli_test(testCliGreatCircleDistanceRadsFile "greatCircleDistanceRads -i ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "0.0246820564") +add_h3_cli_test(testCliGreatCircleDistanceRadsStdin "greatCircleDistanceRads -i -- < ${PROJECT_SOURCE_DIR}/tests/inputfiles/great_circle_distance.txt" "0.0246820564") add_h3_cli_test(testCliGreatCircleDistanceRadsBadArg "greatCircleDistanceRads -c '[[0, 1]]' 2>&1" "Only two pairs of coordinates should be provided.") diff --git a/website/docs/api/misc.mdx b/website/docs/api/misc.mdx index ffa70c549..0df6a1162 100644 --- a/website/docs/api/misc.mdx +++ b/website/docs/api/misc.mdx @@ -1269,7 +1269,7 @@ h3: Calculates the 'great circle' or 'haversine' distance between two lat, lng p H3 4.1.0 greatCircleDistanceKm Calculates the 'great circle' or 'haversine' distance between two lat, lng points, in kilometers - -f, --file The file to load the coordinates from. Use -- to read from stdin. + -i, --file The file to load the coordinates from. Use -- to read from stdin. -c, --coordinates The array of coordinates to convert. Up to 1500 characters. -h, --help Show this help message. ``` @@ -1342,7 +1342,7 @@ h3: Calculates the 'great circle' or 'haversine' distance between two lat, lng p H3 4.1.0 greatCircleDistanceM Calculates the 'great circle' or 'haversine' distance between two lat, lng points, in meters - -f, --file The file to load the coordinates from. Use -- to read from stdin. + -i, --file The file to load the coordinates from. Use -- to read from stdin. -c, --coordinates The array of coordinates to convert. Up to 1500 characters. -h, --help Show this help message. ``` @@ -1414,8 +1414,8 @@ $ h3 greatCircleDistanceRads --help h3: Calculates the 'great circle' or 'haversine' distance between two lat, lng points, in radians H3 4.1.0 - greatCircleDistanceRadsCalculates the 'great circle' or 'haversine' distance between two lat, lng points, in radians - -f, --file The file to load the coordinates from. Use -- to read from stdin. + greatCircleDistanceRads Calculates the 'great circle' or 'haversine' distance between two lat, lng points, in radians + -i, --file The file to load the coordinates from. Use -- to read from stdin. -c, --coordinates The array of coordinates to convert. Up to 1500 characters. -h, --help Show this help message. ``` diff --git a/website/docs/api/regions.mdx b/website/docs/api/regions.mdx index 62dfad9b6..da921b270 100644 --- a/website/docs/api/regions.mdx +++ b/website/docs/api/regions.mdx @@ -154,8 +154,8 @@ H3 4.1.0 maxPolygonToCellsSize Returns the maximum number of cells that could be needed to cover the polygon. Will always be equal or more than actually necessary -h, --help Show this help message. - -f, --file The file to load the polygon from. Use -- to read from stdin. - -p, --polygon The polygon to convert. Up to 1500 characters. + -i, --file The file to load the polygon from. Use -- to read from stdin. + -p, --polygon The polygon to convert. Up to 1500 characters. -r, --resolution Required. Resolution, 0-15 inclusive, that the polygon should be converted to. ``` From 34a6f387d2eb02e0d90b83651400895b2c321da9 Mon Sep 17 00:00:00 2001 From: David Ellis Date: Thu, 17 Oct 2024 10:49:56 -0700 Subject: [PATCH 5/5] Try %7s for the format reading --- src/apps/filters/h3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index f45d03404..b24f50a5f 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -116,7 +116,7 @@ Arg helpArg = ARG_HELP; #define DEFINE_FORMAT_ARG(desc) \ char format[8] = {0}; \ Arg formatArg = {.names = {"-f", "--format"}, \ - .scanFormat = "%s", \ + .scanFormat = "%7s", \ .value = format, \ .valueName = "FMT", \ .helpText = desc}