in src/apps/filters/latLngToCell.c [60:122]
int main(int argc, char *argv[]) {
int res = 0;
double lat = 0;
double lng = 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 lngArg = {.names = {"--lng", "--longitude"},
.scanFormat = "%lf",
.valueName = "lng",
.value = &lng,
.helpText = "Longitude in degrees."};
Arg *args[] = {&helpArg, &resArg, &latArg, &lngArg};
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 != lngArg.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, lng, res);
} else {
// process the lat/lng's on stdin
char buff[BUFF_SIZE];
while (1) {
// get a lat/lng from stdin
if (!fgets(buff, BUFF_SIZE, stdin)) {
if (feof(stdin))
break;
else
error("reading lat/lng");
}
if (sscanf(buff, "%lf %lf", &lat, &lng) != 2)
error("parsing lat/lng");
// convert to H3
doCoords(lat, lng, res);
}
}
}