mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-22 04:18:01 +00:00
Use JSON writer functions for tile size stats
This commit is contained in:
parent
605ccbe077
commit
ddf4a45b33
51
decode.cpp
51
decode.cpp
@ -28,16 +28,32 @@ int maxzoom = 32;
|
|||||||
bool force = false;
|
bool force = false;
|
||||||
|
|
||||||
void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, unsigned y) {
|
void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, unsigned y) {
|
||||||
printf("{ \"zoom\": %d, \"x\": %u, \"y\": %u, \"bytes\": %zu, \"compressed\": %s", z, x, y, size, compressed ? "true" : "false");
|
json_write_state state;
|
||||||
|
|
||||||
|
json_write_hash(stdout, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "zoom", state);
|
||||||
|
json_write_signed(stdout, z, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "x", state);
|
||||||
|
json_write_unsigned(stdout, x, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "y", state);
|
||||||
|
json_write_unsigned(stdout, y, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "bytes", state);
|
||||||
|
json_write_unsigned(stdout, size, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "compressed", state);
|
||||||
|
json_write_bool(stdout, compressed, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "layers", state);
|
||||||
|
json_write_hash(stdout, state);
|
||||||
|
|
||||||
printf(", \"layers\": { ");
|
|
||||||
for (size_t i = 0; i < tile.layers.size(); i++) {
|
for (size_t i = 0; i < tile.layers.size(); i++) {
|
||||||
if (i != 0) {
|
json_write_string(stdout, tile.layers[i].name, state);
|
||||||
printf(", ");
|
|
||||||
}
|
|
||||||
fprintq(stdout, tile.layers[i].name.c_str());
|
|
||||||
|
|
||||||
int points = 0, lines = 0, polygons = 0;
|
size_t points = 0, lines = 0, polygons = 0;
|
||||||
for (size_t j = 0; j < tile.layers[i].features.size(); j++) {
|
for (size_t j = 0; j < tile.layers[i].features.size(); j++) {
|
||||||
if (tile.layers[i].features[j].type == mvt_point) {
|
if (tile.layers[i].features[j].type == mvt_point) {
|
||||||
points++;
|
points++;
|
||||||
@ -48,10 +64,27 @@ void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(": { \"points\": %d, \"lines\": %d, \"polygons\": %d, \"extent\": %lld }", points, lines, polygons, tile.layers[i].extent);
|
json_write_hash(stdout, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "points", state);
|
||||||
|
json_write_unsigned(stdout, points, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "lines", state);
|
||||||
|
json_write_unsigned(stdout, lines, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "polygons", state);
|
||||||
|
json_write_unsigned(stdout, polygons, state);
|
||||||
|
|
||||||
|
json_write_string(stdout, "extent", state);
|
||||||
|
json_write_signed(stdout, tile.layers[i].extent, state);
|
||||||
|
|
||||||
|
json_end_hash(stdout, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" } }\n");
|
json_end_hash(stdout, state);
|
||||||
|
json_end_hash(stdout, state);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle(std::string message, int z, unsigned x, unsigned y, std::set<std::string> const &to_decode, bool pipeline, bool stats) {
|
void handle(std::string message, int z, unsigned x, unsigned y, std::set<std::string> const &to_decode, bool pipeline, bool stats) {
|
||||||
|
@ -9,28 +9,6 @@
|
|||||||
#include "write_json.hpp"
|
#include "write_json.hpp"
|
||||||
#include "milo/dtoa_milo.h"
|
#include "milo/dtoa_milo.h"
|
||||||
|
|
||||||
enum json_write_tok {
|
|
||||||
JSON_WRITE_HASH,
|
|
||||||
JSON_WRITE_HASH_KEY,
|
|
||||||
JSON_WRITE_HASH_VALUE,
|
|
||||||
JSON_WRITE_ARRAY,
|
|
||||||
JSON_WRITE_ARRAY_ELEMENT,
|
|
||||||
JSON_WRITE_TOP,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct json_write_state {
|
|
||||||
std::vector<json_write_tok> state;
|
|
||||||
|
|
||||||
~json_write_state() {
|
|
||||||
if (state.size() > 0) {
|
|
||||||
if (state.size() != 1 || state[0] != JSON_WRITE_TOP) {
|
|
||||||
fprintf(stderr, "JSON not closed at end\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void json_adjust(FILE *f, json_write_state &state) {
|
static void json_adjust(FILE *f, json_write_state &state) {
|
||||||
if (state.state.size() == 0) {
|
if (state.state.size() == 0) {
|
||||||
state.state.push_back(JSON_WRITE_TOP);
|
state.state.push_back(JSON_WRITE_TOP);
|
||||||
|
@ -1,2 +1,46 @@
|
|||||||
|
#ifndef WRITE_JSON_HPP
|
||||||
|
#define WRITE_JSON_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
enum json_write_tok {
|
||||||
|
JSON_WRITE_HASH,
|
||||||
|
JSON_WRITE_HASH_KEY,
|
||||||
|
JSON_WRITE_HASH_VALUE,
|
||||||
|
JSON_WRITE_ARRAY,
|
||||||
|
JSON_WRITE_ARRAY_ELEMENT,
|
||||||
|
JSON_WRITE_TOP,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct json_write_state {
|
||||||
|
std::vector<json_write_tok> state;
|
||||||
|
|
||||||
|
~json_write_state() {
|
||||||
|
if (state.size() > 0) {
|
||||||
|
if (state.size() != 1 || state[0] != JSON_WRITE_TOP) {
|
||||||
|
fprintf(stderr, "JSON not closed at end\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void layer_to_geojson(FILE *fp, mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long extent, bool complain);
|
void layer_to_geojson(FILE *fp, mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long extent, bool complain);
|
||||||
void fprintq(FILE *f, const char *s);
|
void fprintq(FILE *f, const char *s);
|
||||||
|
|
||||||
|
void json_write_array(FILE *f, json_write_state &state);
|
||||||
|
void json_end_array(FILE *f, json_write_state &state);
|
||||||
|
void json_write_hash(FILE *f, json_write_state &state);
|
||||||
|
void json_end_hash(FILE *f, json_write_state &state);
|
||||||
|
void json_write_string(FILE *f, std::string const &s, json_write_state &state);
|
||||||
|
void json_write_number(FILE *f, double d, json_write_state &state);
|
||||||
|
void json_write_float(FILE *f, double d, json_write_state &state);
|
||||||
|
void json_write_unsigned(FILE *f, unsigned long long v, json_write_state &state);
|
||||||
|
void json_write_signed(FILE *f, long long v, json_write_state &state);
|
||||||
|
void json_write_stringified(FILE *f, std::string const &s, json_write_state &state);
|
||||||
|
void json_write_bool(FILE *f, bool b, json_write_state &state);
|
||||||
|
void json_write_null(FILE *f, json_write_state &state);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user