bes  Updated for version 3.20.8
build_test_s_indices.cc
1 //
2 // Created by James Gallagher on 7/1/20.
3 //
18 #include <iostream>
19 #include <unistd.h>
20 #include <STARE.h>
21 #include <SpatialRange.h>
22 
23 using namespace std;
24 
25 void usage(const char *name) {
26  cerr << name << " [-v -c -a <lat center> -o <lon center> -r <radius> -l <level>] | -h" << endl;
27 }
28 
29 int main(int argc, char *argv[]) {
30 
31  int c;
32  extern char *optarg;
33  extern int optind;
34  bool verbose = false;
35  float64 latDegrees = 0.0, lonDegrees = 0.0, radius_degrees = 0.5;
36  int force_resolution_level = 10; // 10km neighborhood
37  bool csv = false;
38 
39  while ((c = getopt(argc, argv, "vhca:o:r:l:")) != -1) {
40  switch (c) {
41  case 'v':
42  verbose = true;
43  break;
44  case 'o':
45  latDegrees = atof(optarg);
46  break;
47  case 'a':
48  lonDegrees = atof(optarg);
49  break;
50  case 'r':
51  radius_degrees = atof(optarg);
52  break;
53  case 'l':
54  force_resolution_level = atoi(optarg);
55  break;
56  case 'c':
57  csv = true;
58  break;
59  case 'h':
60  default:
61  usage(argv[0]);
62  exit(EXIT_SUCCESS);
63  break;
64  }
65  }
66 
67  // This resets argc and argv once the optional arguments have been processed. jhrg 12/5/19
68  argc -= optind;
69  argv += optind;
70 
71  STARE stare;
72 
73  // Make a region of interest. At thiks writing, a 0.5 degree circle centered at the origin.
74 
75  STARE_SpatialIntervals circle_indices = stare.CoverCircleFromLatLonRadiusDegrees(latDegrees, lonDegrees,
76  radius_degrees,
77  force_resolution_level);
78  if (csv) {
79  for (STARE_SpatialIntervals::iterator i = circle_indices.begin(), e = circle_indices.end()-1; i != e; ++i)
80  cout << *i << ", ";
81  cout << *(circle_indices.end()-1) << endl;
82  }
83  else {
84  for (STARE_ArrayIndexSpatialValue s: circle_indices) {
85  cout << s << endl;
86  }
87  }
88 }