in src/apps/filters/geoToH3.c [55:117]
int main(int argc, char* argv[]) {
int res = 0;
double lat = 0;
double lon = 0;
Arg helpArg = ARG_HELP;
Arg resArg = {.names = {"-r", "--resolution"},
.required = true,
.scanFormat = "%d",
.valueName = "res",
.value = &res,
.helpText = "Resolution, 0-15 inclusive."};
Arg latArg = {.names = {"--lat", "--latitude"},
.scanFormat = "%lf",
.valueName = "lat",
.value = &lat,
.helpText =
"Latitude in degrees. If not specified, \"latitude "
"longitude\" pairs will be read from standard input."};
Arg lonArg = {.names = {"--lon", "--longitude"},
.scanFormat = "%lf",
.valueName = "lon",
.value = &lon,
.helpText = "Longitude in degrees."};
Arg* args[] = {&helpArg, &resArg, &latArg, &lonArg};
const int numArgs = 4;
const char* helpText =
"Convert degrees latitude/longitude coordinates to H3 indexes.";
if (parseArgs(argc, argv, numArgs, args, &helpArg, helpText)) {
return helpArg.found ? 0 : 1;
}
if (latArg.found != lonArg.found) {
// One is found but the other is not.
printHelp(stderr, argv[0], helpText, numArgs, args,
"Latitude and longitude must both be specified.", NULL);
return 1;
}
if (latArg.found) {
doCoords(lat, lon, res);
} else {
// process the lat/lon's on stdin
char buff[BUFF_SIZE];
while (1) {
// get a lat/lon from stdin
if (!fgets(buff, BUFF_SIZE, stdin)) {
if (feof(stdin))
break;
else
error("reading lat/lon");
}
if (sscanf(buff, "%lf %lf", &lat, &lon) != 2)
error("parsing lat/lon");
// convert to H3
doCoords(lat, lon, res);
}
}
}