Files
tippecanoe/write_json.hpp
T
Erica FischerandBrandon Liu 3b2599f587 Add support for pmtiles output format (#55)
* add pmtiles.hpp from github.com/protomaps/PMTiles [#10]

* tippecanoe main writes pmtiles output. [#10]

* detect output format using suffix
* after mbtiles is done writing, replace with pmtiles based on map/image tables.
* add method to write_json for writing json sub-object.

* tippecanoe-decode reads pmtiles input. [#10]

* tile-join reads and writes pmtiles. [#10]

* pmtiles test suite for decode and tile-join [#10]

* add base GitHub CI action for compiling and test suite.

* update pmtiles.hpp with z>15 fix

* Fix some ordering problems with pmtiles decode

* Pmtiles should also pass the raw tiles tests

* Eradicate spaces from tileset metadata JSON fields

* Eradicate spaces from more test fixtures

* Update more tests

* Pmtiles tests pass now too

* Remove unnecessary sort (and make indent)

* Update changelog

* The allow-existing test for pmtiles needs -o, not -e

* Declare --allow-existing to be unsupported for pmtiles.

It was always a bad idea even for mbtiles.

Co-authored-by: Brandon Liu <bdon@bdon.org>
2022-12-29 12:00:13 -08:00

68 lines
1.6 KiB
C++

#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_writer {
std::vector<json_write_tok> state;
bool nospace = false;
bool wantnl = false;
FILE *f = NULL;
std::string *s = NULL;
~json_writer() {
if (state.size() > 0) {
if (state.size() != 1 || state[0] != JSON_WRITE_TOP) {
fprintf(stderr, "JSON not closed at end\n");
exit(EXIT_FAILURE);
}
}
}
json_writer(FILE *fp) {
f = fp;
}
json_writer(std::string *out) {
s = out;
}
void json_write_array();
void json_end_array();
void json_write_hash();
void json_end_hash();
void json_write_string(std::string const &s);
void json_write_json(std::string const &s);
void json_write_number(double d);
void json_write_float(double d);
void json_write_unsigned(unsigned long long v);
void json_write_signed(long long v);
void json_write_stringified(std::string const &s);
void json_write_bool(bool b);
void json_write_null();
void json_write_newline();
void json_comma_newline();
private:
void json_adjust();
void aprintf(const char *format, ...);
void addc(char c);
void adds(std::string const &s);
};
void layer_to_geojson(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, json_writer &state, double scale);
void fprintq(FILE *f, const char *s);
#endif