-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbench.cpp
58 lines (45 loc) · 1.75 KB
/
bench.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
#include <mapbox/feature.hpp>
#include <rapidjson/document.h>
#include <rapidjson/filereadstream.h>
#define DEBUG_TIMER true
#include <supercluster.hpp>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <vector>
int main() {
std::FILE *fp = std::fopen("../supercluster/tmp/trees-na2.json", "r");
char buffer[65536];
rapidjson::FileReadStream is(fp, buffer, sizeof(buffer));
mapbox::supercluster::Timer timer;
rapidjson::Document d;
d.ParseStream(is);
timer("parse JSON");
const auto &json_features = d["features"];
mapbox::feature::feature_collection<double> features;
features.reserve(json_features.Size());
for (auto itr = json_features.Begin(); itr != json_features.End(); ++itr) {
const auto &json_coords = (*itr)["geometry"]["coordinates"];
const auto lng = json_coords[0].GetDouble();
const auto lat = json_coords[1].GetDouble();
mapbox::geometry::point<double> point(lng, lat);
mapbox::feature::feature<double> feature{ point };
features.push_back(feature);
}
timer("convert to geometry.hpp");
mapbox::supercluster::Options options;
options.radius = 75;
mapbox::supercluster::Supercluster index(features, options);
timer("total supercluster time");
mapbox::feature::feature_collection<std::int16_t> tile = index.getTile(0, 0, 0);
timer("query zero tile");
std::cerr << tile.size() << " features in tile 0-0-0:\n";
for (auto &f : tile) {
const auto itr = f.properties.find("cluster");
if (itr != f.properties.end() && itr->second.get<bool>()) {
std::cerr << "cluster: " << f.properties["point_count"].get<std::uint64_t>() << "\n";
} else {
std::cerr << "point\n";
}
}
}