mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-21 03:55:00 +00:00
Use the standard JSON writer when writing metadata.json
This commit is contained in:
parent
ebb0334ef0
commit
3c827b1d68
51
mbtiles.cpp
51
mbtiles.cpp
@ -88,38 +88,6 @@ void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void quote(std::string &buf, std::string const &s) {
|
|
||||||
for (size_t i = 0; i < s.size(); i++) {
|
|
||||||
unsigned char ch = s[i];
|
|
||||||
|
|
||||||
if (ch == '\\' || ch == '\"') {
|
|
||||||
buf.push_back('\\');
|
|
||||||
buf.push_back(ch);
|
|
||||||
} else if (ch < ' ') {
|
|
||||||
char tmp[7];
|
|
||||||
sprintf(tmp, "\\u%04x", ch);
|
|
||||||
buf.append(std::string(tmp));
|
|
||||||
} else {
|
|
||||||
buf.push_back(ch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void aprintf(std::string *buf, const char *format, ...) {
|
|
||||||
va_list ap;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
if (vasprintf(&tmp, format, ap) < 0) {
|
|
||||||
fprintf(stderr, "memory allocation failure\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
buf->append(tmp, strlen(tmp));
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool type_and_string::operator<(const type_and_string &o) const {
|
bool type_and_string::operator<(const type_and_string &o) const {
|
||||||
if (string < o.string) {
|
if (string < o.string) {
|
||||||
return true;
|
return true;
|
||||||
@ -505,7 +473,10 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp, "{\n");
|
json_writer state(fp);
|
||||||
|
|
||||||
|
state.json_write_hash();
|
||||||
|
state.json_write_newline();
|
||||||
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
@ -520,19 +491,17 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
quote(key, k);
|
state.json_comma_newline();
|
||||||
quote(value, v);
|
state.json_write_string(k);
|
||||||
|
state.json_write_string(v);
|
||||||
if (!first) {
|
|
||||||
fprintf(fp, ",\n");
|
|
||||||
}
|
|
||||||
fprintf(fp, " \"%s\": \"%s\"", key.c_str(), value.c_str());
|
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp, "\n}\n");
|
state.json_write_newline();
|
||||||
|
state.json_end_hash();
|
||||||
|
state.json_write_newline();
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,6 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam
|
|||||||
|
|
||||||
void mbtiles_close(sqlite3 *outdb, const char *pgm);
|
void mbtiles_close(sqlite3 *outdb, const char *pgm);
|
||||||
|
|
||||||
void aprintf(std::string *buf, const char *format, ...);
|
|
||||||
|
|
||||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps);
|
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps);
|
||||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps, bool trunc);
|
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps, bool trunc);
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "tests/raw-tiles/raw-tiles",
|
"name": "tests/raw-tiles/raw-tiles",
|
||||||
"description": "tests/raw-tiles/raw-tiles",
|
"description": "tests/raw-tiles/raw-tiles",
|
||||||
"version": "2",
|
"version": "2",
|
||||||
"minzoom": "0",
|
"minzoom": "0",
|
||||||
"maxzoom": "14",
|
"maxzoom": "14",
|
||||||
"center": "-122.662354,45.514045,14",
|
"center": "-122.662354,45.514045,14",
|
||||||
"bounds": "-122.682427,45.512331,-122.654961,45.569975",
|
"bounds": "-122.682427,45.512331,-122.654961,45.569975",
|
||||||
"type": "overlay",
|
"type": "overlay",
|
||||||
"format": "pbf",
|
"format": "pbf",
|
||||||
"json": "{\"vector_layers\": [ { \"id\": \"hackspots\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 14, \"fields\": {\"Address\": \"String\", \"Name\": \"String\", \"Notes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"hackspots\",\"count\": 4,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"Address\",\"count\": 4,\"type\": \"string\",\"values\": [\"1507 N Rosa Parks Way Portland, OR 97217\",\"201 SE 12th Ave, Portland, OR 97214\",\"4637 N Albina Ave Portland, OR 97217\",\"915 SE Hawthorne Blvd. Portland, OR 97214\"]},{\"attribute\": \"Name\",\"count\": 4,\"type\": \"string\",\"values\": [\"Albina Press\",\"Arbor Lodge\",\"Lucky Labrador Brew Pub\",\"Three Friends Coffeehouse\"]},{\"attribute\": \"Notes\",\"count\": 3,\"type\": \"string\",\"values\": [\"\",\"Dog friendly\",\"usually busy, outlets on side wall only\"]}]}]}}"
|
"json": "{\"vector_layers\": [ { \"id\": \"hackspots\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 14, \"fields\": {\"Address\": \"String\", \"Name\": \"String\", \"Notes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"hackspots\",\"count\": 4,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"Address\",\"count\": 4,\"type\": \"string\",\"values\": [\"1507 N Rosa Parks Way Portland, OR 97217\",\"201 SE 12th Ave, Portland, OR 97214\",\"4637 N Albina Ave Portland, OR 97217\",\"915 SE Hawthorne Blvd. Portland, OR 97214\"]},{\"attribute\": \"Name\",\"count\": 4,\"type\": \"string\",\"values\": [\"Albina Press\",\"Arbor Lodge\",\"Lucky Labrador Brew Pub\",\"Three Friends Coffeehouse\"]},{\"attribute\": \"Notes\",\"count\": 3,\"type\": \"string\",\"values\": [\"\",\"Dog friendly\",\"usually busy, outlets on side wall only\"]}]}]}}"
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,21 @@ struct stats {
|
|||||||
double minlat, minlon, maxlat, maxlon;
|
double minlat, minlon, maxlat, maxlon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void aprintf(std::string *buf, const char *format, ...) {
|
||||||
|
va_list ap;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
if (vasprintf(&tmp, format, ap) < 0) {
|
||||||
|
fprintf(stderr, "memory allocation failure\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
buf->append(tmp, strlen(tmp));
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::string, layermap_entry> &layermap, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping, std::set<std::string> &exclude, std::set<std::string> &keep_layers, std::set<std::string> &remove_layers, int ifmatched, mvt_tile &outtile, json_object *filter) {
|
void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::string, layermap_entry> &layermap, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping, std::set<std::string> &exclude, std::set<std::string> &keep_layers, std::set<std::string> &remove_layers, int ifmatched, mvt_tile &outtile, json_object *filter) {
|
||||||
mvt_tile tile;
|
mvt_tile tile;
|
||||||
int features_added = 0;
|
int features_added = 0;
|
||||||
|
@ -195,18 +195,18 @@ void json_writer::json_comma_newline() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void json_writer::aprintf(const char *format, ...) {
|
void json_writer::aprintf(const char *format, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
if (vasprintf(&tmp, format, ap) < 0) {
|
if (vasprintf(&tmp, format, ap) < 0) {
|
||||||
fprintf(stderr, "memory allocation failure\n");
|
fprintf(stderr, "memory allocation failure\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
adds(std::string(tmp, strlen(tmp)));
|
adds(std::string(tmp, strlen(tmp)));
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void json_writer::addc(char c) {
|
void json_writer::addc(char c) {
|
||||||
|
@ -53,7 +53,7 @@ struct json_writer {
|
|||||||
void json_write_newline();
|
void json_write_newline();
|
||||||
void json_comma_newline();
|
void json_comma_newline();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void json_adjust();
|
void json_adjust();
|
||||||
void aprintf(const char *format, ...);
|
void aprintf(const char *format, ...);
|
||||||
void addc(char c);
|
void addc(char c);
|
||||||
|
Loading…
Reference in New Issue
Block a user