-
Notifications
You must be signed in to change notification settings - Fork 53
/
dump.c
92 lines (70 loc) · 1.47 KB
/
dump.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include "dump.h"
#include "util.h"
static int first = 1;
void dump_begin(int dump) {
if (dump == 2) {
printf("{\n");
printf("\"type\": \"FeatureCollection\",\n");
printf("\"features\": [\n");
}
}
void dump_end(int dump) {
if (dump == 2) {
printf("]\n}\n");
}
}
void dump_out(int dump, unsigned int *x, unsigned int *y, int components, int metabits, long long meta) {
if (dump == 2) {
if (!first) {
printf(",\n");
}
first = 0;
printf("{ ");
printf("\"type\": \"Feature\", ");
printf("\"properties\": {");
if (metabits != 0) {
printf(" \"meta\": %lld ", meta);
}
printf("}, ");
printf("\"geometry\": { ");
if (components == 1) {
printf("\"type\": \"Point\", ");
} else {
printf("\"type\": \"LineString\", ");
}
printf("\"coordinates\": [ ");
int k;
for (k = 0; k < components; k++) {
double lat, lon;
tile2latlon(x[k], y[k], 32, &lat, &lon);
if (components != 1) {
printf("[ ");
}
printf("%lf, %lf", lon, lat);
if (components != 1) {
printf(" ]");
if (k + 1 < components) {
printf(",");
}
}
printf(" ");
}
printf("] } }\n");
} else {
int k;
for (k = 0; k < components; k++) {
double lat, lon;
tile2latlon(x[k], y[k], 32, &lat, &lon);
printf("%lf,%lf ", lat, lon);
}
if (metabits != 0) {
printf("%d:%lld ", metabits, meta);
}
printf("// ");
for (k = 0; k < components; k++) {
printf("%08x %08x ", x[k], y[k]);
}
printf("\n");
}
}