1 /*
2 * Copyright 2016-2017 Uber Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 /** @file
17 * @brief generates random lat/lon pairs and bins them at the specified
18 * resolution
19 *
20 * See `mkRandGeo --help` for usage.
21 *
22 * The program generates `numPoints` random lat/lon coordinates and outputs
23 * them along with the corresponding H3Index at the specified `resolution`.
24 */
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include "args.h"
30 #include "utility.h"
31
main(int argc,char * argv[])32 int main(int argc, char* argv[]) {
33 int res = 0;
34 int numPoints = 0;
35
36 Arg helpArg = ARG_HELP;
37 Arg numPointsArg = {
38 .names = {"-n", "--num-points"},
39 .required = true,
40 .scanFormat = "%d",
41 .valueName = "num",
42 .value = &numPoints,
43 .helpText = "Number of random lat/lon pairs to generate."};
44 Arg resArg = {.names = {"-r", "--resolution"},
45 .required = true,
46 .scanFormat = "%d",
47 .valueName = "res",
48 .value = &res,
49 .helpText = "Resolution, 0-15 inclusive."};
50
51 Arg* args[] = {&helpArg, &numPointsArg, &resArg};
52 const int numArgs = 3;
53 const char* helpText =
54 "Generates random lat/lon pairs and indexes them at the specified "
55 "resolution.";
56
57 if (parseArgs(argc, argv, numArgs, args, &helpArg, helpText)) {
58 return helpArg.found ? 0 : 1;
59 }
60
61 if (res > MAX_H3_RES) {
62 printHelp(stderr, argv[0], helpText, numArgs, args,
63 "Resolution exceeds maximum resolution.", NULL);
64 return 1;
65 }
66
67 for (int i = 0; i < numPoints; i++) {
68 GeoCoord g;
69 randomGeo(&g);
70
71 H3Index h = H3_EXPORT(geoToH3)(&g, res);
72
73 h3Print(h);
74 printf(" ");
75 geoPrintlnNoFmt(&g);
76 }
77 }
78