-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdecode.cpp
65 lines (54 loc) · 1.34 KB
/
decode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <string>
#include "tippecanoe/projection.hpp"
#include "header.hpp"
#include "serial.hpp"
#include "milo/dtoa_milo.h"
void usage(char **argv) {
fprintf(stderr, "Usage: %s file.count ...\n", argv[0]);
}
int main(int argc, char **argv) {
extern int optind;
int i;
while ((i = getopt(argc, argv, "")) != -1) {
switch (i) {
default:
usage(argv);
exit(EXIT_FAILURE);
}
}
if (optind == argc) {
usage(argv);
exit(EXIT_FAILURE);
}
for (; optind < argc; optind++) {
FILE *f = fopen(argv[optind], "rb");
if (f == NULL) {
perror(optind[argv]);
exit(EXIT_FAILURE);
}
char header[HEADER_LEN];
if (fread(header, HEADER_LEN, 1, f) != 1) {
perror("read header");
exit(EXIT_FAILURE);
}
if (memcmp(header, header_text, HEADER_LEN) != 0) {
fprintf(stderr, "%s: not a tile-count file\n", argv[optind]);
exit(EXIT_FAILURE);
}
unsigned char buf[RECORD_BYTES];
while (fread(buf, RECORD_BYTES, 1, f) == 1) {
unsigned long long index = read64(buf);
unsigned long long count = read32(buf + INDEX_BYTES);
unsigned x, y;
decode(index, &x, &y);
double lon, lat;
projection->unproject(x, y, 32, &lon, &lat);
printf("%s,%s,%llu\n", milo::dtoa_milo(lon).c_str(), milo::dtoa_milo(lat).c_str(), count);
}
fclose(f);
}
}